Skip to content

Commit

Permalink
test: snapshot pr automerge result
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Apr 15, 2021
1 parent b070646 commit 6d17d7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
15 changes: 15 additions & 0 deletions lib/workers/pr/__snapshots__/automerge.spec.ts.snap
@@ -0,0 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`workers/pr/automerge checkAutoMerge(pr, config) should automerge comment 1`] = `true`;

exports[`workers/pr/automerge checkAutoMerge(pr, config) should automerge if enabled and pr is mergeable 1`] = `true`;

exports[`workers/pr/automerge checkAutoMerge(pr, config) should not automerge if enabled and pr is mergeable but branch status is not success 1`] = `false`;

exports[`workers/pr/automerge checkAutoMerge(pr, config) should not automerge if enabled and pr is mergeable but cannot rebase 1`] = `false`;

exports[`workers/pr/automerge checkAutoMerge(pr, config) should not automerge if enabled and pr is mergeable but unstable 1`] = `false`;

exports[`workers/pr/automerge checkAutoMerge(pr, config) should not automerge if enabled and pr is unmergeable 1`] = `false`;

exports[`workers/pr/automerge checkAutoMerge(pr, config) should remove previous automerge comment when rebasing 1`] = `true`;
23 changes: 16 additions & 7 deletions lib/workers/pr/automerge.spec.ts
Expand Up @@ -28,15 +28,18 @@ describe(getName(__filename), () => {
config.automerge = true;
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
platform.mergePr.mockResolvedValueOnce(true);
await prAutomerge.checkAutoMerge(pr, config);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.mergePr).toHaveBeenCalledTimes(1);
});
it('should automerge comment', async () => {
config.automerge = true;
config.automergeType = 'pr-comment';
config.automergeComment = '!merge';
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
await prAutomerge.checkAutoMerge(pr, config);
platform.ensureComment.mockResolvedValueOnce(true);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(0);
expect(platform.ensureComment).toHaveBeenCalledTimes(1);
});
Expand All @@ -46,33 +49,39 @@ describe(getName(__filename), () => {
config.automergeComment = '!merge';
config.rebaseRequested = true;
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
await prAutomerge.checkAutoMerge(pr, config);
platform.ensureComment.mockResolvedValueOnce(true);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.ensureCommentRemoval).toHaveBeenCalledTimes(1);
expect(platform.ensureComment).toHaveBeenCalledTimes(1);
});
it('should not automerge if enabled and pr is mergeable but cannot rebase', async () => {
config.automerge = true;
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.green);
git.isBranchModified.mockResolvedValueOnce(true);
await prAutomerge.checkAutoMerge(pr, config);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.mergePr).toHaveBeenCalledTimes(0);
});
it('should not automerge if enabled and pr is mergeable but branch status is not success', async () => {
config.automerge = true;
platform.getBranchStatus.mockResolvedValueOnce(BranchStatus.yellow);
await prAutomerge.checkAutoMerge(pr, config);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.mergePr).toHaveBeenCalledTimes(0);
});
it('should not automerge if enabled and pr is mergeable but unstable', async () => {
config.automerge = true;
pr.canMerge = undefined;
await prAutomerge.checkAutoMerge(pr, config);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.mergePr).toHaveBeenCalledTimes(0);
});
it('should not automerge if enabled and pr is unmergeable', async () => {
config.automerge = true;
pr.isConflicted = true;
await prAutomerge.checkAutoMerge(pr, config);
const res = await prAutomerge.checkAutoMerge(pr, config);
expect(res).toMatchSnapshot();
expect(platform.mergePr).toHaveBeenCalledTimes(0);
});
});
Expand Down

0 comments on commit 6d17d7b

Please sign in to comment.