Skip to content

Commit aa6f452

Browse files
committed
Create release endpoint test
1 parent 782415a commit aa6f452

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ async function run() {
393393

394394
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
395395
const tagName = core.getInput('tag_name', { required: true });
396+
396397
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
397398
const tag = tagName.replace('refs/tags/', '');
398-
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
399399
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
400400
const draft = core.getInput('draft', { required: false }) === 'true';
401401
const prerelease = core.getInput('prerelease', { required: false }) === 'true';

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ async function run() {
1111

1212
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
1313
const tagName = core.getInput('tag_name', { required: true });
14+
1415
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
1516
const tag = tagName.replace('refs/tags/', '');
16-
// This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15'
1717
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
1818
const draft = core.getInput('draft', { required: false }) === 'true';
1919
const prerelease = core.getInput('prerelease', { required: false }) === 'true';

tests/main.test.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
1+
jest.mock('@actions/core');
2+
jest.mock('@actions/github');
3+
4+
const core = require('@actions/core');
5+
const { GitHub, context } = require('@actions/github');
6+
const run = require('../src/main.js');
7+
18
/* eslint-disable no-undef */
2-
describe('Create release', () => {
3-
test('Create release endpoint is called', async () => {});
9+
describe('module', () => {
10+
let createRelease;
11+
12+
beforeEach(() => {
13+
core.getInput = jest.fn()
14+
.mockReturnValueOnce('refs/tags/v1.0.0')
15+
.mockReturnValueOnce('myRelease')
16+
.mockReturnValueOnce('false')
17+
.mockReturnValueOnce('false');
18+
19+
createRelease = jest.fn();
20+
21+
context.repo = {
22+
owner: 'owner',
23+
repo: 'repo'
24+
};
25+
26+
const github = {
27+
repos: {
28+
createRelease
29+
}
30+
};
31+
32+
GitHub.mockImplementation(() => github);
33+
});
34+
35+
test('Create release endpoint is called', async () => {
36+
await run();
37+
38+
expect(createRelease).toHaveBeenCalledWith({
39+
owner: 'owner',
40+
repo: 'repo',
41+
tag_name: 'v1.0.0',
42+
name: 'myRelease',
43+
draft: false,
44+
prerelease: false
45+
});
46+
});
447

548
test('Outputs are set', async () => {});
649
});

0 commit comments

Comments
 (0)