@@ -9,7 +9,11 @@ import {
99 createUserParticipantRequest ,
1010} from '../../../testHelpers/apiTestHelpers' ;
1111import { UserRoleId } from '../../entities/UserRole' ;
12- import { isAdminOrUid2SupportCheck , isUid2SupportCheck } from '../userRoleMiddleware' ;
12+ import {
13+ isAdminOrUid2SupportCheck ,
14+ isSuperUserCheck ,
15+ isUid2SupportCheck ,
16+ } from '../userRoleMiddleware' ;
1317
1418describe ( 'User Role Middleware Tests' , ( ) => {
1519 let knex : Knex ;
@@ -47,6 +51,32 @@ describe('User Role Middleware Tests', () => {
4751 expect ( next ) . not . toHaveBeenCalled ( ) ;
4852 } ) ;
4953 } ) ;
54+ describe ( 'SuperUser check' , ( ) => {
55+ it ( 'should call next if requesting user has the SuperUser role' , async ( ) => {
56+ const participant = await createParticipant ( knex , { } ) ;
57+ const user = await createUser ( {
58+ participantToRoles : [ { participantId : participant . id , userRoleId : UserRoleId . SuperUser } ] ,
59+ } ) ;
60+ const userParticipantRequest = createUserParticipantRequest ( user . email , participant , user . id ) ;
61+
62+ await isSuperUserCheck ( userParticipantRequest , res , next ) ;
63+
64+ expect ( res . status ) . not . toHaveBeenCalled ( ) ;
65+ expect ( next ) . toHaveBeenCalled ( ) ;
66+ } ) ;
67+ it ( 'should return 403 if requesting user does not have SuperUser role' , async ( ) => {
68+ const participant = await createParticipant ( knex , { } ) ;
69+ const user = await createUser ( {
70+ participantToRoles : [ { participantId : participant . id , userRoleId : UserRoleId . UID2Support } ] ,
71+ } ) ;
72+ const userParticipantRequest = createUserParticipantRequest ( user . email , participant , user . id ) ;
73+
74+ await isSuperUserCheck ( userParticipantRequest , res , next ) ;
75+
76+ expect ( res . status ) . toHaveBeenCalledWith ( 403 ) ;
77+ expect ( next ) . not . toHaveBeenCalled ( ) ;
78+ } ) ;
79+ } ) ;
5080 describe ( 'Admin Role or UID2 Support check' , ( ) => {
5181 it . each ( [
5282 { role : UserRoleId . Admin , description : 'Admin Role for the participant' } ,
0 commit comments