2019-11-08 23:34:29 +08:00
|
|
|
// Initial env variable setup for tests.
|
2019-11-08 08:57:58 +08:00
|
|
|
process.env["INPUT_FOLDER"] = "build";
|
|
|
|
|
|
|
|
import { execute } from "../src/util";
|
2019-11-08 23:34:29 +08:00
|
|
|
import { init, generateBranch, deploy } from "../src/git";
|
2019-11-08 08:57:58 +08:00
|
|
|
import {action} from '../src/constants'
|
2019-11-08 23:34:29 +08:00
|
|
|
import {cp} from '@actions/io';
|
|
|
|
import _ from 'lodash';
|
2019-11-08 08:57:58 +08:00
|
|
|
|
2019-11-08 23:34:29 +08:00
|
|
|
const originalAction = _.cloneDeep(action);
|
2019-11-08 08:57:58 +08:00
|
|
|
|
|
|
|
jest.mock("../src/util", () => ({
|
|
|
|
execute: jest.fn()
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock("@actions/io", () => ({
|
|
|
|
cp: jest.fn()
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe("git", () => {
|
2019-11-08 23:34:29 +08:00
|
|
|
afterEach(() => {
|
|
|
|
_.assignIn(action, originalAction);
|
|
|
|
});
|
|
|
|
|
2019-11-08 08:57:58 +08:00
|
|
|
describe("init", () => {
|
2019-11-08 23:34:29 +08:00
|
|
|
it("should execute three commands if a GitHub token is provided", async () => {
|
2019-11-08 08:57:58 +08:00
|
|
|
|
2019-11-08 23:34:29 +08:00
|
|
|
|
|
|
|
Object.assign(action, {
|
|
|
|
build: 'build',
|
|
|
|
gitHubToken: '123',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
2019-11-08 08:57:58 +08:00
|
|
|
|
2019-11-08 23:34:29 +08:00
|
|
|
const call = await init();
|
2019-11-08 08:57:58 +08:00
|
|
|
expect(execute).toBeCalledTimes(3);
|
2019-11-08 23:34:29 +08:00
|
|
|
expect(call).toBe('Initialization step complete...')
|
2019-11-08 08:57:58 +08:00
|
|
|
});
|
|
|
|
|
2019-11-08 23:34:29 +08:00
|
|
|
it("should execute three commands if a Access token is provided", async () => {
|
|
|
|
|
|
|
|
Object.assign(action, {
|
|
|
|
build: 'build',
|
|
|
|
accessToken: '123',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
|
|
|
const call = await init();
|
|
|
|
|
|
|
|
expect(execute).toBeCalledTimes(3);
|
|
|
|
expect(call).toBe('Initialization step complete...')
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should fail if there is no provided GitHub Token or Access Token", async () => {
|
|
|
|
Object.assign(action, {
|
|
|
|
build: 'build',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
|
|
|
const call = await init()
|
|
|
|
|
|
|
|
expect(execute).toBeCalledTimes(0);
|
|
|
|
expect(call).toBe('Initialization step complete...')
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should fail if the build folder begins with a /", async () => {
|
|
|
|
Object.assign(action, {
|
|
|
|
accessToken: '123',
|
|
|
|
build: '/',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
|
|
|
const call = await init()
|
|
|
|
|
|
|
|
expect(execute).toBeCalledTimes(0);
|
|
|
|
expect(call).toBe('Initialization step complete...')
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should fail if the build folder begins with a ./", async () => {
|
|
|
|
Object.assign(action, {
|
|
|
|
accessToken: '123',
|
|
|
|
build: './',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
|
|
|
const call = await init()
|
|
|
|
|
|
|
|
expect(execute).toBeCalledTimes(0);
|
|
|
|
expect(call).toBe('Initialization step complete...')
|
2019-11-08 08:57:58 +08:00
|
|
|
})
|
2019-11-11 05:31:05 +08:00
|
|
|
|
|
|
|
it("should not fail if root is used", async () => {
|
|
|
|
Object.assign(action, {
|
|
|
|
accessToken: '123',
|
|
|
|
build: '.',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
|
|
|
const call = await init()
|
|
|
|
|
|
|
|
expect(execute).toBeCalledTimes(3);
|
|
|
|
expect(call).toBe('Initialization step complete...')
|
|
|
|
})
|
2019-11-08 08:57:58 +08:00
|
|
|
});
|
2019-11-08 23:34:29 +08:00
|
|
|
|
|
|
|
describe('generateBranch', () => {
|
|
|
|
it('should execute five commands', async () => {
|
|
|
|
const call = await generateBranch();
|
2019-11-11 05:31:05 +08:00
|
|
|
expect(execute).toBeCalledTimes(6);
|
2019-11-08 23:34:29 +08:00
|
|
|
expect(call).toBe('Deployment branch creation step complete...')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('deploy', () => {
|
|
|
|
it('should execute five commands', async () => {
|
2019-11-11 05:31:05 +08:00
|
|
|
Object.assign(action, {
|
|
|
|
build: 'build',
|
|
|
|
gitHubToken: '123',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
2019-11-08 23:34:29 +08:00
|
|
|
const call = await deploy();
|
|
|
|
|
|
|
|
// Includes the call to generateBranch
|
2019-11-11 05:31:05 +08:00
|
|
|
expect(execute).toBeCalledTimes(14);
|
2019-11-08 23:34:29 +08:00
|
|
|
expect(cp).toBeCalledTimes(1)
|
|
|
|
expect(call).toBe('Commit step complete...')
|
|
|
|
})
|
2019-11-11 05:31:05 +08:00
|
|
|
|
|
|
|
it('should execute six commands if root is used', async () => {
|
|
|
|
Object.assign(action, {
|
|
|
|
build: '.',
|
|
|
|
gitHubToken: '123',
|
|
|
|
pusher: {
|
|
|
|
name: 'asd',
|
|
|
|
email: 'as@cat'
|
|
|
|
}})
|
|
|
|
|
|
|
|
const call = await deploy();
|
|
|
|
|
|
|
|
// Includes the call to generateBranch
|
|
|
|
expect(execute).toBeCalledTimes(15);
|
|
|
|
expect(cp).toBeCalledTimes(0)
|
|
|
|
expect(call).toBe('Commit step complete...')
|
|
|
|
})
|
2019-11-08 23:34:29 +08:00
|
|
|
})
|
2019-11-08 08:57:58 +08:00
|
|
|
});
|