|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import { SUPPLIERID, SUPPLIER_LETTERS } from "../../constants/api-constants"; |
| 3 | +import getRestApiGatewayBaseUrl from "../../helpers/aws-gateway-helper"; |
| 4 | +import { |
| 5 | + post500ErrorResponseBody, |
| 6 | + postDuplicateIDRequestBody, |
| 7 | + postDuplicateIDResponseBody, |
| 8 | + postInvalidStatusRequestBody, |
| 9 | + postInvalidStatusResponseBody, |
| 10 | + postLettersInvalidRequestHeaders, |
| 11 | + postLettersRequestHeaders, |
| 12 | + postValidRequestBody, |
| 13 | +} from "./testCases/update-multiple-letter-status"; |
| 14 | +import { |
| 15 | + createTestData, |
| 16 | + getLettersBySupplier, |
| 17 | +} from "../../helpers/generate-fetch-test-data"; |
| 18 | + |
| 19 | +let baseUrl: string; |
| 20 | + |
| 21 | +test.beforeAll(async () => { |
| 22 | + baseUrl = await getRestApiGatewayBaseUrl(); |
| 23 | +}); |
| 24 | + |
| 25 | +test.describe("API Gateway Tests to Verify post Status Endpoint", () => { |
| 26 | + test(`post /letters returns 202 and status is updated for multiple letters`, async ({ |
| 27 | + request, |
| 28 | + }) => { |
| 29 | + await createTestData(SUPPLIERID, 4); |
| 30 | + const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 4); |
| 31 | + |
| 32 | + if (!letters?.length) { |
| 33 | + test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + const headers = postLettersRequestHeaders(); |
| 38 | + const body = postValidRequestBody(letters); |
| 39 | + |
| 40 | + const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { |
| 41 | + headers, |
| 42 | + data: body, |
| 43 | + }); |
| 44 | + |
| 45 | + expect(response.status()).toBe(202); |
| 46 | + }); |
| 47 | + |
| 48 | + test(`Post /letters returns 400 if request has invalid status`, async ({ |
| 49 | + request, |
| 50 | + }) => { |
| 51 | + await createTestData(SUPPLIERID, 2); |
| 52 | + const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 2); |
| 53 | + |
| 54 | + if (!letters?.length) { |
| 55 | + test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); |
| 56 | + return; |
| 57 | + } |
| 58 | + |
| 59 | + const headers = postLettersRequestHeaders(); |
| 60 | + const body = postInvalidStatusRequestBody(letters); |
| 61 | + |
| 62 | + const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { |
| 63 | + headers, |
| 64 | + data: body, |
| 65 | + }); |
| 66 | + |
| 67 | + const responseBody = await response.json(); |
| 68 | + |
| 69 | + expect(response.status()).toBe(400); |
| 70 | + expect(responseBody).toMatchObject(postInvalidStatusResponseBody()); |
| 71 | + }); |
| 72 | + |
| 73 | + test(`Post /letters returns 400 if request has duplicate id`, async ({ |
| 74 | + request, |
| 75 | + }) => { |
| 76 | + await createTestData(SUPPLIERID, 2); |
| 77 | + const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 2); |
| 78 | + |
| 79 | + if (!letters?.length) { |
| 80 | + test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); |
| 81 | + return; |
| 82 | + } |
| 83 | + |
| 84 | + const headers = postLettersRequestHeaders(); |
| 85 | + const body = postDuplicateIDRequestBody(letters); |
| 86 | + |
| 87 | + const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { |
| 88 | + headers, |
| 89 | + data: body, |
| 90 | + }); |
| 91 | + |
| 92 | + const responseBody = await response.json(); |
| 93 | + |
| 94 | + expect(response.status()).toBe(400); |
| 95 | + expect(responseBody).toMatchObject(postDuplicateIDResponseBody()); |
| 96 | + }); |
| 97 | + |
| 98 | + test(`Post /letters returns 500 if request has invalid header`, async ({ |
| 99 | + request, |
| 100 | + }) => { |
| 101 | + await createTestData(SUPPLIERID, 4); |
| 102 | + const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 4); |
| 103 | + |
| 104 | + if (!letters?.length) { |
| 105 | + test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); |
| 106 | + return; |
| 107 | + } |
| 108 | + |
| 109 | + const headers = postLettersInvalidRequestHeaders(); |
| 110 | + const body = postValidRequestBody(letters); |
| 111 | + |
| 112 | + const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, { |
| 113 | + headers, |
| 114 | + data: body, |
| 115 | + }); |
| 116 | + |
| 117 | + const responseBody = await response.json(); |
| 118 | + |
| 119 | + expect(response.status()).toBe(500); |
| 120 | + expect(responseBody).toMatchObject(post500ErrorResponseBody()); |
| 121 | + }); |
| 122 | +}); |
0 commit comments