2019-11-19 23:06:27 +08:00
|
|
|
// Initial env variable setup for tests.
|
|
|
|
process.env["INPUT_FOLDER"] = "build";
|
2019-12-22 05:51:39 +08:00
|
|
|
process.env["GITHUB_SHA"] = "123";
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
import _ from "lodash";
|
|
|
|
import { action } from "../src/constants";
|
|
|
|
import { deploy, generateBranch, init, switchToBaseBranch } from "../src/git";
|
2019-11-19 23:06:27 +08:00
|
|
|
import { execute } from "../src/util";
|
|
|
|
|
|
|
|
const originalAction = _.cloneDeep(action);
|
|
|
|
|
|
|
|
jest.mock("../src/util", () => ({
|
|
|
|
execute: jest.fn()
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe("git", () => {
|
|
|
|
afterEach(() => {
|
|
|
|
_.assignIn(action, originalAction);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("init", () => {
|
|
|
|
it("should execute three commands if a GitHub token is provided", async () => {
|
2019-12-22 05:51:39 +08:00
|
|
|
Object.assign(action, {
|
|
|
|
build: "build",
|
|
|
|
gitHubToken: "123",
|
|
|
|
pusher: {
|
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
|
|
|
const call = await init();
|
2020-01-07 23:59:50 +08:00
|
|
|
expect(execute).toBeCalledTimes(4);
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(call).toBe("Initialization step complete...");
|
2019-11-19 23:06:27 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should execute three commands if a Access token is provided", async () => {
|
|
|
|
Object.assign(action, {
|
2019-12-22 05:51:39 +08:00
|
|
|
build: "build",
|
|
|
|
accessToken: "123",
|
2019-11-19 23:06:27 +08:00
|
|
|
pusher: {
|
2019-12-22 05:51:39 +08:00
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
2019-11-19 23:06:27 +08:00
|
|
|
});
|
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
const call = await init();
|
|
|
|
|
2020-01-07 23:59:50 +08:00
|
|
|
expect(execute).toBeCalledTimes(4);
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(call).toBe("Initialization step complete...");
|
|
|
|
});
|
|
|
|
|
2019-11-19 23:06:27 +08:00
|
|
|
it("should fail if there is no provided GitHub Token or Access Token", async () => {
|
|
|
|
Object.assign(action, {
|
2019-12-22 05:51:39 +08:00
|
|
|
build: "build",
|
2019-11-19 23:06:27 +08:00
|
|
|
pusher: {
|
2019-12-22 05:51:39 +08:00
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
const call = await init();
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(execute).toBeCalledTimes(0);
|
|
|
|
expect(call).toBe("Initialization step complete...");
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
|
|
|
it("should fail if the build folder begins with a /", async () => {
|
|
|
|
Object.assign(action, {
|
2019-12-22 05:51:39 +08:00
|
|
|
accessToken: "123",
|
|
|
|
build: "/",
|
2019-11-19 23:06:27 +08:00
|
|
|
pusher: {
|
2019-12-22 05:51:39 +08:00
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
const call = await init();
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(execute).toBeCalledTimes(0);
|
|
|
|
expect(call).toBe("Initialization step complete...");
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
|
|
|
it("should fail if the build folder begins with a ./", async () => {
|
|
|
|
Object.assign(action, {
|
2019-12-22 05:51:39 +08:00
|
|
|
accessToken: "123",
|
|
|
|
build: "./",
|
2019-11-19 23:06:27 +08:00
|
|
|
pusher: {
|
2019-12-22 05:51:39 +08:00
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
const call = await init();
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(execute).toBeCalledTimes(0);
|
|
|
|
expect(call).toBe("Initialization step complete...");
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
|
|
|
it("should not fail if root is used", async () => {
|
|
|
|
Object.assign(action, {
|
2019-12-22 05:51:39 +08:00
|
|
|
accessToken: "123",
|
|
|
|
build: ".",
|
2019-11-19 23:06:27 +08:00
|
|
|
pusher: {
|
2019-12-22 05:51:39 +08:00
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
const call = await init();
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2020-01-07 23:59:50 +08:00
|
|
|
expect(execute).toBeCalledTimes(4);
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(call).toBe("Initialization step complete...");
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
});
|
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
describe("generateBranch", () => {
|
|
|
|
it("should execute five commands", async () => {
|
2019-11-19 23:06:27 +08:00
|
|
|
const call = await generateBranch();
|
|
|
|
expect(execute).toBeCalledTimes(6);
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(call).toBe("Deployment branch creation step complete... ✅");
|
|
|
|
});
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
|
2019-12-22 05:51:39 +08:00
|
|
|
describe("switchToBaseBranch", () => {
|
|
|
|
it("should execute one command", async () => {
|
|
|
|
const call = await switchToBaseBranch();
|
|
|
|
expect(execute).toBeCalledTimes(1);
|
|
|
|
expect(call).toBe("Switched to the base branch...");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("deploy", () => {
|
|
|
|
it("should execute five commands", async () => {
|
2019-11-19 23:06:27 +08:00
|
|
|
Object.assign(action, {
|
2019-12-22 05:51:39 +08:00
|
|
|
build: "build",
|
|
|
|
gitHubToken: "123",
|
2019-11-19 23:06:27 +08:00
|
|
|
pusher: {
|
2019-12-22 05:51:39 +08:00
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-11-19 23:06:27 +08:00
|
|
|
const call = await deploy();
|
|
|
|
|
|
|
|
// Includes the call to generateBranch
|
2019-12-22 03:58:59 +08:00
|
|
|
expect(execute).toBeCalledTimes(18);
|
2019-12-22 05:51:39 +08:00
|
|
|
expect(call).toBe("Commit step complete...");
|
|
|
|
});
|
|
|
|
});
|
2019-11-19 23:06:27 +08:00
|
|
|
});
|