11import { test , expect } from '@playwright/test' ;
2- import { SUPPLIER_LETTERS , supplierId } from '../../constants/api_constants' ;
2+ import { SUPPLIER_LETTERS , SUPPLIERID } from '../../constants/api_constants' ;
33import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper' ;
4- import { patch400ErrorResponseBody , patch500ErrorResponseBody , patchFailureRequestBody , patchRequestHeaders , patchValidRequestBody } from './testCases/UpdateLetterStatus ' ;
4+ import { patch400ErrorResponseBody , patch500ErrorResponseBody , patchFailureRequestBody , patchRequestHeaders , patchValidRequestBody } from './testCases/updateLetterStatus ' ;
55import { createTestData , deleteLettersBySupplier , getLettersBySupplier } from '../../helpers/generate_fetch_testData' ;
66import { randomUUID } from 'crypto' ;
77import { createInvalidRequestHeaders } from '../../constants/request_headers' ;
8+ import { error403ResponseBody } from '../../helpers/commonTypes' ;
89
910let baseUrl : string ;
1011
@@ -15,11 +16,11 @@ test.beforeAll(async () => {
1516test . describe ( 'API Gateway Tests to Verify Patch Status Endpoint' , ( ) => {
1617 test ( `Patch /letters returns 200 and status is updated to ACCEPTED` , async ( { request } ) => {
1718
18- await createTestData ( supplierId ) ;
19- const letters = await getLettersBySupplier ( supplierId , 'PENDING' , 1 ) ;
19+ await createTestData ( SUPPLIERID ) ;
20+ const letters = await getLettersBySupplier ( SUPPLIERID , 'PENDING' , 1 ) ;
2021
2122 if ( ! letters ?. length ) {
22- test . fail ( true , `No PENDING letters found for supplier ${ supplierId } ` ) ;
23+ test . fail ( true , `No PENDING letters found for supplier ${ SUPPLIERID } ` ) ;
2324 return ;
2425 }
2526 const letter = letters [ 0 ] ;
@@ -31,9 +32,9 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
3132 data : body
3233 } ) ;
3334
34- const res = await response . json ( ) ;
35+ const responseBody = await response . json ( ) ;
3536 expect ( response . status ( ) ) . toBe ( 200 ) ;
36- expect ( res ) . toMatchObject ( {
37+ expect ( responseBody ) . toMatchObject ( {
3738 data :{
3839 attributes : {
3940 status : 'ACCEPTED' ,
@@ -50,11 +51,11 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
5051
5152 test ( `Patch /letters returns 200 and status is updated to REJECTED` , async ( { request } ) => {
5253
53- await createTestData ( supplierId ) ;
54- const letters = await getLettersBySupplier ( supplierId , 'PENDING' , 1 ) ;
54+ await createTestData ( SUPPLIERID ) ;
55+ const letters = await getLettersBySupplier ( SUPPLIERID , 'PENDING' , 1 ) ;
5556
5657 if ( ! letters ?. length ) {
57- test . fail ( true , `No PENDING letters found for supplier ${ supplierId } ` ) ;
58+ test . fail ( true , `No PENDING letters found for supplier ${ SUPPLIERID } ` ) ;
5859 return ;
5960 }
6061 const letter = letters [ 0 ] ;
@@ -66,9 +67,9 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
6667 data : body
6768 } ) ;
6869
69- const res = await response . json ( ) ;
70+ const responseBody = await response . json ( ) ;
7071 expect ( response . status ( ) ) . toBe ( 200 ) ;
71- expect ( res ) . toMatchObject ( {
72+ expect ( responseBody ) . toMatchObject ( {
7273 data :{
7374 attributes : {
7475 status : 'REJECTED' ,
@@ -94,10 +95,10 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
9495 data : body
9596 } ) ;
9697
97- const res = await response . json ( ) ;
98+ const responseBody = await response . json ( ) ;
9899
99100 expect ( response . status ( ) ) . toBe ( 400 ) ;
100- expect ( res ) . toMatchObject ( patch400ErrorResponseBody ( ) ) ;
101+ expect ( responseBody ) . toMatchObject ( patch400ErrorResponseBody ( ) ) ;
101102 } ) ;
102103
103104 test ( `Patch /letters returns 500 if Id doesn't exist for SupplierId` , async ( { request } ) => {
@@ -110,13 +111,13 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
110111 data : body
111112 } ) ;
112113
113- const res = await response . json ( ) ;
114+ const responseBody = await response . json ( ) ;
114115 expect ( response . status ( ) ) . toBe ( 500 ) ;
115- expect ( res ) . toMatchObject ( patch500ErrorResponseBody ( id ) ) ;
116+ expect ( responseBody ) . toMatchObject ( patch500ErrorResponseBody ( id ) ) ;
116117 } ) ;
117118
118119 test ( `Patch /letters returns 403 for invalid headers` , async ( { request } ) => {
119- const headers = await createInvalidRequestHeaders ( ) ;
120+ const headers = createInvalidRequestHeaders ( ) ;
120121 const id = randomUUID ( )
121122 const body = patchValidRequestBody ( id , 'PENDING' ) ;
122123
@@ -125,7 +126,8 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
125126 data : body
126127 } ) ;
127128
128- const res = await response . json ( ) ;
129+ const responseBody = await response . json ( ) ;
129130 expect ( response . status ( ) ) . toBe ( 403 ) ;
131+ expect ( responseBody ) . toMatchObject ( error403ResponseBody ( ) ) ;
130132 } ) ;
131133} ) ;
0 commit comments