Skip to content

Commit f551e18

Browse files
Added test for AuthGuard
1 parent d366a30 commit f551e18

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/router/components/RoutesWrapper/__tests__/AuthGuard.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,52 @@ describe('AuthGuard', () => {
127127
const { getByText } = renderAuthGuard()
128128
expect(getByText('children')).toBeInTheDocument()
129129
})
130+
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,
135+
}
136+
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,
159+
}
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+
})
130178
})

0 commit comments

Comments
 (0)