forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfailureNotifier.test.js
59 lines (53 loc) · 2.08 KB
/
failureNotifier.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const assertions = require('./assertions/failureNotifierAssertions');
const mocks = require('./mocks/failureNotifierMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
jest.setTimeout(90 * 1000);
let mockGithub;
const FILES_TO_COPY_INTO_TEST_REPO = [
{
src: path.resolve(__dirname, '..', '.github', 'workflows', 'failureNotifier.yml'),
dest: '.github/workflows/failureNotifier.yml',
},
];
describe('test workflow failureNotifier', () => {
const actor = 'Dummy Actor';
beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
repo: {
testFailureNotifierWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
// if any branches besides main are need add: pushedBranches: ['staging', 'production'],
},
},
});
await mockGithub.setup();
});
afterEach(async () => {
await mockGithub.teardown();
});
it('runs the notify failure when main fails', async () => {
const repoPath = mockGithub.repo.getPath('testFailureNotifierWorkflowRepo') || '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml');
let act = new ExtendedAct(repoPath, workflowPath);
const event = 'workflow_run';
act = act.setEvent({
workflow_run: {
name: 'Process new code merged to main',
conclusion: 'failure',
},
});
const testMockSteps = {
notifyFailure: mocks.FAILURENOTIFIER__NOTIFYFAILURE__STEP_MOCKS,
};
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'),
mockSteps: testMockSteps,
actor,
});
// assert execution with imported assertions
assertions.assertNotifyFailureJobExecuted(result);
});
});