Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: publish button delay #752

Merged
merged 3 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/integration/Reviews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1265,13 +1265,41 @@ describe("Review Requests Integration Tests", () => {
})
})

it("should return 404 if review request is not approved", async () => {
// Arrange
const app = generateRouterForUserWithSite(
subrouter,
MOCK_USER_SESSION_DATA_ONE,
MOCK_REPO_NAME_TWO
)

// Act
const actual = await request(app).post(
`/${MOCK_REPO_NAME_TWO}/${MOCK_GITHUB_PULL_REQUEST_NUMBER}/merge`
)

// Assert
expect(actual.statusCode).toEqual(404)
})

it("should merge the pull request successfully", async () => {
// Arrange
const app = generateRouterForUserWithSite(
subrouter,
MOCK_USER_SESSION_DATA_ONE,
MOCK_REPO_NAME_ONE
)
const activeReviewRequest = await ReviewRequest.findOne({
where: {
requestorId: MOCK_USER_ID_ONE,
siteId: MOCK_SITE_ID_ONE,
},
})
if (!activeReviewRequest) fail("Should not reach here")
await activeReviewRequest.set({
reviewStatus: ReviewRequestStatus.Approved,
})
await activeReviewRequest.save()
mockGenericAxios.post.mockResolvedValueOnce(null)
mockGenericAxios.put.mockResolvedValueOnce(null)

Expand Down
6 changes: 3 additions & 3 deletions src/routes/v2/authenticated/__tests__/review.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,9 +738,9 @@ describe("Review Requests Router", () => {
// Arrange

mockCollaboratorsService.getRole.mockResolvedValueOnce("role")
mockReviewRequestService.getReviewRequest.mockResolvedValueOnce(
"review request"
)
mockReviewRequestService.getReviewRequest.mockResolvedValueOnce({
reviewStatus: ReviewRequestStatus.Approved,
})
mockReviewRequestService.mergeReviewRequest.mockResolvedValueOnce(
undefined
)
Expand Down
10 changes: 8 additions & 2 deletions src/routes/v2/authenticated/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,19 @@ export class ReviewsRouter {
return res.status(404).json({ message: possibleReviewRequest.message })
}

// Step 4: Merge review request
// Step 4: Check if review request is valid
if (possibleReviewRequest.reviewStatus !== ReviewRequestStatus.Approved)
return res
.status(404)
.json({ message: "Approved review request not found!" })

// Step 5: Merge review request
// NOTE: We are not checking for existence of PR
// as the underlying Github API returns 404 if
// the requested review could not be found.
await this.reviewRequestService.mergeReviewRequest(possibleReviewRequest)

// Step 5: Clean up the review request view records
// Step 6: Clean up the review request view records
// The error is discarded as we are guaranteed to have a review request
await this.reviewRequestService.deleteAllReviewRequestViews(
site.value,
Expand Down