Skip to content

Commit 88f6440

Browse files
GHA-81 Add UTs for RequestReview (#240)
1 parent ac70308 commit 88f6440

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

RequestReview/RequestReview.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import * as github from '@actions/github';
2+
import { LogTester } from '../tests/LogTester';
3+
import { createOctokitRestStub } from '../tests/OctokitRestStub';
4+
import { RequestReview } from './RequestReview';
5+
import { jiraClientStub } from '../tests/JiraClientStub';
6+
7+
describe('RequestReview', () => {
8+
const originalKeys = Object.keys(process.env);
9+
let logTester: LogTester;
10+
11+
beforeEach(() => {
12+
logTester = new LogTester();
13+
for (const key of Object.keys(process.env)) {
14+
if (!originalKeys.includes(key)) {
15+
// Otherwise, changes form previous UT are propagated to the next one
16+
delete process.env[key];
17+
}
18+
}
19+
process.env['GITHUB_REPOSITORY'] = 'test-owner/test-repo';
20+
process.env['INPUT_GITHUB-TOKEN'] = 'fake';
21+
github.context.payload = {
22+
pull_request: {
23+
number: 42,
24+
title: "PR Title",
25+
},
26+
requested_reviewer: {
27+
login: "test-user",
28+
type: "User",
29+
},
30+
sender: {
31+
login: 'test-user',
32+
type: "User"
33+
}
34+
};
35+
});
36+
37+
afterEach(() => {
38+
logTester.afterEach();
39+
});
40+
41+
// This is just a smoke test to make sure the other components works together. Details are tested in their respective classes
42+
it('Processes all issues in title', async () => {
43+
const sut = new RequestReview();
44+
(sut as any).jira = jiraClientStub;
45+
(sut as any).rest = createOctokitRestStub("GHA-42 and GHA-43");
46+
(sut as any).findEmail = async function (login: string): Promise<string> {
47+
48+
}
49+
await sut.run();
50+
expect(logTester.logsParams).toStrictEqual([
51+
"Loading PR #42",
52+
"Invoked jira.moveIssue('GHA-42', 'Request Review', null)",
53+
"Invoked jira.assignIssueToEmail('GHA-42', '[email protected]')",
54+
"Invoked jira.moveIssue('GHA-43', 'Request Review', null)",
55+
"Invoked jira.assignIssueToEmail('GHA-43', '[email protected]')",
56+
"Done",
57+
]);
58+
});
59+
});

dist/RequestReview/RequestReview.test.js

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/RequestReview/RequestReview.test.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)