Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roryabraham committed Nov 18, 2023
1 parent 80c05e2 commit 402d64f
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions tests/unit/createOrUpdateStagingDeployTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
*/
const core = require('@actions/core');
const fns = require('date-fns');
const {vol} = require('memfs');
const path = require('path');
const CONST = require('../../.github/libs/CONST');
const GitUtils = require('../../.github/libs/GitUtils');
const GithubUtils = require('../../.github/libs/GithubUtils');
const run = require('../../.github/actions/javascript/createOrUpdateStagingDeploy/createOrUpdateStagingDeploy');

const PATH_TO_PACKAGE_JSON = path.resolve(__dirname, '../../package.json');

jest.mock('fs');
const mockGetInput = jest.fn();
const mockListIssues = jest.fn();
const mockGetPullRequestsMergedBetween = jest.fn();
Expand Down Expand Up @@ -50,6 +55,11 @@ beforeAll(() => {

// Mock GitUtils
GitUtils.getPullRequestsMergedBetween = mockGetPullRequestsMergedBetween;

vol.reset();
vol.fromJSON({
[PATH_TO_PACKAGE_JSON]: JSON.stringify({version: '1.0.2-1'}),
});
});

afterEach(() => {
Expand Down Expand Up @@ -139,14 +149,14 @@ describe('createOrUpdateStagingDeployCash', () => {
const baseNewPullRequests = [6, 7, 8];

test('creates new issue when there is none open', async () => {
vol.reset();
vol.fromJSON({
[PATH_TO_PACKAGE_JSON]: JSON.stringify({version: '1.0.2-1'}),
});
mockGetInput.mockImplementation((arg) => {

Check failure on line 156 in tests/unit/createOrUpdateStagingDeployTest.js

View workflow job for this annotation

GitHub Actions / lint

Prefer an early return to a conditionally-wrapped function body
if (arg === 'GITHUB_TOKEN') {
return 'fake_token';
}

if (arg === 'NPM_VERSION') {
return '1.0.2-1';
}
});

mockGetPullRequestsMergedBetween.mockImplementation((fromRef, toRef) => {
Expand Down Expand Up @@ -231,14 +241,14 @@ describe('createOrUpdateStagingDeployCash', () => {
];

test('with NPM_VERSION input, pull requests, and deploy blockers', async () => {
vol.reset();
vol.fromJSON({
[PATH_TO_PACKAGE_JSON]: JSON.stringify({version: '1.0.2-2'}),
});
mockGetInput.mockImplementation((arg) => {

Check failure on line 248 in tests/unit/createOrUpdateStagingDeployTest.js

View workflow job for this annotation

GitHub Actions / lint

Prefer an early return to a conditionally-wrapped function body
if (arg === 'GITHUB_TOKEN') {
return 'fake_token';
}

if (arg === 'NPM_VERSION') {
return '1.0.2-2';
}
});

// New pull requests to add to open StagingDeployCash
Expand Down Expand Up @@ -309,6 +319,10 @@ describe('createOrUpdateStagingDeployCash', () => {
});

test('without NPM_VERSION input, just a new deploy blocker', async () => {
vol.reset();
vol.fromJSON({
[PATH_TO_PACKAGE_JSON]: JSON.stringify({version: '1.0.2-1'}),
});
mockGetInput.mockImplementation((arg) => {
if (arg !== 'GITHUB_TOKEN') {
return;
Expand Down

0 comments on commit 402d64f

Please sign in to comment.