File tree Expand file tree Collapse file tree 5 files changed +21
-19
lines changed
Expand file tree Collapse file tree 5 files changed +21
-19
lines changed Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import {
3- render ,
4- screen ,
5- waitFor ,
6- within ,
7- } from '@testing-library/react' ;
2+ import { render , screen , waitFor , within } from '@testing-library/react' ;
83import { mockDeep } from 'jest-mock-extended' ;
94import NhsNotifyHeaderWithAccount from '@molecules/HeaderWithAccount/HeaderWithAccount' ;
105import { type UseAuthenticator , useAuthenticator } from '@aws-amplify/ui-react' ;
@@ -13,12 +8,12 @@ jest.mock('@aws-amplify/ui-react');
138
149const mockFetchAuthSession = jest . fn ( ) ;
1510jest . mock ( 'aws-amplify/auth' , ( ) => ( {
16- fetchAuthSession : ( ... args : any [ ] ) => mockFetchAuthSession ( ... args ) ,
11+ fetchAuthSession : ( ) => mockFetchAuthSession ( ) ,
1712} ) ) ;
1813
1914const mockGetIdTokenClaims = jest . fn ( ) ;
2015jest . mock ( '@utils/token-utils' , ( ) => ( {
21- getIdTokenClaims : ( ... args : any [ ] ) => mockGetIdTokenClaims ( ... args ) ,
16+ getIdTokenClaims : ( token : string ) => mockGetIdTokenClaims ( token ) ,
2217} ) ) ;
2318
2419const setAuthStatus = (
Original file line number Diff line number Diff line change @@ -13,7 +13,11 @@ jest.mock('aws-amplify/auth/server');
1313
1414jest . mock ( '@aws-amplify/adapter-nextjs' , ( ) => ( {
1515 createServerRunner : ( ) => ( {
16- runWithAmplifyServerContext : async ( { operation } : any ) => operation ( { } ) ,
16+ runWithAmplifyServerContext : async ( {
17+ operation,
18+ } : {
19+ operation : ( ctx : { token : string } ) => unknown | Promise < unknown > ;
20+ } ) => operation ( { token : 'mock-token' } ) ,
1721 } ) ,
1822} ) ) ;
1923
Original file line number Diff line number Diff line change @@ -33,9 +33,7 @@ export function NHSNotifyHeader({ dataTestId }: HeaderType) {
3333 width = '100'
3434 data-testid = 'page-header-logo'
3535 >
36- < title >
37- { content . components . header . logoLink . logoTitle }
38- </ title >
36+ < title > { content . components . header . logoLink . logoTitle } </ title >
3937 < path
4038 className = 'nhsuk-logo__background'
4139 fill = '#005eb8'
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ interface NhsNotifyHeaderWithAccountProps {
2020const headerContent = content . components . header ;
2121
2222const NhsNotifyHeaderWithAccount = ( {
23- features
23+ features,
2424} : NhsNotifyHeaderWithAccountProps ) => {
2525 // TODO: CCM-11148 Use real routing feature flag
2626 const routingEnabled = features ?. routing ;
@@ -39,10 +39,12 @@ const NhsNotifyHeaderWithAccount = ({
3939 try {
4040 const session = await fetchAuthSession ( ) ;
4141 const idToken = session . tokens ?. idToken ?. toString ( ) ;
42- if ( ! idToken ) {
42+ if ( idToken ) {
43+ setState ( getIdTokenClaims ( idToken ) ) ;
44+ } else {
4345 setState ( { } ) ;
4446 return ;
45- } else setState ( getIdTokenClaims ( idToken ) ) ;
47+ }
4648 } catch {
4749 setState ( { } ) ;
4850 }
Original file line number Diff line number Diff line change 1- import { jwtDecode } from " jwt-decode" ;
2- import { JWT } from " aws-amplify/auth" ;
1+ import { jwtDecode } from ' jwt-decode' ;
2+ import { JWT } from ' aws-amplify/auth' ;
33
44export const decodeJwt = ( token : string ) : JWT [ 'payload' ] =>
55 jwtDecode < JWT [ 'payload' ] > ( token ) ;
66
7- export const getClaim = ( claims : JWT [ 'payload' ] , key : string ) : string | undefined => {
7+ export const getClaim = (
8+ claims : JWT [ 'payload' ] ,
9+ key : string
10+ ) : string | undefined => {
811 const value = claims [ key ] ;
9- return value != null ? String ( value ) : undefined ;
12+ return value == null ? undefined : String ( value ) ;
1013} ;
1114
1215export const getIdTokenClaims = (
You can’t perform that action at this time.
0 commit comments