From 515e39edbf1cb92755bded394024cdf85de4c79d Mon Sep 17 00:00:00 2001 From: grantbirki Date: Fri, 14 Apr 2023 20:43:44 +0100 Subject: [PATCH] structuring tests and functions --- __tests__/functions/deployment.test.js | 275 +++++++++++++++++++++++++ __tests__/index.test.js | 274 ------------------------ src/{ => functions}/api-client.js | 0 src/{ => functions}/context.js | 0 src/{ => functions}/deployment.js | 0 src/index.js | 4 +- 6 files changed, 277 insertions(+), 276 deletions(-) create mode 100644 __tests__/functions/deployment.test.js rename src/{ => functions}/api-client.js (100%) rename src/{ => functions}/context.js (100%) rename src/{ => functions}/deployment.js (100%) diff --git a/__tests__/functions/deployment.test.js b/__tests__/functions/deployment.test.js new file mode 100644 index 0000000..9aeb7c2 --- /dev/null +++ b/__tests__/functions/deployment.test.js @@ -0,0 +1,275 @@ + +const core = require('@actions/core') +const nock = require('nock') + +const { Deployment } = require('../../src/functions/deployment') + +const fakeJwt = + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w' + +describe('Deployment', () => { + beforeEach(() => { + process.env.ACTIONS_RUNTIME_URL = 'http://my-url/' + process.env.GITHUB_RUN_ID = '123' + process.env.ACTIONS_RUNTIME_TOKEN = 'a-token' + process.env.GITHUB_REPOSITORY = 'actions/is-awesome' + process.env.GITHUB_TOKEN = 'gha-token' + process.env.GITHUB_SHA = '123abc' + process.env.GITHUB_ACTOR = 'monalisa' + process.env.GITHUB_ACTION = '__monalisa/octocat' + process.env.GITHUB_ACTION_PATH = 'something' + + jest.spyOn(core, 'getInput').mockImplementation(param => { + switch (param) { + case 'artifact_name': + return 'github-pages' + case 'token': + return process.env.GITHUB_TOKEN + default: + return process.env[`INPUT_${param.toUpperCase()}`] || '' + } + }) + + jest.spyOn(core, 'setOutput').mockImplementation(param => { + return param + }) + + jest.spyOn(core, 'setFailed').mockImplementation(param => { + return param + }) + // Mock error/warning/info/debug + jest.spyOn(core, 'error').mockImplementation(jest.fn()) + jest.spyOn(core, 'warning').mockImplementation(jest.fn()) + jest.spyOn(core, 'info').mockImplementation(jest.fn()) + jest.spyOn(core, 'debug').mockImplementation(jest.fn()) + }) + + describe('#create', () => { + afterEach(() => { + // Remove mock for `core.getInput('preview')` + delete process.env.INPUT_PREVIEW + }) + + it('can successfully create a deployment', async () => { + process.env.GITHUB_SHA = 'valid-build-version' + + const artifactExchangeScope = nock(`http://my-url`) + .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') + .reply(200, { + value: [ + { url: 'https://another-artifact.com', name: 'another-artifact' }, + { url: 'https://fake-artifact.com', name: 'github-pages' } + ] + }) + + const createDeploymentScope = nock('https://api.github.com') + .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { + artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', + pages_build_version: process.env.GITHUB_SHA, + oidc_token: fakeJwt + }) + .reply(200, { + status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, + page_url: 'https://actions.github.io/is-awesome' + }) + + core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) + + // Create the deployment + const deployment = new Deployment() + await deployment.create(fakeJwt) + + expect(core.setFailed).not.toHaveBeenCalled() + expect(core.info).toHaveBeenLastCalledWith( + expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`)) + ) + + artifactExchangeScope.done() + createDeploymentScope.done() + }) + + it('can successfully create a preview deployment', async () => { + process.env.GITHUB_SHA = 'valid-build-version' + + const artifactExchangeScope = nock(`http://my-url`) + .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') + .reply(200, { + value: [ + { url: 'https://another-artifact.com', name: 'another-artifact' }, + { url: 'https://fake-artifact.com', name: 'github-pages' } + ] + }) + + const createDeploymentScope = nock('https://api.github.com') + .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { + artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', + pages_build_version: process.env.GITHUB_SHA, + oidc_token: fakeJwt, + preview: true + }) + .reply(200, { + status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, + page_url: 'https://actions.github.io/is-awesome', + preview_url: 'https://actions.drafts.github.io/is-awesome' + }) + + core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) + + // Return `"true"` for `core.getInput("preview")` + process.env.INPUT_PREVIEW = 'true' + + // Create the deployment + const deployment = new Deployment() + await deployment.create(fakeJwt) + + expect(core.setFailed).not.toHaveBeenCalled() + expect(core.info).toHaveBeenLastCalledWith( + expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`)) + ) + + artifactExchangeScope.done() + createDeploymentScope.done() + }) + + it('reports errors with failed artifact exchange', async () => { + process.env.GITHUB_SHA = 'invalid-build-version' + const artifactExchangeScope = nock(`http://my-url`) + .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') + .reply(400, {}) + + // Create the deployment + const deployment = new Deployment() + await expect(deployment.create()).rejects.toEqual( + new Error( + `Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad Request` + ) + ) + + artifactExchangeScope.done() + }) + + it('reports errors with failed deployments', async () => { + process.env.GITHUB_SHA = 'invalid-build-version' + const artifactExchangeScope = nock(`http://my-url`) + .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') + .reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] }) + + const createDeploymentScope = nock('https://api.github.com') + .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { + artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent', + pages_build_version: process.env.GITHUB_SHA + }) + .reply(400, { message: 'Bad request' }) + + // Create the deployment + const deployment = new Deployment() + await expect(deployment.create()).rejects.toEqual( + new Error( + `Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request` + ) + ) + + artifactExchangeScope.done() + createDeploymentScope.done() + }) + }) + + describe('#check', () => { + it('sets output to success when deployment is successful', async () => { + process.env.GITHUB_SHA = 'valid-build-version' + + const artifactExchangeScope = nock(`http://my-url`) + .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') + .reply(200, { + value: [ + { url: 'https://another-artifact.com', name: 'another-artifact' }, + { url: 'https://fake-artifact.com', name: 'github-pages' } + ] + }) + + const createDeploymentScope = nock('https://api.github.com') + .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { + artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', + pages_build_version: process.env.GITHUB_SHA, + oidc_token: fakeJwt + }) + .reply(200, { + status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, + page_url: 'https://actions.github.io/is-awesome' + }) + + const deploymentStatusScope = nock('https://api.github.com') + .get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`) + .reply(200, { + status: 'succeed' + }) + + core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) + core.GetInput = jest.fn(input => { + switch (input) { + case 'timeout': + return 10 * 1000 + case 'reporting_interval': + return 0 + } + }) + + // Create the deployment + const deployment = new Deployment() + await deployment.create(fakeJwt) + await deployment.check() + + expect(core.setOutput).toBeCalledWith('status', 'succeed') + expect(core.info).toHaveBeenLastCalledWith('Reported success!') + + artifactExchangeScope.done() + createDeploymentScope.done() + deploymentStatusScope.done() + }) + }) + + describe('#cancel', () => { + it('can successfully cancel a deployment', async () => { + process.env.GITHUB_SHA = 'valid-build-version' + + const artifactExchangeScope = nock(`http://my-url`) + .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') + .reply(200, { + value: [ + { url: 'https://another-artifact.com', name: 'another-artifact' }, + { url: 'https://fake-artifact.com', name: 'github-pages' } + ] + }) + + const createDeploymentScope = nock('https://api.github.com') + .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { + artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', + pages_build_version: process.env.GITHUB_SHA, + oidc_token: fakeJwt + }) + .reply(200, { + status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, + page_url: 'https://actions.github.io/is-awesome' + }) + + const cancelDeploymentScope = nock('https://api.github.com') + .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`) + .reply(200, {}) + + core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) + + // Create the deployment + const deployment = new Deployment() + await deployment.create(fakeJwt) + + // Cancel it + await deployment.cancel() + + expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`) + + artifactExchangeScope.done() + createDeploymentScope.done() + cancelDeploymentScope.done() + }) + }) + }) diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 82ce5fa..c652475 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -1,13 +1,6 @@ -const core = require('@actions/core') const process = require('process') const cp = require('child_process') const path = require('path') -const nock = require('nock') - -const { Deployment } = require('../src/deployment') - -const fakeJwt = - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJiNjllMWIxOC1jOGFiLTRhZGQtOGYxOC03MzVlMzVjZGJhZjAiLCJzdWIiOiJyZXBvOnBhcGVyLXNwYS9taW55aTplbnZpcm9ubWVudDpQcm9kdWN0aW9uIiwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3BhcGVyLXNwYSIsInJlZiI6InJlZnMvaGVhZHMvbWFpbiIsInNoYSI6ImEyODU1MWJmODdiZDk3NTFiMzdiMmM0YjM3M2MxZjU3NjFmYWM2MjYiLCJyZXBvc2l0b3J5IjoicGFwZXItc3BhL21pbnlpIiwicmVwb3NpdG9yeV9vd25lciI6InBhcGVyLXNwYSIsInJ1bl9pZCI6IjE1NDY0NTkzNjQiLCJydW5fbnVtYmVyIjoiMzQiLCJydW5fYXR0ZW1wdCI6IjIiLCJhY3RvciI6IllpTXlzdHkiLCJ3b3JrZmxvdyI6IkNJIiwiaGVhZF9yZWYiOiIiLCJiYXNlX3JlZiI6IiIsImV2ZW50X25hbWUiOiJwdXNoIiwicmVmX3R5cGUiOiJicmFuY2giLCJlbnZpcm9ubWVudCI6IlByb2R1Y3Rpb24iLCJqb2Jfd29ya2Zsb3dfcmVmIjoicGFwZXItc3BhL21pbnlpLy5naXRodWIvd29ya2Zsb3dzL2JsYW5rLnltbEByZWZzL2hlYWRzL21haW4iLCJpc3MiOiJodHRwczovL3Rva2VuLmFjdGlvbnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tIiwibmJmIjoxNjM4ODI4MDI4LCJleHAiOjE2Mzg4Mjg5MjgsImlhdCI6MTYzODgyODYyOH0.1wyupfxu1HGoTyIqatYg0hIxy2-0bMO-yVlmLSMuu2w' describe('with all environment variables set', () => { beforeEach(() => { @@ -43,270 +36,3 @@ describe('with variables missing', () => { }) }) }) - -describe('Deployment', () => { - beforeEach(() => { - process.env.ACTIONS_RUNTIME_URL = 'http://my-url/' - process.env.GITHUB_RUN_ID = '123' - process.env.ACTIONS_RUNTIME_TOKEN = 'a-token' - process.env.GITHUB_REPOSITORY = 'actions/is-awesome' - process.env.GITHUB_TOKEN = 'gha-token' - process.env.GITHUB_SHA = '123abc' - process.env.GITHUB_ACTOR = 'monalisa' - process.env.GITHUB_ACTION = '__monalisa/octocat' - process.env.GITHUB_ACTION_PATH = 'something' - - jest.spyOn(core, 'getInput').mockImplementation(param => { - switch (param) { - case 'artifact_name': - return 'github-pages' - case 'token': - return process.env.GITHUB_TOKEN - default: - return process.env[`INPUT_${param.toUpperCase()}`] || '' - } - }) - - jest.spyOn(core, 'setOutput').mockImplementation(param => { - return param - }) - - jest.spyOn(core, 'setFailed').mockImplementation(param => { - return param - }) - // Mock error/warning/info/debug - jest.spyOn(core, 'error').mockImplementation(jest.fn()) - jest.spyOn(core, 'warning').mockImplementation(jest.fn()) - jest.spyOn(core, 'info').mockImplementation(jest.fn()) - jest.spyOn(core, 'debug').mockImplementation(jest.fn()) - }) - - describe('#create', () => { - afterEach(() => { - // Remove mock for `core.getInput('preview')` - delete process.env.INPUT_PREVIEW - }) - - it('can successfully create a deployment', async () => { - process.env.GITHUB_SHA = 'valid-build-version' - - const artifactExchangeScope = nock(`http://my-url`) - .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') - .reply(200, { - value: [ - { url: 'https://another-artifact.com', name: 'another-artifact' }, - { url: 'https://fake-artifact.com', name: 'github-pages' } - ] - }) - - const createDeploymentScope = nock('https://api.github.com') - .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { - artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', - pages_build_version: process.env.GITHUB_SHA, - oidc_token: fakeJwt - }) - .reply(200, { - status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, - page_url: 'https://actions.github.io/is-awesome' - }) - - core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) - - // Create the deployment - const deployment = new Deployment() - await deployment.create(fakeJwt) - - expect(core.setFailed).not.toHaveBeenCalled() - expect(core.info).toHaveBeenLastCalledWith( - expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`)) - ) - - artifactExchangeScope.done() - createDeploymentScope.done() - }) - - it('can successfully create a preview deployment', async () => { - process.env.GITHUB_SHA = 'valid-build-version' - - const artifactExchangeScope = nock(`http://my-url`) - .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') - .reply(200, { - value: [ - { url: 'https://another-artifact.com', name: 'another-artifact' }, - { url: 'https://fake-artifact.com', name: 'github-pages' } - ] - }) - - const createDeploymentScope = nock('https://api.github.com') - .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { - artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', - pages_build_version: process.env.GITHUB_SHA, - oidc_token: fakeJwt, - preview: true - }) - .reply(200, { - status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, - page_url: 'https://actions.github.io/is-awesome', - preview_url: 'https://actions.drafts.github.io/is-awesome' - }) - - core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) - - // Return `"true"` for `core.getInput("preview")` - process.env.INPUT_PREVIEW = 'true' - - // Create the deployment - const deployment = new Deployment() - await deployment.create(fakeJwt) - - expect(core.setFailed).not.toHaveBeenCalled() - expect(core.info).toHaveBeenLastCalledWith( - expect.stringMatching(new RegExp(`^Created deployment for ${process.env.GITHUB_SHA}`)) - ) - - artifactExchangeScope.done() - createDeploymentScope.done() - }) - - it('reports errors with failed artifact exchange', async () => { - process.env.GITHUB_SHA = 'invalid-build-version' - const artifactExchangeScope = nock(`http://my-url`) - .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') - .reply(400, {}) - - // Create the deployment - const deployment = new Deployment() - await expect(deployment.create()).rejects.toEqual( - new Error( - `Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad Request` - ) - ) - - artifactExchangeScope.done() - }) - - it('reports errors with failed deployments', async () => { - process.env.GITHUB_SHA = 'invalid-build-version' - const artifactExchangeScope = nock(`http://my-url`) - .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') - .reply(200, { value: [{ url: 'https://invalid-artifact.com', name: 'github-pages' }] }) - - const createDeploymentScope = nock('https://api.github.com') - .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { - artifact_url: 'https://invalid-artifact.com&%24expand=SignedContent', - pages_build_version: process.env.GITHUB_SHA - }) - .reply(400, { message: 'Bad request' }) - - // Create the deployment - const deployment = new Deployment() - await expect(deployment.create()).rejects.toEqual( - new Error( - `Failed to create deployment (status: 400) with build version ${process.env.GITHUB_SHA}. Responded with: Bad request` - ) - ) - - artifactExchangeScope.done() - createDeploymentScope.done() - }) - }) - - describe('#check', () => { - it('sets output to success when deployment is successful', async () => { - process.env.GITHUB_SHA = 'valid-build-version' - - const artifactExchangeScope = nock(`http://my-url`) - .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') - .reply(200, { - value: [ - { url: 'https://another-artifact.com', name: 'another-artifact' }, - { url: 'https://fake-artifact.com', name: 'github-pages' } - ] - }) - - const createDeploymentScope = nock('https://api.github.com') - .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { - artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', - pages_build_version: process.env.GITHUB_SHA, - oidc_token: fakeJwt - }) - .reply(200, { - status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, - page_url: 'https://actions.github.io/is-awesome' - }) - - const deploymentStatusScope = nock('https://api.github.com') - .get(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`) - .reply(200, { - status: 'succeed' - }) - - core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) - core.GetInput = jest.fn(input => { - switch (input) { - case 'timeout': - return 10 * 1000 - case 'reporting_interval': - return 0 - } - }) - - // Create the deployment - const deployment = new Deployment() - await deployment.create(fakeJwt) - await deployment.check() - - expect(core.setOutput).toBeCalledWith('status', 'succeed') - expect(core.info).toHaveBeenLastCalledWith('Reported success!') - - artifactExchangeScope.done() - createDeploymentScope.done() - deploymentStatusScope.done() - }) - }) - - describe('#cancel', () => { - it('can successfully cancel a deployment', async () => { - process.env.GITHUB_SHA = 'valid-build-version' - - const artifactExchangeScope = nock(`http://my-url`) - .get('/_apis/pipelines/workflows/123/artifacts?api-version=6.0-preview') - .reply(200, { - value: [ - { url: 'https://another-artifact.com', name: 'another-artifact' }, - { url: 'https://fake-artifact.com', name: 'github-pages' } - ] - }) - - const createDeploymentScope = nock('https://api.github.com') - .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments`, { - artifact_url: 'https://fake-artifact.com&%24expand=SignedContent', - pages_build_version: process.env.GITHUB_SHA, - oidc_token: fakeJwt - }) - .reply(200, { - status_url: `https://api.github.com/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}`, - page_url: 'https://actions.github.io/is-awesome' - }) - - const cancelDeploymentScope = nock('https://api.github.com') - .post(`/repos/${process.env.GITHUB_REPOSITORY}/pages/deployments/${process.env.GITHUB_SHA}/cancel`) - .reply(200, {}) - - core.getIDToken = jest.fn().mockResolvedValue(fakeJwt) - - // Create the deployment - const deployment = new Deployment() - await deployment.create(fakeJwt) - - // Cancel it - await deployment.cancel() - - expect(core.info).toHaveBeenLastCalledWith(`Canceled deployment with ID ${process.env.GITHUB_SHA}`) - - artifactExchangeScope.done() - createDeploymentScope.done() - cancelDeploymentScope.done() - }) - }) -}) diff --git a/src/api-client.js b/src/functions/api-client.js similarity index 100% rename from src/api-client.js rename to src/functions/api-client.js diff --git a/src/context.js b/src/functions/context.js similarity index 100% rename from src/context.js rename to src/functions/context.js diff --git a/src/deployment.js b/src/functions/deployment.js similarity index 100% rename from src/deployment.js rename to src/functions/deployment.js diff --git a/src/index.js b/src/index.js index 73a4b02..82be417 100644 --- a/src/index.js +++ b/src/index.js @@ -4,8 +4,8 @@ const core = require('@actions/core') -const { Deployment } = require('./deployment') -const getContext = require('./context') +const { Deployment } = require('./functions/deployment') +const getContext = require('./functions/context') const deployment = new Deployment()