Skip to content

Commit 8440d8d

Browse files
committed
test(review): add test toe ensure users cannot specify themselves for review request
1 parent 227d54e commit 8440d8d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/routes/v2/authenticated/__tests__/review.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { mockUserId } from "@fixtures/identity"
1313
import { MOCK_USER_EMAIL_ONE, MOCK_USER_EMAIL_TWO } from "@fixtures/users"
1414
import { CollaboratorRoles, ReviewRequestStatus } from "@root/constants"
1515
import MissingSiteError from "@root/errors/MissingSiteError"
16+
import { MOCK_USER_SESSION_DATA_ONE } from "@root/fixtures/sessionData"
1617
import GitHubService from "@root/services/db/GitHubService"
1718
import CollaboratorsService from "@services/identity/CollaboratorsService"
1819
import NotificationsService from "@services/identity/NotificationsService"
@@ -335,6 +336,35 @@ describe("Review Requests Router", () => {
335336
).not.toHaveBeenCalled()
336337
expect(mockNotificationsService.create).not.toHaveBeenCalled()
337338
})
339+
340+
it("should return 400 if the user requests themselves to review", async () => {
341+
// Arrange
342+
mockCollaboratorsService.getRole.mockResolvedValueOnce("role")
343+
mockIdentityUsersService.findByEmail.mockResolvedValueOnce("user")
344+
mockCollaboratorsService.list.mockResolvedValueOnce([])
345+
346+
// Act
347+
const response = await request(app)
348+
.post("/mockSite/review/request")
349+
.send({
350+
// NOTE: this is injected via `generateRouterForDefaultUserWithSite`
351+
// and from there, `attachDefaultUserSessionDataWithSite`
352+
reviewers: [MOCK_USER_SESSION_DATA_ONE.email],
353+
title: "mockTitle",
354+
description: "mockDescription",
355+
})
356+
357+
// Assert
358+
expect(response.status).toEqual(400)
359+
expect(mockSitesService.getBySiteName).toHaveBeenCalledTimes(1)
360+
expect(mockCollaboratorsService.getRole).toHaveBeenCalledTimes(1)
361+
expect(mockIdentityUsersService.findByEmail).toHaveBeenCalledTimes(1)
362+
expect(mockCollaboratorsService.list).not.toHaveBeenCalled()
363+
expect(
364+
mockReviewRequestService.createReviewRequest
365+
).not.toHaveBeenCalled()
366+
expect(mockNotificationsService.create).not.toHaveBeenCalled()
367+
})
338368
})
339369

340370
describe("listReviews", () => {

0 commit comments

Comments
 (0)