Skip to content

Commit c1e6a50

Browse files
committed
CCM-10893 lint fix
1 parent c20519d commit c1e6a50

File tree

5 files changed

+21
-19
lines changed

5 files changed

+21
-19
lines changed

frontend/src/__tests__/components/molecules/HeaderWithAccount.test.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import 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';
83
import { mockDeep } from 'jest-mock-extended';
94
import NhsNotifyHeaderWithAccount from '@molecules/HeaderWithAccount/HeaderWithAccount';
105
import { type UseAuthenticator, useAuthenticator } from '@aws-amplify/ui-react';
@@ -13,12 +8,12 @@ jest.mock('@aws-amplify/ui-react');
138

149
const mockFetchAuthSession = jest.fn();
1510
jest.mock('aws-amplify/auth', () => ({
16-
fetchAuthSession: (...args: any[]) => mockFetchAuthSession(...args),
11+
fetchAuthSession: () => mockFetchAuthSession(),
1712
}));
1813

1914
const mockGetIdTokenClaims = jest.fn();
2015
jest.mock('@utils/token-utils', () => ({
21-
getIdTokenClaims: (...args: any[]) => mockGetIdTokenClaims(...args),
16+
getIdTokenClaims: (token: string) => mockGetIdTokenClaims(token),
2217
}));
2318

2419
const setAuthStatus = (

frontend/src/__tests__/utils/amplify-utils.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ jest.mock('aws-amplify/auth/server');
1313

1414
jest.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

frontend/src/components/molecules/Header/Header.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff 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'

frontend/src/components/molecules/HeaderWithAccount/HeaderWithAccount.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ interface NhsNotifyHeaderWithAccountProps {
2020
const headerContent = content.components.header;
2121

2222
const 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
}

frontend/src/utils/token-utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
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

44
export 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

1215
export const getIdTokenClaims = (

0 commit comments

Comments
 (0)