|
| 1 | +import {test, expect} from '@playwright/test'; |
| 2 | +import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper"; |
| 3 | +import { MI_ENDPOINT } from '../../constants/api_constants'; |
| 4 | +import { createHeaderWithNoCorrelationId, createHeaderWithNoRequestId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers'; |
| 5 | +import { miInValidRequest, miValidRequest } from './testCases/createMi'; |
| 6 | +import { time } from 'console'; |
| 7 | +import { error400ResponseBody, error404ResponseBody, RequestId500Error } from '../../helpers/commonTypes'; |
| 8 | + |
| 9 | +let baseUrl: string; |
| 10 | + |
| 11 | +test.beforeAll(async () => { |
| 12 | + baseUrl = await getRestApiGatewayBaseUrl(); |
| 13 | +}); |
| 14 | + |
| 15 | +test.describe('API Gateway Tests to Verify Mi Endpoint', () => { |
| 16 | + test(`Post /mi returns 200 when a valid request is passed`, async ({ request }) => { |
| 17 | + |
| 18 | + const headers = createValidRequestHeaders(); |
| 19 | + const body = miValidRequest(); |
| 20 | + |
| 21 | + const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { |
| 22 | + headers: headers, |
| 23 | + data: body |
| 24 | + }); |
| 25 | + |
| 26 | + const res = await response.json(); |
| 27 | + expect(response.status()).toBe(201); |
| 28 | + expect(res.data.attributes).toMatchObject({ |
| 29 | + groupId: 'group123', |
| 30 | + lineItem: 'envelope-business-standard', |
| 31 | + quantity: 10, |
| 32 | + specificationId: 'Test-Spec-Id', |
| 33 | + stockRemaining: 100, |
| 34 | + timestamp: body.data.attributes.timestamp, |
| 35 | + }); |
| 36 | + expect(res.data.type).toBe('ManagementInformation'); |
| 37 | + }); |
| 38 | + |
| 39 | + test(`Post /mi returns 400 when a invalid request is passed`, async ({ request }) => { |
| 40 | + const headers = createValidRequestHeaders(); |
| 41 | + const body = miInValidRequest(); |
| 42 | + |
| 43 | + const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { |
| 44 | + headers: headers, |
| 45 | + data: body |
| 46 | + }); |
| 47 | + |
| 48 | + const res = await response.json(); |
| 49 | + expect(response.status()).toBe(400); |
| 50 | + expect(res).toMatchObject(error400ResponseBody()); |
| 51 | + }); |
| 52 | + |
| 53 | + test(`Post /mi returns 403 when a invalid request is passed`, async ({ request }) => { |
| 54 | + const headers = createInvalidRequestHeaders(); |
| 55 | + const body = miValidRequest(); |
| 56 | + |
| 57 | + const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { |
| 58 | + headers: headers, |
| 59 | + data: body |
| 60 | + }); |
| 61 | + |
| 62 | + const res = await response.json(); |
| 63 | + 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 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + test(`Post /mi returns 500 when a correlationId is not passed`, async ({ request }) => { |
| 70 | + const headers = createHeaderWithNoCorrelationId(); |
| 71 | + const body = miValidRequest(); |
| 72 | + |
| 73 | + const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { |
| 74 | + headers: headers, |
| 75 | + data: body |
| 76 | + }); |
| 77 | + |
| 78 | + const res = await response.json(); |
| 79 | + expect(response.status()).toBe(500); |
| 80 | + expect(res.errors[0].detail).toBe("The request headers don't contain the APIM correlation id"); |
| 81 | + }); |
| 82 | + |
| 83 | + test(`Post /mi returns 500 when a x-request-id is not passed`, async ({ request }) => { |
| 84 | + const headers = createHeaderWithNoRequestId(); |
| 85 | + const body = miValidRequest(); |
| 86 | + |
| 87 | + const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, { |
| 88 | + headers: headers, |
| 89 | + data: body |
| 90 | + }); |
| 91 | + |
| 92 | + const res = await response.json(); |
| 93 | + expect(response.status()).toBe(500); |
| 94 | + expect(res).toMatchObject(RequestId500Error()); |
| 95 | + }); |
| 96 | + |
| 97 | + |
| 98 | +}); |
0 commit comments