Skip to content

Commit

Permalink
test: add test to updateManualBackport
Browse files Browse the repository at this point in the history
  • Loading branch information
alicelovescake committed Apr 1, 2024
1 parent 5d028ba commit fdf2284
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/fixtures/backport_pull_request.closed.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"head": {
"ref": "123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg"
},
"base": {
"ref": "main",
"repo": {
"default_branch": "main"
}
},
"body": "Backport of #14\nSee that PR for details.\nNotes: <!-- One-line Change Summary Here-->",
"created_at": "2018-11-01T17:29:51Z",
"merged_at": "2018-11-01T17:30:11Z",
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/backport_pull_request.merged.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"head": {
"ref": "123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg"
},
"base": {
"ref": "main",
"repo": {
"default_branch": "main"
}
},
"body": "Backport of #14\nSee that PR for details.\nNotes: <!-- One-line Change Summary Here-->",
"created_at": "2018-11-01T17:29:51Z",
"merged_at": "2018-11-01T17:30:11Z",
Expand Down
12 changes: 12 additions & 0 deletions spec/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,12 @@ Notes: <!-- One-line Change Summary Here-->`,
head: {
ref: '123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg',
},
base: {
ref: 'main',
repo: {
default_branch: 'main',
},
},
labels: [
{
color: 'ededed',
Expand Down Expand Up @@ -429,6 +435,12 @@ Notes: <!-- One-line Change Summary Here-->`,
head: {
ref: '123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg',
},
base: {
ref: 'main',
repo: {
default_branch: 'main',
},
},
labels: [
{
color: 'ededed',
Expand Down
61 changes: 61 additions & 0 deletions spec/operations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import * as path from 'path';
import simpleGit from 'simple-git';
import { initRepo } from '../src/operations/init-repo';
import { setupRemotes } from '../src/operations/setup-remotes';
import { tagBackportReviewers } from '../src/utils';
import { PRChange } from '../src/enums';
import { updateManualBackport } from '../src/operations/update-manual-backport';

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

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

const backportPRMergedEvent = require('./fixtures/backport_pull_request.merged.json');
const backportPRClosedEvent = require('./fixtures/backport_pull_request.closed.json');
const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.json');

jest.mock('../src/utils', () => ({
tagBackportReviewers: jest.fn().mockReturnValue(Promise.resolve()),
isSemverMinorPR: jest.fn().mockReturnValue(false),
}));

jest.mock('../src/utils/label-utils', () => ({
labelExistsOnPR: jest.fn().mockResolvedValue(true),
getSemverLabel: jest.fn().mockResolvedValue(false),
addLabels: jest.fn(),
removeLabel: jest.fn(),
}));

describe('runner', () => {
jest.setTimeout(30000);
console.error = jest.fn();
Expand Down Expand Up @@ -101,4 +120,46 @@ describe('runner', () => {
}
});
});

describe('updateManualBackport()', () => {
let context: any;
let octokit = {
pulls: {
get: jest.fn().mockReturnValue(Promise.resolve({})),
},
issues: {
createComment: jest.fn().mockReturnValue(Promise.resolve({})),
listComments: jest.fn().mockReturnValue(Promise.resolve({ data: [] })),
},
};

it('tags reviewers on manual backport creation', async () => {
context = {
...backportPROpenedEvent,
octokit,
repo: jest.fn(),
};
await updateManualBackport(context, PRChange.OPEN, 1234);
expect(tagBackportReviewers).toHaveBeenCalled();
});

it('does not tag reviewers on merged PRs', async () => {
context = {
...backportPRMergedEvent,
octokit,
repo: jest.fn(),
};
await updateManualBackport(context, PRChange.MERGE, 1234);
expect(tagBackportReviewers).not.toHaveBeenCalled();
});
it('does not tag reviewers on closed PRs', async () => {
context = {
...backportPRClosedEvent,
octokit,
repo: jest.fn(),
};
await updateManualBackport(context, PRChange.CLOSE, 1234);
expect(tagBackportReviewers).not.toHaveBeenCalled();
});
});
});

0 comments on commit fdf2284

Please sign in to comment.