-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit testing coverage for new action
- Loading branch information
1 parent
9cf6b24
commit a9af7a0
Showing
2 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
const run = require('../../.github/actions/awaitStagingDeploys/awaitStagingDeploys'); | ||
const GitHubUtils = require('../../.github/libs/GithubUtils'); | ||
|
||
// Lower poll rate to speed up tests | ||
const TEST_POLL_RATE = 1; | ||
const COMPLETED_WORKFLOW = {status: 'completed'}; | ||
const INCOMPLETE_WORKFLOW = {status: 'in_progress'}; | ||
|
||
const mockListWorkflowRuns = jest.fn(); | ||
|
||
beforeAll(() => { | ||
// Mock octokit module | ||
const mocktokit = { | ||
actions: { | ||
listWorkflowRuns: mockListWorkflowRuns, | ||
}, | ||
}; | ||
GitHubUtils.octokitInternal = mocktokit; | ||
GitHubUtils.POLL_RATE = TEST_POLL_RATE; | ||
}); | ||
|
||
describe('awaitStagingDeploys', () => { | ||
test('Should wait for all running staging deploys to finish', () => { | ||
mockListWorkflowRuns.mockResolvedValueOnce({ | ||
data: { | ||
workflow_runs: [ | ||
COMPLETED_WORKFLOW, | ||
INCOMPLETE_WORKFLOW, | ||
INCOMPLETE_WORKFLOW, | ||
], | ||
}, | ||
}); | ||
mockListWorkflowRuns.mockResolvedValueOnce({ | ||
data: { | ||
workflow_runs: [ | ||
COMPLETED_WORKFLOW, | ||
COMPLETED_WORKFLOW, | ||
INCOMPLETE_WORKFLOW, | ||
], | ||
}, | ||
}); | ||
mockListWorkflowRuns.mockResolvedValueOnce({ | ||
data: { | ||
workflow_runs: [ | ||
COMPLETED_WORKFLOW, | ||
COMPLETED_WORKFLOW, | ||
COMPLETED_WORKFLOW, | ||
], | ||
}, | ||
}); | ||
|
||
const consoleSpy = jest.spyOn(console, 'log'); | ||
return run() | ||
.then(() => { | ||
expect(consoleSpy).toHaveBeenCalledTimes(3); | ||
expect(consoleSpy).toHaveBeenNthCalledWith(1, 'Found 2 staging deploys still running...'); | ||
expect(consoleSpy).toHaveBeenNthCalledWith(2, 'Found 1 staging deploy still running...'); | ||
expect(consoleSpy).toHaveBeenLastCalledWith('No current staging deploys found'); | ||
}); | ||
}); | ||
}); |