|
| 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 | +}); |
0 commit comments