Skip to content

Commit

Permalink
feat: feature test for PullRequestClosed event are done
Browse files Browse the repository at this point in the history
  • Loading branch information
skywarth committed Jun 26, 2024
1 parent 94761f0 commit 2f4b913
Show file tree
Hide file tree
Showing 8 changed files with 453 additions and 1 deletion.
100 changes: 100 additions & 0 deletions test/feature/PullRequest/pullRequestClosed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {describe, test, afterEach, vi, beforeAll} from "vitest";
import {CaseSlugs} from "../../../src/enums/CaseSlug";
import {StrategyTestSetup} from "../strategyTestSetup";
import PullRequestClosedStrategy from "../../../src/ActionHandler/PullRequest/PullRequestClosedStrategy";



import pullRequestClosedMergedPayload from '../../fixtures/events/pull_request/closed/merged/pull_request.closed.merged.json';
import pullRequestClosedMergedNoCommentsPayload from '../../fixtures/events/pull_request/closed/merged/pull_request.closed.merged.no_comments.json';
import pullRequestClosedNotMergedPayload from '../../fixtures/events/pull_request/closed/not_merged/pull_request.closed.not_merged.json';
import pullRequestClosedNotMergedNoCommentsPayload from '../../fixtures/events/pull_request/closed/not_merged/pull_request.closed.not_merged.no_comments.json';

import pullRequestReviewsListMany from '../../fixtures/data/pull_request_reviews/pull_request_reviews.list.many.json';
import pullRequestReviewsListFew from '../../fixtures/data/pull_request_reviews/pull_request_reviews.list.few.json';

import pullRequestListNotMerged from '../../fixtures/data/pulls/pulls.list.not-merged.json';



