@@ -72,21 +72,22 @@ describe('postMI API Handler', () => {
7272 } ) ;
7373
7474
75- it . each ( [ [ 'not a date string' ] , [ '2025-10-16T00:00:00' ] , [ '2025-16-10T00:00:00Z' ] ] )
76- ( 'returns 400 Bad Request when the timestamp is not an ISO8601 instant' , async ( timestamp : string ) => {
77- const invalidRequest = JSON . parse ( requestBody ) ;
78- invalidRequest [ 'data' ] [ 'attributes' ] [ 'timestamp' ] = timestamp ;
75+ it . each ( [ [ 'not a date string' , false ] , [ '2025-10-16T00:00:00' , false ] , [ '2025-16-10T00:00:00Z' , false ] ,
76+ [ '2025-10-16T00:00:00Z' , true ] , [ '2025-10-16T00:00:00.000000Z' , true ] ] )
77+ ( 'validates the timestamp' , async ( timestamp : string , valid : boolean ) => {
78+ const modifiedRequest = JSON . parse ( requestBody ) ;
79+ modifiedRequest [ 'data' ] [ 'attributes' ] [ 'timestamp' ] = timestamp ;
7980 const event = makeApiGwEvent ( {
8081 path : '/mi' ,
81- body : JSON . stringify ( invalidRequest ) ,
82+ body : JSON . stringify ( modifiedRequest ) ,
8283 headers : { 'nhsd-supplier-id' : 'supplier1' , 'nhsd-correlation-id' : 'correlationId' }
8384 } ) ;
8485
8586 const postMI = createPostMIHandler ( mockedDeps ) ;
8687 const result = await postMI ( event , mockDeep < Context > ( ) , jest . fn ( ) ) ;
8788
8889 expect ( result ) . toEqual ( expect . objectContaining ( {
89- statusCode : 400
90+ statusCode : valid ? 201 : 400
9091 } ) ) ;
9192 } ) ;
9293
0 commit comments