@@ -112,6 +112,51 @@ describe('API Lambda handler', () => {
112112 } ) ;
113113 } ) ;
114114
115+ it ( 'returns 200 OK with a valid limit' , async ( ) => {
116+
117+ const mockedGetLetters = letterService . getLettersForSupplier as jest . Mock ;
118+ mockedGetLetters . mockResolvedValue ( [
119+ {
120+ id : 'l1' ,
121+ specificationId : 's1' ,
122+ groupId : 'g1' ,
123+ status : 'PENDING'
124+ } ,
125+ ] ) ;
126+
127+ const event = makeApiGwEvent ( {
128+ path : '/letters' ,
129+ queryStringParameters : { limit : '50' } ,
130+ headers : {
131+ 'nhsd-supplier-id' : 'supplier1' ,
132+ 'nhsd-correlation-id' : 'correlationId' ,
133+ 'x-request-id' : 'requestId'
134+ }
135+ } ) ;
136+ const context = mockDeep < Context > ( ) ;
137+ const callback = jest . fn ( ) ;
138+
139+ const getLettersHandler = createGetLettersHandler ( mockedDeps ) ;
140+ const result = await getLettersHandler ( event , context , callback ) ;
141+
142+ expect ( mockedGetLetters ) . toHaveBeenCalledWith ( 'supplier1' , 'PENDING' , 50 , mockedDeps . letterRepo ) ;
143+
144+ const expected = {
145+ data : [
146+ {
147+ id : 'l1' ,
148+ type : 'Letter' ,
149+ attributes : { status : 'PENDING' , specificationId : 's1' , groupId : 'g1' } ,
150+ } ,
151+ ] ,
152+ } ;
153+
154+ expect ( result ) . toEqual ( {
155+ statusCode : 200 ,
156+ body : JSON . stringify ( expected , null , 2 ) ,
157+ } ) ;
158+ } ) ;
159+
115160 it ( 'returns error if the limit parameter is not a number' , async ( ) => {
116161
117162 const event = makeApiGwEvent ( {
0 commit comments