Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add and update tests
Browse files Browse the repository at this point in the history
alicelovescake committed Apr 21, 2024

Verified

This commit was signed with the committer’s verified signature.
SergeyKopienko Sergey Kopienko
1 parent 919ed29 commit 35f9170
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion spec/index.spec.ts
Original file line number Diff line number Diff line change
@@ -430,7 +430,7 @@ Notes: <!-- One-line Change Summary Here-->`,
const pr = {
body: `Backport of #14
See that PR for details.
Notes: <!-- One-line Change Summary Here-->`,
Notes: new cool stuff added`,
created_at: '2018-11-01T17:29:51Z',
head: {
ref: '123456789iuytdxcvbnjhfdriuyfedfgy54escghjnbg',
1 change: 1 addition & 0 deletions spec/operations.spec.ts
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ const backportPROpenedEvent = require('./fixtures/backport_pull_request.opened.j
jest.mock('../src/utils', () => ({
tagBackportReviewers: jest.fn().mockReturnValue(Promise.resolve()),
isSemverMinorPR: jest.fn().mockReturnValue(false),
updateManualBackportReleaseNotes: jest.fn(),
}));

jest.mock('../src/utils/label-utils', () => ({
59 changes: 57 additions & 2 deletions spec/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import * as logUtils from '../src/utils/log-util';
import { LogLevel } from '../src/enums';
import { tagBackportReviewers } from '../src/utils';
import {
tagBackportReviewers,
updateManualBackportReleaseNotes,
} from '../src/utils';
import * as utils from '../src/utils';
import * as logUtils from '../src/utils/log-util';

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

jest.mock('../src/constants', () => ({
...jest.requireActual('../src/constants'),
@@ -74,4 +80,53 @@ describe('utils', () => {
);
});
});

describe('updateManualBackportReleaseNotes', () => {
const octokit = {
pulls: {
update: jest.fn(),
get: jest.fn(),
},
};

const context = {
octokit,
repo: jest.fn((obj) => obj),
...backportPROpenedEvent,
};

const backportPRMissingReleaseNotes =
backportPROpenedEvent.payload.pull_request;
const backportPRWithReleaseNotes =
backportPRMergedEvent.payload.pull_request;
const originalPRWithReleaseNotes = PROpenedEvent.payload.pull_request;

beforeEach(() => {
jest.clearAllMocks();
});

it('should not update backport PR if release notes match original PR', async () => {
await updateManualBackportReleaseNotes(
context,
backportPRWithReleaseNotes,
originalPRWithReleaseNotes,
);

expect(context.octokit.pulls.update).not.toHaveBeenCalled();
});

it('should update backport PR if release notes do not match original PR', async () => {
jest.spyOn(utils, 'getOriginalBackportNumber').mockResolvedValue(1234);
await updateManualBackportReleaseNotes(
context,
backportPRMissingReleaseNotes,
originalPRWithReleaseNotes,
);

expect(context.octokit.pulls.update).toHaveBeenCalledWith({
pull_number: 7,
body: 'Backport of #1234\n\nSee that PR for details.\n\n\nNotes: new cool stuff added',
});
});
});
});

0 comments on commit 35f9170

Please sign in to comment.