describe("Pull Request Opened Tests", () => {
const strategyTestSetup = new StrategyTestSetup();

beforeAll(() => {
strategyTestSetup.beforeAll();
});

afterEach(() => {
strategyTestSetup.afterEach();
});

describe.each([
{
description: "Merged, many reviews",
previousPrs: [],
pullRequestReviews: pullRequestReviewsListMany,
expectedCaseSlug: CaseSlugs.PullRequest.Closed.MergedManyReviews,
payload:pullRequestClosedMergedPayload
},
{
description: "Merged, few reviews",
previousPrs: [],
pullRequestReviews: pullRequestReviewsListFew,
expectedCaseSlug: CaseSlugs.PullRequest.Closed.MergedFewReviews,
payload:pullRequestClosedMergedPayload
},
{
description: "Merged, no reviews",
previousPrs: [],
pullRequestReviews: [],
expectedCaseSlug: CaseSlugs.PullRequest.Closed.MergedNoReviews,
payload:pullRequestClosedMergedNoCommentsPayload
},
{
description: "Not merged, many reviews",
previousPrs: [],
pullRequestReviews: pullRequestReviewsListMany,
expectedCaseSlug: CaseSlugs.PullRequest.Closed.NotMergedManyReviews,
payload:pullRequestClosedNotMergedPayload
},
{
description: "Not merged, few reviews",
previousPrs: [],
pullRequestReviews: pullRequestReviewsListFew,
expectedCaseSlug: CaseSlugs.PullRequest.Closed.NotMergedFewReviews,
payload:pullRequestClosedNotMergedPayload
},
{
description: "Not merged, no reviews",
previousPrs: [],
pullRequestReviews: [],
expectedCaseSlug: CaseSlugs.PullRequest.Closed.NotMergedNoReviews,
payload:pullRequestClosedNotMergedNoCommentsPayload
},
{
description: "Not merged, previously closed",
previousPrs: pullRequestListNotMerged,
pullRequestReviews: pullRequestReviewsListFew,
expectedCaseSlug: CaseSlugs.PullRequest.Closed.NotMergedPreviouslyClosed,
payload:pullRequestClosedNotMergedPayload
},
])('$description', ({ previousPrs,pullRequestReviews, expectedCaseSlug ,payload}) => {
test('Creates a comment after receiving the event', async () => {
strategyTestSetup.actionStrategyHandleSpy = vi.spyOn(PullRequestClosedStrategy.prototype as any, 'handle');

strategyTestSetup.pullRequestIndexResponseMock.mockImplementation(() => previousPrs);
strategyTestSetup.pullRequestReviewIndexResponseMock.mockImplementation(() => pullRequestReviews);

await strategyTestSetup.probot.receive({
id: '123',
name: 'pull_request',
payload: payload as any,
});


strategyTestSetup.performCommonAssertions(expectedCaseSlug);


});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"id": 1,
"user": {
"login": "reviewer1",
"id": 101,
"avatar_url": "https://avatars.githubusercontent.com/u/101?v=4",
"url": "https://api.github.com/users/reviewer1"
},
"body": "Great work!",
"state": "APPROVED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-1",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-01T00:00:00Z",
"commit_id": "commit-sha-1",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-1"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
},
{
"id": 2,
"user": {
"login": "reviewer2",
"id": 102,
"avatar_url": "https://avatars.githubusercontent.com/u/102?v=4",
"url": "https://api.github.com/users/reviewer2"
},
"body": "Needs some changes.",
"state": "CHANGES_REQUESTED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-2",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-02T00:00:00Z",
"commit_id": "commit-sha-2",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-2"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
[
{
"id": 1,
"user": {
"login": "reviewer1",
"id": 101,
"avatar_url": "https://avatars.githubusercontent.com/u/101?v=4",
"url": "https://api.github.com/users/reviewer1"
},
"body": "Great work!",
"state": "APPROVED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-1",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-01T00:00:00Z",
"commit_id": "commit-sha-1",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-1"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
},
{
"id": 2,
"user": {
"login": "reviewer2",
"id": 102,
"avatar_url": "https://avatars.githubusercontent.com/u/102?v=4",
"url": "https://api.github.com/users/reviewer2"
},
"body": "Needs some changes.",
"state": "CHANGES_REQUESTED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-2",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-02T00:00:00Z",
"commit_id": "commit-sha-2",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-2"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
},
{
"id": 3,
"user": {
"login": "reviewer3",
"id": 103,
"avatar_url": "https://avatars.githubusercontent.com/u/103?v=4",
"url": "https://api.github.com/users/reviewer3"
},
"body": "Looks good to me.",
"state": "APPROVED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-3",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-03T00:00:00Z",
"commit_id": "commit-sha-3",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-3"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
},
{
"id": 4,
"user": {
"login": "reviewer4",
"id": 104,
"avatar_url": "https://avatars.githubusercontent.com/u/104?v=4",
"url": "https://api.github.com/users/reviewer4"
},
"body": "I have some suggestions.",
"state": "COMMENTED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-4",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-04T00:00:00Z",
"commit_id": "commit-sha-4",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-4"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
},
{
"id": 5,
"user": {
"login": "reviewer5",
"id": 105,
"avatar_url": "https://avatars.githubusercontent.com/u/105?v=4",
"url": "https://api.github.com/users/reviewer5"
},
"body": "Looks good to me!",
"state": "APPROVED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-5",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-05T00:00:00Z",
"commit_id": "commit-sha-5",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-5"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
},
{
"id": 6,
"user": {
"login": "reviewer6",
"id": 106,
"avatar_url": "https://avatars.githubusercontent.com/u/106?v=4",
"url": "https://api.github.com/users/reviewer6"
},
"body": "Needs minor tweaks.",
"state": "COMMENTED",
"html_url": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-6",
"pull_request_url": "https://api.github.com/repos/test-owner/test-repo/pulls/1",
"submitted_at": "2023-01-06T00:00:00Z",
"commit_id": "commit-sha-6",
"author_association": "COLLABORATOR",
"_links": {
"html": {
"href": "https://github.com/test-owner/test-repo/pull/1#pullrequestreview-6"
},
"pull_request": {
"href": "https://api.github.com/repos/test-owner/test-repo/pulls/1"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"action": "closed",
"pull_request": {
"id": 1,
"number": 555444,
"state": "closed",
"title": "Test Pull Request",
"user": {
"login": "test-user"
},
"head": {
"ref": "some-side-branch-123"
},
"base": {
"ref": "master"
},
"body": "This is a test pull request",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z",
"merged_at": "2024-01-01T00:00:00Z",
"closed_at": "2024-01-01T00:00:00Z",
"merged": true,
"review_comments": 5
},
"repository": {
"name": "test-repo",
"owner": {
"login": "test-owner"
}
},
"sender": {
"login": "test-user",
"type": "User"
},
"installation": {
"id": 1
},
"isBot": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"action": "closed",
"pull_request": {
"id": 1,
"number": 555444,
"state": "closed",
"title": "Test Pull Request",
"user": {
"login": "test-user"
},
"head": {
"ref": "some-side-branch-123"
},
"base": {
"ref": "master"
},
"body": "This is a test pull request",
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z",
"merged_at": "2024-01-01T00:00:00Z",
"closed_at": "2024-01-01T00:00:00Z",
"merged": true,
"review_comments": 0
},
"repository": {
"name": "test-repo",
"owner": {
"login": "test-owner"
}
},
"sender": {
"login": "test-user",
"type": "User"
},
"installation": {
"id": 1
},
"isBot": false
}
Loading

0 comments on commit 2f4b913

Please sign in to comment.