Skip to content

Commit fdf2284

Browse files
test: add test to updateManualBackport
1 parent 5d028ba commit fdf2284

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

spec/fixtures/backport_pull_request.closed.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"head": {
1313
"ref": "123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg"
1414
},
15+
"base": {
16+
"ref": "main",
17+
"repo": {
18+
"default_branch": "main"
19+
}
20+
},
1521
"body": "Backport of #14\nSee that PR for details.\nNotes: <!-- One-line Change Summary Here-->",
1622
"created_at": "2018-11-01T17:29:51Z",
1723
"merged_at": "2018-11-01T17:30:11Z",

spec/fixtures/backport_pull_request.merged.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"head": {
1313
"ref": "123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg"
1414
},
15+
"base": {
16+
"ref": "main",
17+
"repo": {
18+
"default_branch": "main"
19+
}
20+
},
1521
"body": "Backport of #14\nSee that PR for details.\nNotes: <!-- One-line Change Summary Here-->",
1622
"created_at": "2018-11-01T17:29:51Z",
1723
"merged_at": "2018-11-01T17:30:11Z",

spec/index.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ Notes: <!-- One-line Change Summary Here-->`,
392392
head: {
393393
ref: '123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg',
394394
},
395+
base: {
396+
ref: 'main',
397+
repo: {
398+
default_branch: 'main',
399+
},
400+
},
395401
labels: [
396402
{
397403
color: 'ededed',
@@ -429,6 +435,12 @@ Notes: <!-- One-line Change Summary Here-->`,
429435
head: {
430436
ref: '123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg',
431437
},
438+
base: {
439+
ref: 'main',
440+
repo: {
441+
default_branch: 'main',
442+
},
443+
},
432444
labels: [
433445
{
434446
color: 'ededed',

spec/operations.spec.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import * as path from 'path';
55
import simpleGit from 'simple-git';
66
import { initRepo } from '../src/operations/init-repo';
77
import { setupRemotes } from '../src/operations/setup-remotes';
8+
import { tagBackportReviewers } from '../src/utils';
9+
import { PRChange } from '../src/enums';
10+
import { updateManualBackport } from '../src/operations/update-manual-backport';
811

912
let dirObject: { dir?: string } | null = null;
1013

@@ -13,6 +16,22 @@ const saveDir = (o: { dir: string }) => {
1316
return o.dir;
1417
};
1518

19+
const backportPRMergedEvent = require('./fixtures/backport_pull_request.merged.json');
20+
const backportPRClosedEvent = require('./fixtures/backport_pull_request.closed.json');
21+
const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.json');
22+
23+
jest.mock('../src/utils', () => ({
24+
tagBackportReviewers: jest.fn().mockReturnValue(Promise.resolve()),
25+
isSemverMinorPR: jest.fn().mockReturnValue(false),
26+
}));
27+
28+
jest.mock('../src/utils/label-utils', () => ({
29+
labelExistsOnPR: jest.fn().mockResolvedValue(true),
30+
getSemverLabel: jest.fn().mockResolvedValue(false),
31+
addLabels: jest.fn(),
32+
removeLabel: jest.fn(),
33+
}));
34+
1635
describe('runner', () => {
1736
jest.setTimeout(30000);
1837
console.error = jest.fn();
@@ -101,4 +120,46 @@ describe('runner', () => {
101120
}
102121
});
103122
});
123+
124+
describe('updateManualBackport()', () => {
125+
let context: any;
126+
let octokit = {
127+
pulls: {
128+
get: jest.fn().mockReturnValue(Promise.resolve({})),
129+
},
130+
issues: {
131+
createComment: jest.fn().mockReturnValue(Promise.resolve({})),
132+
listComments: jest.fn().mockReturnValue(Promise.resolve({ data: [] })),
133+
},
134+
};
135+
136+
it('tags reviewers on manual backport creation', async () => {
137+
context = {
138+
...backportPROpenedEvent,
139+
octokit,
140+
repo: jest.fn(),
141+
};
142+
await updateManualBackport(context, PRChange.OPEN, 1234);
143+
expect(tagBackportReviewers).toHaveBeenCalled();
144+
});
145+
146+
it('does not tag reviewers on merged PRs', async () => {
147+
context = {
148+
...backportPRMergedEvent,
149+
octokit,
150+
repo: jest.fn(),
151+
};
152+
await updateManualBackport(context, PRChange.MERGE, 1234);
153+
expect(tagBackportReviewers).not.toHaveBeenCalled();
154+
});
155+
it('does not tag reviewers on closed PRs', async () => {
156+
context = {
157+
...backportPRClosedEvent,
158+
octokit,
159+
repo: jest.fn(),
160+
};
161+
await updateManualBackport(context, PRChange.CLOSE, 1234);
162+
expect(tagBackportReviewers).not.toHaveBeenCalled();
163+
});
164+
});
104165
});

0 commit comments

Comments
 (0)