@@ -16,20 +16,23 @@ import {
1616 setTemplateToSubmitted ,
1717 requestTemplateProof ,
1818} from '@utils/form-actions' ;
19- import { getAccessTokenServer } from '@utils/amplify-utils' ;
19+ import { getSessionServer } from '@utils/amplify-utils' ;
2020import { TemplateDto } from 'nhs-notify-backend-client' ;
2121import { templateClient } from 'nhs-notify-backend-client/src/template-api-client' ;
2222
2323const mockedTemplateClient = jest . mocked ( templateClient ) ;
24- const authIdTokenServerMock = jest . mocked ( getAccessTokenServer ) ;
24+ const authIdTokenServerMock = jest . mocked ( getSessionServer ) ;
2525
2626jest . mock ( '@utils/amplify-utils' ) ;
2727jest . mock ( 'nhs-notify-backend-client/src/template-api-client' ) ;
2828
2929describe ( 'form-actions' , ( ) => {
3030 beforeEach ( ( ) => {
3131 jest . resetAllMocks ( ) ;
32- authIdTokenServerMock . mockResolvedValueOnce ( 'token' ) ;
32+ authIdTokenServerMock . mockResolvedValueOnce ( {
33+ accessToken : 'token' ,
34+ sub : 'sub' ,
35+ } ) ;
3336 } ) ;
3437
3538 test ( 'createTemplate' , async ( ) => {
@@ -89,7 +92,10 @@ describe('form-actions', () => {
8992
9093 test ( 'createTemplate - should throw error when no token' , async ( ) => {
9194 authIdTokenServerMock . mockReset ( ) ;
92- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
95+ authIdTokenServerMock . mockResolvedValueOnce ( {
96+ accessToken : undefined ,
97+ sub : undefined ,
98+ } ) ;
9399
94100 const createTemplateInput : CreateUpdateNHSAppTemplate = {
95101 templateType : 'NHS_APP' ,
@@ -249,7 +255,10 @@ describe('form-actions', () => {
249255
250256 test ( 'createLetterTemplate - should throw error when no token' , async ( ) => {
251257 authIdTokenServerMock . mockReset ( ) ;
252- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
258+ authIdTokenServerMock . mockResolvedValueOnce ( {
259+ accessToken : undefined ,
260+ sub : undefined ,
261+ } ) ;
253262
254263 const createLetterTemplateInput : CreateLetterTemplate = {
255264 templateType : 'LETTER' ,
@@ -337,7 +346,10 @@ describe('form-actions', () => {
337346
338347 test ( 'saveTemplate - should throw error when no token' , async ( ) => {
339348 authIdTokenServerMock . mockReset ( ) ;
340- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
349+ authIdTokenServerMock . mockResolvedValueOnce ( {
350+ accessToken : undefined ,
351+ sub : undefined ,
352+ } ) ;
341353
342354 const updateTemplateInput : NHSAppTemplate = {
343355 id : 'id' ,
@@ -400,7 +412,10 @@ describe('form-actions', () => {
400412
401413 test ( 'getTemplate - should throw error when no token' , async ( ) => {
402414 authIdTokenServerMock . mockReset ( ) ;
403- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
415+ authIdTokenServerMock . mockResolvedValueOnce ( {
416+ accessToken : undefined ,
417+ sub : undefined ,
418+ } ) ;
404419
405420 await expect ( getTemplate ( 'id' ) ) . rejects . toThrow (
406421 'Failed to get access token'
@@ -445,7 +460,10 @@ describe('form-actions', () => {
445460
446461 test ( 'getTemplates - should throw error when no token' , async ( ) => {
447462 authIdTokenServerMock . mockReset ( ) ;
448- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
463+ authIdTokenServerMock . mockResolvedValueOnce ( {
464+ accessToken : undefined ,
465+ sub : undefined ,
466+ } ) ;
449467
450468 await expect ( getTemplates ( ) ) . rejects . toThrow ( 'Failed to get access token' ) ;
451469 } ) ;
@@ -533,7 +551,10 @@ describe('form-actions', () => {
533551
534552 test ( 'submitTemplate - should throw error when no token' , async ( ) => {
535553 authIdTokenServerMock . mockReset ( ) ;
536- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
554+ authIdTokenServerMock . mockResolvedValueOnce ( {
555+ accessToken : undefined ,
556+ sub : undefined ,
557+ } ) ;
537558
538559 await expect ( setTemplateToSubmitted ( 'id' ) ) . rejects . toThrow (
539560 'Failed to get access token'
@@ -577,7 +598,10 @@ describe('form-actions', () => {
577598
578599 test ( 'deleteTemplate - should throw error when no token' , async ( ) => {
579600 authIdTokenServerMock . mockReset ( ) ;
580- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
601+ authIdTokenServerMock . mockResolvedValueOnce ( {
602+ accessToken : undefined ,
603+ sub : undefined ,
604+ } ) ;
581605
582606 await expect ( setTemplateToDeleted ( 'id' ) ) . rejects . toThrow (
583607 'Failed to get access token'
@@ -639,7 +663,10 @@ describe('form-actions', () => {
639663
640664 test ( 'requestTemplateProof - should throw error when no token' , async ( ) => {
641665 authIdTokenServerMock . mockReset ( ) ;
642- authIdTokenServerMock . mockResolvedValueOnce ( undefined ) ;
666+ authIdTokenServerMock . mockResolvedValueOnce ( {
667+ accessToken : undefined ,
668+ sub : undefined ,
669+ } ) ;
643670
644671 await expect ( requestTemplateProof ( 'id' ) ) . rejects . toThrow (
645672 'Failed to get access token'
0 commit comments