forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateNewVersion.test.ts
169 lines (157 loc) · 8.77 KB
/
createNewVersion.test.ts
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/createNewVersionAssertions';
import mocks from './mocks/createNewVersionMocks';
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';
jest.setTimeout(90 * 1000); // 90 sec
let mockGithub: MockGithub;
const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
src: path.resolve(__dirname, '..', '.github', 'workflows', 'createNewVersion.yml'),
dest: '.github/workflows/createNewVersion.yml',
},
];
describe('test workflow createNewVersion', () => {
beforeAll(() => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
utils.removeMockRepoDir();
});
beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new MockGithub({
repo: {
testCreateNewVersionWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
},
},
});
await mockGithub.setup();
});
afterEach(async () => {
await mockGithub.teardown();
});
describe('event is workflow_call', () => {
const event = 'workflow_call';
const inputs = {
SEMVER_LEVEL: 'BUILD',
};
const secrets = {
LARGE_SECRET_PASSPHRASE: '3xtr3m3ly_53cr3t_p455w0rd',
OS_BOTIFY_COMMIT_TOKEN: 'dummy_osbotify_commit_token',
SLACK_WEBHOOK: 'dummy_webhook',
OS_BOTIFY_APP_ID: 'os_botify_app_id',
OS_BOTIFY_PRIVATE_KEY: 'os_botify_private_key',
};
const githubToken = 'dummy_github_token';
describe('actor is admin', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS;
it('executes full workflow', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath);
const testMockSteps = {
validateActor: validateActorMockSteps,
createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS,
};
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName),
});
assertions.assertValidateActorJobExecuted(result);
assertions.assertCreateNewVersionJobExecuted(result);
});
});
describe('actor is writer', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS;
it('executes full workflow', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath);
const testMockSteps = {
validateActor: validateActorMockSteps,
createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS,
};
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName),
});
assertions.assertValidateActorJobExecuted(result);
assertions.assertCreateNewVersionJobExecuted(result);
});
});
describe('actor is reader', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS;
it('stops after validation', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath);
const testMockSteps = {
validateActor: validateActorMockSteps,
createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS,
};
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName),
});
assertions.assertValidateActorJobExecuted(result);
assertions.assertCreateNewVersionJobExecuted(result, 'BUILD', false);
});
});
describe('one step fails', () => {
it('announces failure on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath);
const testMockSteps = {
validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS,
createNewVersion: utils.deepCopy(mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS),
};
testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], {}, {}, false);
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName),
});
assertions.assertValidateActorJobExecuted(result);
assertions.assertCreateNewVersionJobExecuted(result, 'BUILD', true, false);
});
});
it('chooses source branch depending on the SEMVER_LEVEL', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, {SEMVER_LEVEL: 'MAJOR'});
act = utils.setJobRunners(act, {createNewVersion: 'ubuntu-latest'}, workflowPath);
const testMockSteps = {
validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS,
createNewVersion: mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS,
};
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
actor: 'Dummy Author',
logFile: utils.getLogFilePath('createNewVersion', expect.getState().currentTestName),
});
assertions.assertValidateActorJobExecuted(result);
assertions.assertCreateNewVersionJobExecuted(result, 'MAJOR');
});
});
});