More tests

This commit is contained in:
James Ives 2019-11-07 19:57:58 -05:00
parent f157d8c731
commit 712ece2f34
3 changed files with 56 additions and 16 deletions

39
__tests__/git.test.ts Normal file
View File

@ -0,0 +1,39 @@
process.env["INPUT_FOLDER"] = "build";
import { execute } from "../src/util";
import { init } from "../src/git";
import {action} from '../src/constants'
jest.mock("../src/constants", () => ({
build: 'dist',
action: {
pusher: {
name: 'montezuma',
email: 'best@cat',
},
gitHubToken: 'exists',
}
}));
jest.mock("../src/util", () => ({
execute: jest.fn()
}));
jest.mock("@actions/io", () => ({
cp: jest.fn()
}));
describe("git", () => {
describe("init", () => {
it("should execute three commands", async () => {
await init();
expect(execute).toBeCalledTimes(3);
});
it("should fail if the dpeloyment folder begins with /", async () => {
// TODO:
})
});
});

View File

@ -5,15 +5,19 @@ jest.mock('@actions/exec', () => ({
exec: jest.fn()
}))
test('util - execute - should be called with the correct arguements', async() => {
await execute('echo Montezuma', './')
expect(exec).toBeCalledWith(
"echo Montezuma", [], {
cwd: "./",
listeners: {
stdout: expect.any(Function)
}
}
)
});
describe('util', () => {
describe('execute', () => {
it('should be called with the correct arguements', async() => {
await execute('echo Montezuma', './')
expect(exec).toBeCalledWith(
"echo Montezuma", [], {
cwd: "./",
listeners: {
stdout: expect.any(Function)
}
}
)
});
})
})

View File

@ -8,10 +8,7 @@ import { workspace, build, action, repositoryPath } from "./constants";
*/
export async function init(): Promise<any> {
try {
const accessToken = core.getInput("ACCESS_TOKEN");
const gitHubToken = core.getInput("GITHUB_TOKEN");
if (!accessToken && !gitHubToken) {
if (!action.accessToken && !action.gitHubToken) {
core.setFailed(
"You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy."
);