@@ -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,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