@@ -124,7 +124,7 @@ describe('API Lambda handler', () => {
124124 const callback = jest . fn ( ) ;
125125 const result = await getLetters ( event , context , callback ) ;
126126
127- expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestLimitNotInRange ) ) ;
127+ expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestLimitNotInRange , { args : [ getEnvars ( ) . maxLimit ] } ) ) ;
128128 expect ( result ) . toEqual ( expectedErrorResponse ) ;
129129 } ) ;
130130
@@ -138,7 +138,7 @@ describe('API Lambda handler', () => {
138138 const callback = jest . fn ( ) ;
139139 const result = await getLetters ( event , context , callback ) ;
140140
141- expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestLimitNotInRange ) ) ;
141+ expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestLimitNotInRange , { args : [ getEnvars ( ) . maxLimit ] } ) ) ;
142142 expect ( result ) . toEqual ( expectedErrorResponse ) ;
143143 } ) ;
144144
@@ -152,7 +152,7 @@ describe('API Lambda handler', () => {
152152 const callback = jest . fn ( ) ;
153153 const result = await getLetters ( event , context , callback ) ;
154154
155- expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestLimitNotInRange ) ) ;
155+ expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestLimitNotInRange , { args : [ getEnvars ( ) . maxLimit ] } ) ) ;
156156 expect ( result ) . toEqual ( expectedErrorResponse ) ;
157157 } ) ;
158158
@@ -189,103 +189,4 @@ describe('API Lambda handler', () => {
189189 expect ( mockedMapErrorToResponse ) . toHaveBeenCalledWith ( new ValidationError ( errors . ApiErrorDetail . InvalidRequestMissingSupplierId ) ) ;
190190 expect ( result ) . toEqual ( expectedErrorResponse ) ;
191191 } ) ;
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- } ) ;
291192} ) ;
0 commit comments