"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chai_1 = require("chai");
var memFs = require("mem-fs");
var fsEditor = require("mem-fs-editor");
var shelljs_1 = require("shelljs");
var commit_changes_1 = require("../../steps/commit_changes");
var immutable_1 = require("immutable");
describe("commit changes", function () {
    var editor, dest;
    var options;
    var cwd = process.cwd();
    var src = cwd + "/tmp/test/basic_ticket_sample_app";
    beforeEach(function () {
        shelljs_1.mkdir("-p", src);
        shelljs_1.cp("-rf", cwd + "/src/test/fixtures/basic_ticket_sample_app/*", cwd + "/tmp/test/basic_ticket_sample_app");
        editor = fsEditor.create(memFs.create());
        editor.write(src + "/v2/src/javascripts/legacy_app.js", "var a = true");
        options = immutable_1.Map({ src: src, editor: editor });
    });
    afterEach(function () {
        shelljs_1.rm("-rf", src);
        editor.delete(src + "/v2/src/javascripts/legacy_app.js");
    });
    describe("when --replace-v1 is false, or not set", function () {
        before(function () { return (dest = src + "/v2"); });
        it("should save files to a v2 folder", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, commit_changes_1.default(options)];
                    case 1:
                        _a.sent();
                        chai_1.expect(shelljs_1.test("-e", dest + "/src/javascripts/legacy_app.js")).to.be.true;
                        return [2 /*return*/];
                }
            });
        }); });
    });
    describe("when --replace-v1 is true", function () {
        beforeEach(function () {
            options = options.set("replaceV1", true);
        });
        it("should save files to the root of the v1 app folder", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        chai_1.expect(options.get("dest")).not.to.exist;
                        return [4 /*yield*/, commit_changes_1.default(options)];
                    case 1:
                        options = _a.sent();
                        dest = options.get("dest");
                        chai_1.expect(dest).to.equal(src);
                        chai_1.expect(shelljs_1.test("-e", dest + "/src/javascripts/legacy_app.js")).to.be.true;
                        return [2 /*return*/];
                }
            });
        }); });
        it("should backup the v1 app source files to a v1 folder", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        chai_1.expect(shelljs_1.test("-e", dest + "/app.js")).to.be.true;
                        return [4 /*yield*/, commit_changes_1.default(options)];
                    case 1:
                        options = _a.sent();
                        dest = options.get("dest");
                        chai_1.expect(shelljs_1.test("-e", dest + "/app.js")).to.be.false;
                        chai_1.expect(shelljs_1.test("-e", dest + "/v1/app.js")).to.be.true;
                        return [2 /*return*/];
                }
            });
        }); });
    });
});
