From aa6f452281d6064fc211a54b6ce0a803b1df95cc Mon Sep 17 00:00:00 2001 From: Thomas Hughes Date: Thu, 26 Sep 2019 15:24:23 -0500 Subject: [PATCH] Create release endpoint test --- dist/index.js | 2 +- src/main.js | 2 +- tests/main.test.js | 47 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 2fb37c1..ca7c743 100644 --- a/dist/index.js +++ b/dist/index.js @@ -393,9 +393,9 @@ async function run() { // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs const tagName = core.getInput('tag_name', { required: true }); + // This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15' const tag = tagName.replace('refs/tags/', ''); - // This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15' const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', ''); const draft = core.getInput('draft', { required: false }) === 'true'; const prerelease = core.getInput('prerelease', { required: false }) === 'true'; diff --git a/src/main.js b/src/main.js index 43299a9..018e6af 100644 --- a/src/main.js +++ b/src/main.js @@ -11,9 +11,9 @@ async function run() { // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs const tagName = core.getInput('tag_name', { required: true }); + // This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15' const tag = tagName.replace('refs/tags/', ''); - // This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15' const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', ''); const draft = core.getInput('draft', { required: false }) === 'true'; const prerelease = core.getInput('prerelease', { required: false }) === 'true'; diff --git a/tests/main.test.js b/tests/main.test.js index 631be59..d8c5b88 100644 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -1,6 +1,49 @@ +jest.mock('@actions/core'); +jest.mock('@actions/github'); + +const core = require('@actions/core'); +const { GitHub, context } = require('@actions/github'); +const run = require('../src/main.js'); + /* eslint-disable no-undef */ -describe('Create release', () => { - test('Create release endpoint is called', async () => {}); +describe('module', () => { + let createRelease; + + beforeEach(() => { + core.getInput = jest.fn() + .mockReturnValueOnce('refs/tags/v1.0.0') + .mockReturnValueOnce('myRelease') + .mockReturnValueOnce('false') + .mockReturnValueOnce('false'); + + createRelease = jest.fn(); + + context.repo = { + owner: 'owner', + repo: 'repo' + }; + + const github = { + repos: { + createRelease + } + }; + + GitHub.mockImplementation(() => github); + }); + + test('Create release endpoint is called', async () => { + await run(); + + expect(createRelease).toHaveBeenCalledWith({ + owner: 'owner', + repo: 'repo', + tag_name: 'v1.0.0', + name: 'myRelease', + draft: false, + prerelease: false + }); + }); test('Outputs are set', async () => {}); });