@@ -13,6 +13,7 @@ import { mockUserId } from "@fixtures/identity"
1313import { MOCK_USER_EMAIL_ONE , MOCK_USER_EMAIL_TWO } from "@fixtures/users"
1414import { CollaboratorRoles , ReviewRequestStatus } from "@root/constants"
1515import MissingSiteError from "@root/errors/MissingSiteError"
16+ import { MOCK_USER_SESSION_DATA_ONE } from "@root/fixtures/sessionData"
1617import GitHubService from "@root/services/db/GitHubService"
1718import CollaboratorsService from "@services/identity/CollaboratorsService"
1819import NotificationsService from "@services/identity/NotificationsService"
@@ -335,6 +336,34 @@ 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+
345+ // Act
346+ const response = await request ( app )
347+ . post ( "/mockSite/review/request" )
348+ . send ( {
349+ // NOTE: this is injected via `generateRouterForDefaultUserWithSite`
350+ // and from there, `attachDefaultUserSessionDataWithSite`
351+ reviewers : [ MOCK_USER_SESSION_DATA_ONE . email ] ,
352+ title : "mockTitle" ,
353+ description : "mockDescription" ,
354+ } )
355+
356+ // Assert
357+ expect ( response . status ) . toEqual ( 400 )
358+ expect ( mockSitesService . getBySiteName ) . toHaveBeenCalledTimes ( 1 )
359+ expect ( mockCollaboratorsService . getRole ) . toHaveBeenCalledTimes ( 1 )
360+ expect ( mockIdentityUsersService . findByEmail ) . toHaveBeenCalledTimes ( 1 )
361+ expect ( mockCollaboratorsService . list ) . not . toHaveBeenCalled ( )
362+ expect (
363+ mockReviewRequestService . createReviewRequest
364+ ) . not . toHaveBeenCalled ( )
365+ expect ( mockNotificationsService . create ) . not . toHaveBeenCalled ( )
366+ } )
338367 } )
339368
340369 describe ( "listReviews" , ( ) => {
0 commit comments