diff --git a/src/packages/auth/components/auth.spec.js b/src/packages/auth/components/auth.spec.tsx similarity index 73% rename from src/packages/auth/components/auth.spec.js rename to src/packages/auth/components/auth.spec.tsx index e0477cc91..01faf0e28 100644 --- a/src/packages/auth/components/auth.spec.js +++ b/src/packages/auth/components/auth.spec.tsx @@ -1,13 +1,13 @@ import { AuthDumb, mapStateToProps } from './auth'; import { render } from '@testing-library/react'; import { LOADING } from '../../sdk/constants'; +import { ReduxModel } from '../../redux/model'; describe('AuthDumb', () => { it('should return the fallback if the user is not authorized', () => { const { container } = render( { it('should return the children if the user is authorized', () => { const { container } = render( { it('should return the children if the user is authorized via a complementary check', () => { const { container } = render( true]]} loadUserStamp={jest.fn()} + userStamp="stamp" > Children @@ -50,8 +49,7 @@ describe('AuthDumb', () => { it('should return the fallback if the user is not authorized via a complementary check', () => { const { container } = render( false]]} loadUserStamp={jest.fn()} @@ -61,6 +59,20 @@ describe('AuthDumb', () => { ); expect(container.innerHTML).toEqual('fallback'); }); + + it('should return the fallback if the user does not have a stamp via a complementary check', () => { + const { container } = render( + true]]} + loadUserStamp={jest.fn()} + > + Children + + ); + expect(container.innerHTML).toEqual('fallback'); + }); }); describe('mapStateToProps', () => { @@ -68,8 +80,10 @@ describe('mapStateToProps', () => { const state = { app: { auth: { + type: 'type', user: { - roles: 'roles', + roles: ['roles'], + stamp: 'stamp', }, }, }, @@ -79,9 +93,9 @@ describe('mapStateToProps', () => { stamp: 'stamp', }, }, - }; + } as unknown as ReduxModel; expect(mapStateToProps(state)).toEqual({ - userRoles: 'roles', + userRoles: ['roles'], userStamp: 'stamp', isLoading: true, }); diff --git a/src/packages/auth/components/auth.ts b/src/packages/auth/components/auth.ts index 7f7a835a7..99c045ec7 100644 --- a/src/packages/auth/components/auth.ts +++ b/src/packages/auth/components/auth.ts @@ -48,8 +48,11 @@ export function AuthDumb({ }, [userStamp, isLoading, loadUserStamp]); const isAuthorized = !!roles.find((role) => { if (Array.isArray(role)) { - const [r, check] = role; - return userRoles?.includes(r) && check(userStamp!); + if (!!userStamp) { + const [r, check] = role; + return userRoles?.includes(r) && check(userStamp); + } + return false; } return userRoles?.includes(role); });