Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add additional tests
  • Loading branch information
Thomas Hughes committed Sep 26, 2019
1 parent aa6f452 commit cc8e50b
Showing 1 changed file with 94 additions and 8 deletions.
102 changes: 94 additions & 8 deletions tests/main.test.js
Expand Up @@ -10,13 +10,13 @@ describe('module', () => {
let createRelease;

beforeEach(() => {
core.getInput = jest.fn()
.mockReturnValueOnce('refs/tags/v1.0.0')
.mockReturnValueOnce('myRelease')
.mockReturnValueOnce('false')
.mockReturnValueOnce('false');

createRelease = jest.fn();
createRelease = jest.fn().mockReturnValueOnce({
data: {
id: 'releaseId',
html_url: 'htmlUrl',
upload_url: 'uploadUrl'
}
});

context.repo = {
owner: 'owner',
Expand All @@ -33,6 +33,13 @@ describe('module', () => {
});

test('Create release endpoint is called', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('refs/tags/v1.0.0')
.mockReturnValueOnce('myRelease')
.mockReturnValueOnce('false')
.mockReturnValueOnce('false');

await run();

expect(createRelease).toHaveBeenCalledWith({
Expand All @@ -45,5 +52,84 @@ describe('module', () => {
});
});

test('Outputs are set', async () => {});
test('Draft release is created', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('refs/tags/v1.0.0')
.mockReturnValueOnce('myRelease')
.mockReturnValueOnce('true')
.mockReturnValueOnce('false');

await run();

expect(createRelease).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repo',
tag_name: 'v1.0.0',
name: 'myRelease',
draft: true,
prerelease: false
});
});

test('Pre-release release is created', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('refs/tags/v1.0.0')
.mockReturnValueOnce('myRelease')
.mockReturnValueOnce('false')
.mockReturnValueOnce('true');

await run();

expect(createRelease).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repo',
tag_name: 'v1.0.0',
name: 'myRelease',
draft: false,
prerelease: true
});
});

test('Outputs are set', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('refs/tags/v1.0.0')
.mockReturnValueOnce('myRelease')
.mockReturnValueOnce('false')
.mockReturnValueOnce('false');

core.setOutput = jest.fn();

await run();

expect(core.setOutput).toHaveBeenNthCalledWith(1, 'id', 'releaseId');
expect(core.setOutput).toHaveBeenNthCalledWith(2, 'html_url', 'htmlUrl');
expect(core.setOutput).toHaveBeenNthCalledWith(3, 'upload_url', 'uploadUrl');
});

test('Action fails elegantly', async () => {
core.getInput = jest
.fn()
.mockReturnValueOnce('refs/tags/v1.0.0')
.mockReturnValueOnce('myRelease')
.mockReturnValueOnce('false')
.mockReturnValueOnce('false');

createRelease.mockRestore();
createRelease.mockImplementation(() => {
throw new Error('Error creating release');
});

core.setOutput = jest.fn();

core.setFailed = jest.fn();

await run();

expect(createRelease).toHaveBeenCalled();
expect(core.setFailed).toHaveBeenCalledWith('Error creating release');
expect(core.setOutput).toHaveBeenCalledTimes(0);
});
});

0 comments on commit cc8e50b

Please sign in to comment.