|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | +import getRestApiGatewayBaseUrl from "../../helpers/aws-gateway-helper"; |
| 3 | +import { getLettersBySupplier } from "../../helpers/generate-fetch-test-data"; |
| 4 | +import { SUPPLIERID, SUPPLIER_LETTERS, DATA } from "../../constants/api-constants"; |
| 5 | +import { createValidRequestHeaders } from "../../constants/request-headers"; |
| 6 | +import { |
| 7 | + error404ResponseBody, |
| 8 | + error500ResponseBody, |
| 9 | +} from "../../helpers/common-types"; |
| 10 | + |
| 11 | +let baseUrl: string; |
| 12 | + |
| 13 | +test.beforeAll(async () => { |
| 14 | + baseUrl = await getRestApiGatewayBaseUrl(); |
| 15 | +}); |
| 16 | + |
| 17 | +test.describe("API Gateway Tests to Verify Get Letter PDF Endpoint", () => { |
| 18 | + test(`Get /letters/{id}/data returns 200 and valid response for a given id`, async ({ |
| 19 | + request, |
| 20 | + }) => { |
| 21 | + const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 1); |
| 22 | + |
| 23 | + if (!letters?.length) { |
| 24 | + test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`); |
| 25 | + return; |
| 26 | + } |
| 27 | + const letter = letters[0]; |
| 28 | + const headers = createValidRequestHeaders(); |
| 29 | + const response = await request.get( |
| 30 | + `${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}/${DATA}`, |
| 31 | + { |
| 32 | + headers, |
| 33 | + }, |
| 34 | + ); |
| 35 | + |
| 36 | + const responseBody = await response.json(); |
| 37 | + |
| 38 | + expect(response.status()).toBe(200); |
| 39 | + expect(responseBody).toMatchObject({ |
| 40 | + data: { |
| 41 | + attributes: { |
| 42 | + status: "PENDING", |
| 43 | + specificationId: letter.specificationId, |
| 44 | + groupId: letter.groupId, |
| 45 | + }, |
| 46 | + id: letter.id, |
| 47 | + type: "Letter", |
| 48 | + }, |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + test(`Get /letters/{id}/data returns 404 if no resource is found for id`, async ({ |
| 53 | + request, |
| 54 | + }) => { |
| 55 | + const id = "11"; |
| 56 | + const headers = createValidRequestHeaders(); |
| 57 | + const response = await request.get( |
| 58 | + `${baseUrl}/${SUPPLIER_LETTERS}/${id}/${DATA}`, |
| 59 | + { |
| 60 | + headers, |
| 61 | + }, |
| 62 | + ); |
| 63 | + |
| 64 | + const responseBody = await response.json(); |
| 65 | + expect(response.status()).toBe(404); |
| 66 | + expect(responseBody).toMatchObject(error404ResponseBody()); |
| 67 | + }); |
| 68 | + |
| 69 | + test(`Get /letters/{id}/data returns 500 if letter is not found for supplierId ${SUPPLIERID}`, async ({ |
| 70 | + request, |
| 71 | + }) => { |
| 72 | + const id = "non-existing-id-12345"; |
| 73 | + const headers = createValidRequestHeaders(); |
| 74 | + const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, { |
| 75 | + headers, |
| 76 | + }); |
| 77 | + |
| 78 | + const responseBody = await response.json(); |
| 79 | + expect(response.status()).toBe(500); |
| 80 | + expect(responseBody).toMatchObject(error500ResponseBody()); |
| 81 | + }); |
| 82 | +}); |
0 commit comments