@@ -128,51 +128,57 @@ describe('AuthGuard', () => {
128128 expect ( getByText ( 'children' ) ) . toBeInTheDocument ( )
129129 } )
130130
131- it ( 'Should able to access when user try to access on delegations routes and he is a PA' , ( ) => {
132- const props : AuthGuardTestProps = {
133- ...defaultProps ,
134- isSupport : false ,
131+ it . each ( [ 'DELEGATIONS' , 'DELEGATION_DETAILS' , 'CREATE_DELEGATION' ] as const ) (
132+ 'Should able to access when user try to access on %s route and he is a PA' ,
133+ ( routeKey ) => {
134+ const props : AuthGuardTestProps = {
135+ ...defaultProps ,
136+ isSupport : false ,
137+ }
138+
139+ useAuthGuardSpy . mockReturnValue ( {
140+ isPublic : false ,
141+ authLevels : [ ] ,
142+ isUserAuthorized : ( ) => true ,
143+ } )
144+ mockUseCurrentRoute ( {
145+ routeKey,
146+ } )
147+ mockUseGetActiveUserParty ( {
148+ data : {
149+ externalId : { origin : 'IPA' } ,
150+ } ,
151+ } )
152+
153+ const { getByText } = renderAuthGuard ( props )
154+ expect ( getByText ( 'children' ) ) . toBeInTheDocument ( )
135155 }
156+ )
136157
137- useAuthGuardSpy . mockReturnValue ( {
138- isPublic : false ,
139- authLevels : [ ] ,
140- isUserAuthorized : ( ) => true ,
141- } )
142- mockUseCurrentRoute ( {
143- routeKey : 'DELEGATIONS' || 'DELEGATION_DETAILS' || 'CREATE_DELEGATION' ,
144- } )
145- mockUseGetActiveUserParty ( {
146- data : {
147- externalId : { origin : 'IPA' } ,
148- } ,
149- } )
150-
151- const { getByText } = renderAuthGuard ( props )
152- expect ( getByText ( 'children' ) ) . toBeInTheDocument ( )
153- } )
154-
155- it ( 'Should render Error component when user try to access on delegations routes and he is not a PA' , ( ) => {
156- const props : AuthGuardTestProps = {
157- ...defaultProps ,
158- isSupport : false ,
158+ it . each ( [ 'DELEGATIONS' , 'DELEGATION_DETAILS' , 'CREATE_DELEGATION' ] as const ) (
159+ 'Should render Error component when user try to access on delegations routes and he is not a PA' ,
160+ ( routeKey ) => {
161+ const props : AuthGuardTestProps = {
162+ ...defaultProps ,
163+ isSupport : false ,
164+ }
165+
166+ useAuthGuardSpy . mockReturnValue ( {
167+ isPublic : false ,
168+ authLevels : [ ] ,
169+ isUserAuthorized : ( ) => false ,
170+ } )
171+ mockUseCurrentRoute ( {
172+ routeKey,
173+ } )
174+ mockUseGetActiveUserParty ( {
175+ data : {
176+ externalId : { origin : '' } ,
177+ } ,
178+ } )
179+
180+ const { getByText } = renderAuthGuard ( props )
181+ expect ( getByText ( 'error' ) ) . toBeInTheDocument ( )
159182 }
160-
161- useAuthGuardSpy . mockReturnValue ( {
162- isPublic : false ,
163- authLevels : [ ] ,
164- isUserAuthorized : ( ) => false ,
165- } )
166- mockUseCurrentRoute ( {
167- routeKey : 'DELEGATIONS' || 'DELEGATION_DETAILS' || 'CREATE_DELEGATION' ,
168- } )
169- mockUseGetActiveUserParty ( {
170- data : {
171- externalId : { origin : '' } ,
172- } ,
173- } )
174-
175- const { getByText } = renderAuthGuard ( props )
176- expect ( getByText ( 'error' ) ) . toBeInTheDocument ( )
177- } )
183+ )
178184} )
0 commit comments