Skip to content

Commit

Permalink
chore: Add regression tests for parsing linked PR info in description…
Browse files Browse the repository at this point in the history
… frontmatter

Signed-off-by: Yoriyasu Yano <430092+yorinasub17@users.noreply.github.com>
  • Loading branch information
yorinasub17 committed Oct 19, 2023
1 parent 1c39199 commit 3890118
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions src/engine/from_github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,113 @@ test("multiple file changes from GitHub is parsed correctly", async () => {
},
]);
});

test("extracts linked PRs in front matter", async () => {
// View PR at
// https://github.com/fensak-test/test-fensak-rules-engine/pull/39
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 39);
expect(patches.metadata).toEqual({
sourceBranch: "test/one-linked",
targetBranch: "main",
linkedPRs: [
{
repo: "",
prNum: 1,
isMerged: false,
isClosed: false,
},
],
});
});

test("extracts closed linked PRs in front matter", async () => {
// View PR at
// https://github.com/fensak-test/test-fensak-rules-engine/pull/40
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 40);
expect(patches.metadata).toEqual({
sourceBranch: "test/one-linked-closed",
targetBranch: "main",
linkedPRs: [
{
repo: "",
prNum: 38,
isMerged: false,
isClosed: true,
},
],
});
});

test("extracts merged linked PRs in front matter", async () => {
// View PR at
// https://github.com/fensak-test/test-fensak-rules-engine/pull/42
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 42);
expect(patches.metadata).toEqual({
sourceBranch: "test/one-linked-merged",
targetBranch: "main",
linkedPRs: [
{
repo: "",
prNum: 41,
isMerged: true,
isClosed: true,
},
],
});
});

test("extracts external linked PRs in front matter", async () => {
// View PR at
// https://github.com/fensak-test/test-fensak-rules-engine/pull/44
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 44);
expect(patches.metadata).toEqual({
sourceBranch: "test/external-linked",
targetBranch: "main",
linkedPRs: [
{
repo: "terraform-null-testfensak",
prNum: 1,
isMerged: false,
isClosed: true,
},
],
});
});

test("extracts multiple linked PRs in front matter", async () => {
// View PR at
// https://github.com/fensak-test/test-fensak-rules-engine/pull/43
const patches = await patchFromGitHubPullRequest(octokit, testRepo, 43);
expect(patches.metadata).toEqual({
sourceBranch: "test/multiple-linked",
targetBranch: "main",
linkedPRs: [
{
repo: "",
prNum: 1,
isMerged: false,
isClosed: false,
},
{
repo: "",
prNum: 38,
isMerged: false,
isClosed: true,
},
{
repo: "",
prNum: 41,
isMerged: true,
isClosed: true,
},
],
});
});

test("errors with bad front matter", async () => {
// View PR at
// https://github.com/fensak-test/test-fensak-rules-engine/pull/45
expect(
async () => await patchFromGitHubPullRequest(octokit, testRepo, 45),
).rejects.toThrow(TypeError);
});

0 comments on commit 3890118

Please sign in to comment.