Skip to content

Commit

Permalink
add unitary test for fork repository with different name
Browse files Browse the repository at this point in the history
  • Loading branch information
rgdoliveira committed Oct 4, 2023
1 parent 2932ab6 commit 503f39d
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions test/unitary/service/git/git-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,49 +119,62 @@ test.each([
[
"success: same source and target owner",
true,
["target1", "target1", "repoA"],
["target1", "repoA", "target1", "repoA"],
],
[
"failure: same source and target owner",
false,
["target2", "target2", "repoA"],
["target2", "repoA", "target2", "repoA"],
],
[
"success: different source and target owner",
true,
["target3", "source", "repoA"],
["target3", "repoA", "source", "repoA"],
],
[
"failure: different source and target owner",
false,
["target4", "source", "repoA"],
["target4", "repoA", "source", "repoA"],
],
[
"success: different source and target owner / different repo name",
true,
["target5", "repoA", "source", "repoA_fork"],
],
[
"failure: different source and target owner / different repo name",
false,
["target6", "repoA", "source", "no_fork"],
],
])(
"getForkName %p",
async (_title: string, testForSuccess: boolean, args: string[]) => {
const moctokit = new Moctokit();
if (testForSuccess) {
moctokit.rest.repos
.get({ owner: args[1], repo: args[2] })
.get({ owner: args[0], repo: args[1] })
.reply({ status: 200, data: {} });
moctokit.rest.repos
.get({ owner: args[2], repo: args[3] })
.reply({ status: 200, data: {} });
moctokit.rest.repos.listForks({ owner: args[0], repo: args[2] }).reply({
moctokit.rest.repos.listForks({ owner: args[0], repo: args[1] }).reply({
status: 200,
data: [{ name: args[2], owner: { login: args[1] } }],
data: [{ name: args[3], owner: { login: args[2] } }],
});

await expect(git.getForkName(args[0], args[1], args[2])).resolves.toBe(
args[2]
await expect(git.getForkName(args[0], args[2], args[1])).resolves.toBe(
args[3]
);
} else {
moctokit.rest.repos
.get({ owner: args[1], repo: args[2] })
.get({ owner: args[0], repo: args[1] })
.reply({ status: 404, data: {} });
moctokit.rest.repos
.listForks({ owner: args[0], repo: args[2] })
.listForks({ owner: args[2], repo: args[3] })
.reply({ status: 200, data: [] });

await expect(
git.getForkName(args[0], args[1], args[2])
git.getForkName(args[0], args[2], args[1])
).rejects.toThrowError();
}
}
Expand Down

0 comments on commit 503f39d

Please sign in to comment.