@@ -2,9 +2,9 @@ import {test, expect} from '@playwright/test';
22import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper" ;
33import { MI_ENDPOINT } from '../../constants/api_constants' ;
44import { createHeaderWithNoCorrelationId , createHeaderWithNoRequestId , createInvalidRequestHeaders , createValidRequestHeaders } from '../../constants/request_headers' ;
5- import { miInValidRequest , miValidRequest } from './testCases/createMi' ;
5+ import { miInvalidDateRequest , miInvalidRequest , miValidRequest } from './testCases/createMi' ;
66import { time } from 'console' ;
7- import { error400ResponseBody , error404ResponseBody , RequestId500Error } from '../../helpers/commonTypes' ;
7+ import { error400InvalidDate , error400ResponseBody , error403ResponseBody , error404ResponseBody , requestId500Error } from '../../helpers/commonTypes' ;
88
99let baseUrl : string ;
1010
@@ -23,34 +23,34 @@ test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
2323 data : body
2424 } ) ;
2525
26- const res = await response . json ( ) ;
26+ const responseBody = await response . json ( ) ;
2727 expect ( response . status ( ) ) . toBe ( 201 ) ;
28- expect ( res . data . attributes ) . toMatchObject ( {
28+ expect ( responseBody . data . attributes ) . toMatchObject ( {
2929 groupId : 'group123' ,
3030 lineItem : 'envelope-business-standard' ,
3131 quantity : 10 ,
3232 specificationId : 'Test-Spec-Id' ,
3333 stockRemaining : 100 ,
3434 timestamp : body . data . attributes . timestamp ,
3535 } ) ;
36- expect ( res . data . type ) . toBe ( 'ManagementInformation' ) ;
36+ expect ( responseBody . data . type ) . toBe ( 'ManagementInformation' ) ;
3737 } ) ;
3838
3939 test ( `Post /mi returns 400 when a invalid request is passed` , async ( { request } ) => {
4040 const headers = createValidRequestHeaders ( ) ;
41- const body = miInValidRequest ( ) ;
41+ const body = miInvalidRequest ( ) ;
4242
4343 const response = await request . post ( `${ baseUrl } /${ MI_ENDPOINT } ` , {
4444 headers : headers ,
4545 data : body
4646 } ) ;
4747
48- const res = await response . json ( ) ;
48+ const responseBody = await response . json ( ) ;
4949 expect ( response . status ( ) ) . toBe ( 400 ) ;
50- expect ( res ) . toMatchObject ( error400ResponseBody ( ) ) ;
50+ expect ( responseBody ) . toMatchObject ( error400ResponseBody ( ) ) ;
5151 } ) ;
5252
53- test ( `Post /mi returns 403 when a invalid request is passed` , async ( { request } ) => {
53+ test ( `Post /mi returns 403 when a authentication header is not passed` , async ( { request } ) => {
5454 const headers = createInvalidRequestHeaders ( ) ;
5555 const body = miValidRequest ( ) ;
5656
@@ -59,11 +59,9 @@ test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
5959 data : body
6060 } ) ;
6161
62- const res = await response . json ( ) ;
62+ const responseBody = await response . json ( ) ;
6363 expect ( response . status ( ) ) . toBe ( 403 ) ;
64- expect ( res ) . toMatchObject ( {
65- Message : 'User is not authorized to access this resource with an explicit deny in an identity-based policy' }
66- ) ;
64+ expect ( responseBody ) . toMatchObject ( error403ResponseBody ( ) ) ;
6765 } ) ;
6866
6967 test ( `Post /mi returns 500 when a correlationId is not passed` , async ( { request } ) => {
@@ -89,9 +87,23 @@ test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
8987 data : body
9088 } ) ;
9189
92- const res = await response . json ( ) ;
90+ const responseBody = await response . json ( ) ;
9391 expect ( response . status ( ) ) . toBe ( 500 ) ;
94- expect ( res ) . toMatchObject ( RequestId500Error ( ) ) ;
92+ expect ( responseBody ) . toMatchObject ( requestId500Error ( ) ) ;
93+ } ) ;
94+
95+ test ( `Post /mi returns 400 when a invalid Date is passed` , async ( { request } ) => {
96+ const headers = createValidRequestHeaders ( ) ;
97+ const body = miInvalidDateRequest ( ) ;
98+
99+ const response = await request . post ( `${ baseUrl } /${ MI_ENDPOINT } ` , {
100+ headers : headers ,
101+ data : body
102+ } ) ;
103+
104+ const responseBody = await response . json ( ) ;
105+ expect ( response . status ( ) ) . toBe ( 400 ) ;
106+ expect ( responseBody ) . toMatchObject ( error400InvalidDate ( ) ) ;
95107 } ) ;
96108
97109
0 commit comments