-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #34 Created the option to count the author of a PR as an approval. In the case of the "normal" rules it doesn't change the logic. In the case of the "and-distinct" rule we have to decide if we filter the author from the PR on evaluation time.
- Loading branch information
Showing
10 changed files
with
274 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { PullRequest, PullRequestReview } from "@octokit/webhooks-types"; | ||
import { DeepMockProxy, mock, mockDeep, MockProxy } from "jest-mock-extended"; | ||
|
||
import { PullRequestApi } from "../github/pullRequest"; | ||
import { ActionLogger, GitHubClient } from "../github/types"; | ||
|
||
describe("Pull Request API Tests", () => { | ||
let api: PullRequestApi; | ||
let logger: MockProxy<ActionLogger>; | ||
let client: DeepMockProxy<GitHubClient>; | ||
let pr: DeepMockProxy<PullRequest>; | ||
beforeEach(() => { | ||
logger = mock<ActionLogger>(); | ||
client = mockDeep<GitHubClient>(); | ||
pr = mockDeep<PullRequest>(); | ||
pr.number = 99; | ||
api = new PullRequestApi(client, pr, logger, { owner: "org", repo: "repo" }, ""); | ||
}); | ||
|
||
describe("Approvals", () => { | ||
const random = () => Math.floor(Math.random() * 1000); | ||
|
||
let reviews: PullRequestReview[]; | ||
beforeEach(() => { | ||
reviews = []; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore because the official type and the library type do not match | ||
client.rest.pulls.listReviews.mockResolvedValue({ data: reviews as unknown }); | ||
}); | ||
|
||
test("Should return approval", async () => { | ||
const mockReviews: PullRequestReview[] = [ | ||
{ state: "approved", user: { login: "yes-user", id: random() }, id: random() }, | ||
] as PullRequestReview[]; | ||
reviews.push(...mockReviews); | ||
|
||
const approvals = await api.listApprovedReviewsAuthors(false); | ||
expect(approvals).toEqual(["yes-user"]); | ||
}); | ||
|
||
test("Should return approvals and ignore other reviews", async () => { | ||
const mockReviews: PullRequestReview[] = [ | ||
{ state: "changes_requested", user: { login: "no-user", id: random() }, id: random() }, | ||
{ state: "approved", user: { login: "yes-user", id: random() }, id: random() }, | ||
{ state: "commented", user: { login: "other-user", id: random() }, id: random() }, | ||
] as PullRequestReview[]; | ||
reviews.push(...mockReviews); | ||
|
||
const approvals = await api.listApprovedReviewsAuthors(false); | ||
expect(approvals).toEqual(["yes-user"]); | ||
}); | ||
|
||
test("Should consider only oldest reviews per user", async () => { | ||
const mockReviews: PullRequestReview[] = [ | ||
{ state: "changes_requested", user: { login: "user-1", id: 1 }, id: 1000 }, | ||
{ state: "approved", user: { login: "user-2", id: 2 }, id: 1200 }, | ||
{ state: "approved", user: { login: "user-1", id: 1 }, id: 1500 }, | ||
{ state: "changes_requested", user: { login: "user-2", id: 2 }, id: 1600 }, | ||
] as PullRequestReview[]; | ||
reviews.push(...mockReviews); | ||
|
||
const approvals = await api.listApprovedReviewsAuthors(false); | ||
expect(approvals).toEqual(["user-1"]); | ||
}); | ||
|
||
test("Should return approvals and the author", async () => { | ||
pr.user.login = "abc"; | ||
const mockReviews: PullRequestReview[] = [ | ||
{ state: "changes_requested", user: { login: "no-user", id: random() }, id: random() }, | ||
{ state: "approved", user: { login: "yes-user", id: random() }, id: random() }, | ||
{ state: "commented", user: { login: "other-user", id: random() }, id: random() }, | ||
] as PullRequestReview[]; | ||
reviews.push(...mockReviews); | ||
|
||
const approvals = await api.listApprovedReviewsAuthors(true); | ||
expect(approvals).toEqual(["yes-user", "abc"]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.