@@ -3,13 +3,11 @@ import { Deps } from '../../config/deps';
33import { LetterDto } from '../../contracts/letters' ;
44import { getLetterDataUrl , getLettersForSupplier , patchLetterStatus } from '../letter-operations' ;
55import pino from 'pino' ;
6- import { LambdaEnv } from '../../config/env' ;
76
87jest . mock ( '@aws-sdk/s3-request-presigner' , ( ) => ( {
98 getSignedUrl : jest . fn ( ) ,
109} ) ) ;
1110import { getSignedUrl } from '@aws-sdk/s3-request-presigner' ;
12- const mockedGetSignedUrl = getSignedUrl as jest . MockedFunction < typeof getSignedUrl > ;
1311
1412jest . mock ( '@aws-sdk/client-s3' , ( ) => {
1513 const originalModule = jest . requireActual ( '@aws-sdk/client-s3' ) ;
@@ -18,9 +16,13 @@ jest.mock('@aws-sdk/client-s3', () => {
1816 } ;
1917} ) ;
2018import { S3Client , GetObjectCommand } from '@aws-sdk/client-s3' ;
21- const MockedGetObjectCommand = GetObjectCommand as unknown as jest . Mock ;
2219
2320describe ( "getLetterIdsForSupplier" , ( ) => {
21+
22+ beforeEach ( ( ) => {
23+ jest . clearAllMocks ( ) ;
24+ } ) ;
25+
2426 it ( "returns letter IDs from the repository" , async ( ) => {
2527 const mockRepo = {
2628 getLettersBySupplier : jest . fn ( ) . mockResolvedValue ( [
@@ -50,6 +52,10 @@ describe("getLetterIdsForSupplier", () => {
5052
5153describe ( 'patchLetterStatus function' , ( ) => {
5254
55+ beforeEach ( ( ) => {
56+ jest . clearAllMocks ( ) ;
57+ } ) ;
58+
5359 const updatedLetterDto : LetterDto = {
5460 id : 'letter1' ,
5561 supplierId : 'supplier1' ,
@@ -106,14 +112,27 @@ describe('patchLetterStatus function', () => {
106112
107113describe ( 'getLetterDataUrl function' , ( ) => {
108114
115+ beforeEach ( ( ) => {
116+ jest . clearAllMocks ( ) ;
117+ } ) ;
118+
119+ const mockedGetSignedUrl = getSignedUrl as jest . MockedFunction < typeof getSignedUrl > ;
120+ const MockedGetObjectCommand = GetObjectCommand as unknown as jest . Mock ;
121+
109122 const updatedLetter = makeLetter ( "letter1" , "REJECTED" ) ;
110123
111124 const s3Client = { send : jest . fn ( ) } as unknown as S3Client ;
112125 const letterRepo = {
113126 getLetterById : jest . fn ( ) . mockResolvedValue ( updatedLetter )
114127 } as unknown as LetterRepository ;
115128 const logger = jest . fn ( ) as unknown as pino . Logger ; ;
116- const env = jest . fn ( ) as unknown as LambdaEnv ;
129+ const env = {
130+ LETTERS_TABLE_NAME : 'LettersTable' ,
131+ LETTER_TTL_HOURS : '24' ,
132+ SUPPLIER_ID_HEADER : 'nhsd-supplier-id' ,
133+ APIM_CORRELATION_HEADER : 'nhsd-correlation-id' ,
134+ DOWNLOAD_URL_TTL_SECONDS : '3600'
135+ } ;
117136 const deps : Deps = { s3Client, letterRepo, logger, env } ;
118137
119138 it ( 'should return pre signed url successfully' , async ( ) => {
@@ -122,12 +141,11 @@ describe('getLetterDataUrl function', () => {
122141
123142 const result = await getLetterDataUrl ( 'supplier1' , 'letter1' , deps ) ;
124143
125- expect ( mockedGetSignedUrl ) . toHaveBeenCalled ( ) ;
126- expect ( MockedGetObjectCommand ) . toHaveBeenCalledWith ( {
144+ const expectedCommandInput = {
127145 Bucket : 'letterDataBucket' ,
128146 Key : 'letter1.pdf'
129- } ) ;
130-
147+ } ;
148+ expect ( mockedGetSignedUrl ) . toHaveBeenCalledWith ( s3Client , { input : expectedCommandInput } , { expiresIn : 3600 } ) ;
131149 expect ( result ) . toEqual ( 'http://somePreSignedUrl.com' ) ;
132150 } ) ;
133151
0 commit comments