11import { getToken } from "@src/utils/auth/callbacks/get-token" ;
22import { generateClientAssertion } from "@src/utils/auth/generate-refresh-client-assertion" ;
3- import { Logger } from "pino" ;
43import { Account , Profile } from "next-auth" ;
54import { JWT } from "next-auth/jwt" ;
65import { AppConfig } from "@src/utils/config" ;
@@ -19,11 +18,6 @@ describe("getToken", () => {
1918 NHS_LOGIN_PRIVATE_KEY : "mock-private-key" ,
2019 } as AppConfig ;
2120
22- const mockLog = {
23- info : jest . fn ( ) ,
24- error : jest . fn ( ) ,
25- } as unknown as Logger ;
26-
2721 const nowInSeconds = Math . floor ( Date . now ( ) / 1000 ) ;
2822
2923 beforeEach ( ( ) => {
@@ -42,12 +36,8 @@ describe("getToken", () => {
4236 undefined ,
4337 mockConfig ,
4438 300 ,
45- mockLog ,
4639 ) ;
4740 expect ( result ) . toBeNull ( ) ;
48- expect ( mockLog . error ) . toHaveBeenCalledWith (
49- "No token available in jwt callback." ,
50- ) ;
5141 } ) ;
5242
5343 it ( "should return updated token on initial login with account and profile" , async ( ) => {
@@ -72,7 +62,6 @@ describe("getToken", () => {
7262 profile ,
7363 mockConfig ,
7464 maxAgeInSeconds ,
75- mockLog ,
7665 ) ;
7766
7867 expect ( result ) . toMatchObject ( {
@@ -85,8 +74,6 @@ describe("getToken", () => {
8574 } ,
8675 fixedExpiry : nowInSeconds + maxAgeInSeconds ,
8776 } ) ;
88-
89- expect ( mockLog . info ) . not . toHaveBeenCalled ( ) ;
9077 } ) ;
9178
9279 it ( "should return token with empty values on initial login if account and profile are undefined" , async ( ) => {
@@ -104,7 +91,6 @@ describe("getToken", () => {
10491 profile ,
10592 mockConfig ,
10693 maxAgeInSeconds ,
107- mockLog ,
10894 ) ;
10995
11096 expect ( result ) . toMatchObject ( {
@@ -117,8 +103,6 @@ describe("getToken", () => {
117103 } ,
118104 fixedExpiry : nowInSeconds + maxAgeInSeconds ,
119105 } ) ;
120-
121- expect ( mockLog . info ) . not . toHaveBeenCalled ( ) ;
122106 } ) ;
123107
124108 it ( "should return null if fixedExpiry reached" , async ( ) => {
@@ -128,19 +112,9 @@ describe("getToken", () => {
128112 expires_at : nowInSeconds + 1000 ,
129113 } as JWT ;
130114
131- const result = await getToken (
132- token ,
133- null ,
134- undefined ,
135- mockConfig ,
136- 300 ,
137- mockLog ,
138- ) ;
115+ const result = await getToken ( token , null , undefined , mockConfig , 300 ) ;
139116
140117 expect ( result ) . toBeNull ( ) ;
141- expect ( mockLog . info ) . toHaveBeenCalledWith (
142- "Session has reached the max age" ,
143- ) ;
144118 } ) ;
145119
146120 it ( "should refresh access token if expired, and refresh_token exists; new expires_in and refresh_token are received" , async ( ) => {
@@ -172,16 +146,8 @@ describe("getToken", () => {
172146 } ) ,
173147 } ) ;
174148
175- const result = await getToken (
176- token ,
177- null ,
178- undefined ,
179- mockConfig ,
180- 300 ,
181- mockLog ,
182- ) ;
149+ const result = await getToken ( token , null , undefined , mockConfig , 300 ) ;
183150
184- expect ( mockLog . info ) . toHaveBeenCalledWith ( "Attempting to refresh token" ) ;
185151 expect ( mockGenerateClientAssertion ) . toHaveBeenCalledWith ( mockConfig ) ;
186152
187153 expect ( global . fetch ) . toHaveBeenCalledWith (
@@ -227,16 +193,8 @@ describe("getToken", () => {
227193 } ) ,
228194 } ) ;
229195
230- const result = await getToken (
231- token ,
232- null ,
233- undefined ,
234- mockConfig ,
235- 300 ,
236- mockLog ,
237- ) ;
196+ const result = await getToken ( token , null , undefined , mockConfig , 300 ) ;
238197
239- expect ( mockLog . info ) . toHaveBeenCalledWith ( "Attempting to refresh token" ) ;
240198 expect ( mockGenerateClientAssertion ) . toHaveBeenCalledWith ( mockConfig ) ;
241199
242200 expect ( global . fetch ) . toHaveBeenCalledWith (
@@ -261,18 +219,9 @@ describe("getToken", () => {
261219 refresh_token : "" ,
262220 } as JWT ;
263221
264- const result = await getToken (
265- token ,
266- null ,
267- undefined ,
268- mockConfig ,
269- 300 ,
270- mockLog ,
271- ) ;
222+ const result = await getToken ( token , null , undefined , mockConfig , 300 ) ;
272223
273224 expect ( result ) . toBeNull ( ) ;
274- expect ( mockLog . info ) . toHaveBeenCalledWith ( "Attempting to refresh token" ) ;
275- expect ( mockLog . error ) . toHaveBeenCalledWith ( "Refresh token missing" ) ;
276225 } ) ;
277226
278227 it ( "should return null and logs error if fetch response not ok" , async ( ) => {
@@ -288,20 +237,9 @@ describe("getToken", () => {
288237 json : jest . fn ( ) . mockResolvedValue ( { error : "Error" } ) ,
289238 } ) ;
290239
291- const result = await getToken (
292- token ,
293- null ,
294- undefined ,
295- mockConfig ,
296- 300 ,
297- mockLog ,
298- ) ;
240+ const result = await getToken ( token , null , undefined , mockConfig , 300 ) ;
299241
300242 expect ( result ) . toBeNull ( ) ;
301- expect ( mockLog . error ) . toHaveBeenCalledWith (
302- { error : "Error" } ,
303- "Error in jwt callback" ,
304- ) ;
305243 } ) ;
306244
307245 it ( "should return the token if no refresh needed" , async ( ) => {
@@ -315,16 +253,8 @@ describe("getToken", () => {
315253 } ,
316254 } as JWT ;
317255
318- const result = await getToken (
319- token ,
320- null ,
321- undefined ,
322- mockConfig ,
323- 300 ,
324- mockLog ,
325- ) ;
256+ const result = await getToken ( token , null , undefined , mockConfig , 300 ) ;
326257
327258 expect ( result ) . toEqual ( token ) ;
328- expect ( mockLog . info ) . not . toHaveBeenCalled ( ) ;
329259 } ) ;
330260} ) ;
0 commit comments