@@ -16,7 +16,6 @@ const expectedErrorResponse: APIGatewayProxyResult = {
1616} ;
1717mockedMapErrorToResponse . mockReturnValue ( expectedErrorResponse ) ;
1818
19-
2019jest . mock ( '../../services/letter-operations' ) ;
2120
2221jest . mock ( "../../config/lambda-config" , ( ) => ( {
@@ -190,4 +189,103 @@ describe('API Lambda handler', () => {
190189 expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestMissingSupplierId ) ) ;
191190 expect ( result ) . toEqual ( expectedErrorResponse ) ;
192191 } ) ;
192+
193+ it ( "returns 400 if the limit parameter is not a number" , async ( ) => {
194+ const event = makeApiGwEvent ( {
195+ path : "/letters" ,
196+ queryStringParameters : { limit : "1%" } ,
197+ } ) ;
198+ const context = mockDeep < Context > ( ) ;
199+ const callback = jest . fn ( ) ;
200+ const result = await getLetters ( event , context , callback ) ;
201+
202+ expect ( result ) . toEqual ( {
203+ statusCode : 400 ,
204+ body : "Invalid Request: limit parameter must be a positive number not greater than 2500" ,
205+ } ) ;
206+ } ) ;
207+
208+ it ( "returns 400 if the limit parameter is negative" , async ( ) => {
209+ const event = makeApiGwEvent ( {
210+ path : "/letters" ,
211+ queryStringParameters : { limit : "-1" } ,
212+ } ) ;
213+ const context = mockDeep < Context > ( ) ;
214+ const callback = jest . fn ( ) ;
215+ const result = await getLetters ( event , context , callback ) ;
216+
217+ expect ( result ) . toEqual ( {
218+ statusCode : 400 ,
219+ body : "Invalid Request: limit parameter must be a positive number not greater than 2500" ,
220+ } ) ;
221+ } ) ;
222+
223+ it ( "returns 400 if the limit parameter is zero" , async ( ) => {
224+ const event = makeApiGwEvent ( {
225+ path : "/letters" ,
226+ queryStringParameters : { limit : "0" } ,
227+ } ) ;
228+ const context = mockDeep < Context > ( ) ;
229+ const callback = jest . fn ( ) ;
230+ const result = await getLetters ( event , context , callback ) ;
231+
232+ expect ( result ) . toEqual ( {
233+ statusCode : 400 ,
234+ body : "Invalid Request: limit parameter must be a positive number not greater than 2500" ,
235+ } ) ;
236+ } ) ;
237+
238+ it ( "returns 400 if the limit parameter is out of range" , async ( ) => {
239+ const event = makeApiGwEvent ( {
240+ path : "/letters" ,
241+ queryStringParameters : { limit : "2501" } ,
242+ } ) ;
243+ const context = mockDeep < Context > ( ) ;
244+ const callback = jest . fn ( ) ;
245+ const result = await getLetters ( event , context , callback ) ;
246+
247+ expect ( result ) . toEqual ( {
248+ statusCode : 400 ,
249+ body : "Invalid Request: limit parameter must be a positive number not greater than 2500" ,
250+ } ) ;
251+ } ) ;
252+
253+ it ( "returns 400 if unknown parameters are present" , async ( ) => {
254+ const event = makeApiGwEvent ( {
255+ path : "/letters" ,
256+ queryStringParameters : { max : "2000" } ,
257+ } ) ;
258+ const context = mockDeep < Context > ( ) ;
259+ const callback = jest . fn ( ) ;
260+ const result = await getLetters ( event , context , callback ) ;
261+
262+ expect ( result ) . toEqual ( {
263+ statusCode : 400 ,
264+ body : "Invalid Request: Only 'limit' query parameter is supported" ,
265+ } ) ;
266+ } ) ;
267+
268+ it ( 'returns 400 for missing supplier ID (empty headers)' , async ( ) => {
269+ const event = makeApiGwEvent ( { path : "/letters" , headers : { } } ) ;
270+ const context = mockDeep < Context > ( ) ;
271+ const callback = jest . fn ( ) ;
272+ const result = await getLetters ( event , context , callback ) ;
273+
274+ expect ( result ) . toEqual ( {
275+ statusCode : 400 ,
276+ body : 'Invalid Request: Missing supplier ID' ,
277+ } ) ;
278+ } ) ;
279+
280+ it ( 'returns 400 for missing supplier ID (undefined headers)' , async ( ) => {
281+ const event = makeApiGwEvent ( { path : "/letters" , headers : undefined } ) ;
282+ const context = mockDeep < Context > ( ) ;
283+ const callback = jest . fn ( ) ;
284+ const result = await getLetters ( event , context , callback ) ;
285+
286+ expect ( result ) . toEqual ( {
287+ statusCode : 400 ,
288+ body : 'Invalid Request: Missing supplier ID' ,
289+ } ) ;
290+ } ) ;
193291} ) ;
0 commit comments