Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions tests/component-tests/apiGateway-tests/createMi.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import {test, expect} from '@playwright/test';
import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper";
import { MI_ENDPOINT } from '../../constants/api_constants';
import { createHeaderWithNoCorrelationId, createHeaderWithNoRequestId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
import { miInvalidDateRequest, miInvalidRequest, miValidRequest } from './testCases/createMi';
import { time } from 'console';
import { error400InvalidDate, error400ResponseBody, error403ResponseBody, error404ResponseBody, requestId500Error } from '../../helpers/commonTypes';

let baseUrl: string;

test.beforeAll(async () => {
baseUrl = await getRestApiGatewayBaseUrl();
});

test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
test(`Post /mi returns 200 when a valid request is passed`, async ({ request }) => {

const headers = createValidRequestHeaders();
const body = miValidRequest();

const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
headers: headers,
data: body
});

const responseBody = await response.json();
expect(response.status()).toBe(201);
expect(responseBody.data.attributes).toMatchObject({
groupId: 'group123',
lineItem: 'envelope-business-standard',
quantity: 10,
specificationId: 'Test-Spec-Id',
stockRemaining: 100,
timestamp: body.data.attributes.timestamp,
});
expect(responseBody.data.type).toBe('ManagementInformation');
});

test(`Post /mi returns 400 when a invalid request is passed`, async ({ request }) => {
const headers = createValidRequestHeaders();
const body = miInvalidRequest();

const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
headers: headers,
data: body
});

const responseBody = await response.json();
expect(response.status()).toBe(400);
expect(responseBody).toMatchObject(error400ResponseBody());
});

test(`Post /mi returns 403 when a authentication header is not passed`, async ({ request }) => {
const headers = createInvalidRequestHeaders();
const body = miValidRequest();

const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
headers: headers,
data: body
});

const responseBody = await response.json();
expect(response.status()).toBe(403);
expect(responseBody).toMatchObject(error403ResponseBody());
});

test(`Post /mi returns 500 when a correlationId is not passed`, async ({ request }) => {
const headers = createHeaderWithNoCorrelationId();
const body = miValidRequest();

const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
headers: headers,
data: body
});

const res = await response.json();
expect(response.status()).toBe(500);
expect(res.errors[0].detail).toBe("The request headers don't contain the APIM correlation id");
});

test(`Post /mi returns 500 when a x-request-id is not passed`, async ({ request }) => {
const headers = createHeaderWithNoRequestId();
const body = miValidRequest();

const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
headers: headers,
data: body
});

const responseBody = await response.json();
expect(response.status()).toBe(500);
expect(responseBody).toMatchObject(requestId500Error());
});

test(`Post /mi returns 400 when a invalid Date is passed`, async ({ request }) => {
const headers = createValidRequestHeaders();
const body = miInvalidDateRequest();

const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
headers: headers,
data: body
});

const responseBody = await response.json();
expect(response.status()).toBe(400);
expect(responseBody).toMatchObject(error400InvalidDate());
});


});
71 changes: 71 additions & 0 deletions tests/component-tests/apiGateway-tests/getLetterStatus.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { test, expect } from '@playwright/test';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
import { getLettersBySupplier } from '../../helpers/generate_fetch_testData';
import { SUPPLIER_LETTERS, SUPPLIERID } from '../../constants/api_constants';
import { createValidRequestHeaders } from '../../constants/request_headers';
import { error404ResponseBody, error500ResponseBody } from '../../helpers/commonTypes';

let baseUrl: string;

test.beforeAll(async () => {
baseUrl = await getRestApiGatewayBaseUrl();
});

test.describe('API Gateway Tests to Verify Get Letter Status Endpoint', () => {
test(`Get /letters/{id} returns 200 and valid response for a given id`, async ({ request }) => {

const letters = await getLettersBySupplier(SUPPLIERID, 'PENDING', 1);

if (!letters?.length) {
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
return;
}
const letter = letters[0];
const headers = createValidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, {
headers: headers,
});

const responseBody = await response.json();

expect(response.status()).toBe(200);
expect(responseBody).toMatchObject({
data:{
attributes: {
status: 'PENDING',
specificationId: letter.specificationId,
groupId: letter.groupId,
},
id: letter.id,
type: 'Letter'
}
});
});

test(`Get /letters/{id} returns 404 if no resource is found for id`, async ({ request }) =>
{
const id = '11';
const headers = createValidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
headers: headers,
});

const responseBody = await response.json();
expect(response.status()).toBe(404);
expect(responseBody).toMatchObject(error404ResponseBody());
});

test(`Get /letters/{id} returns 500 if letter is not found for supplierId ${SUPPLIERID}`, async ({ request }) =>
{
const id = 'non-existing-id-12345';
const headers = createValidRequestHeaders();
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
headers: headers,
});

const responseBody = await response.json();
expect(response.status()).toBe(500);
expect(responseBody).toMatchObject(error500ResponseBody(id));
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { SUPPLIER_LETTERS } from '../../constants/api_constants';
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
import { validateApiResponse } from '../../helpers/validateJsonSchema';
import { link } from 'fs';

let baseUrl: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { RequestHeaders } from '../../../constants/request_headers';
import { supplierId } from '../../../constants/api_constants';
import { SUPPLIERID } from '../../../constants/api_constants';
import { ErrorMessageBody } from '../../../helpers/commonTypes';

export type PatchMessageRequestBody = {
Expand Down Expand Up @@ -33,7 +33,7 @@ export function patchRequestHeaders(): RequestHeaders {
let requestHeaders: RequestHeaders;
requestHeaders = {
headerauth1: process.env.HEADERAUTH || '',
'NHSD-Supplier-ID': supplierId,
'NHSD-Supplier-ID': SUPPLIERID,
'NHSD-Correlation-ID': '12344',
'X-Request-ID': 'requestId1'
};
Expand Down Expand Up @@ -106,7 +106,7 @@ export function patch500ErrorResponseBody (id: string) : ErrorMessageBody{
},
status: "500",
title: "Internal server error",
detail: `Letter with id ${id} not found for supplier ${supplierId}`
detail: `Letter with id ${id} not found for supplier ${SUPPLIERID}`
}
]
};
Expand Down
70 changes: 70 additions & 0 deletions tests/component-tests/apiGateway-tests/testCases/createMi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@



export type MiRequestBody = {
data: {
type: string;
attributes: {
groupId: string;
lineItem: string;
quantity: number;
specificationId: string;
stockRemaining: number;
timestamp: string;
};
};
};

export function miValidRequest() : MiRequestBody{
let requestBody: MiRequestBody;

requestBody = {
data: {
 attributes: {
groupId: 'group123',
lineItem: 'envelope-business-standard',
quantity: 10,
specificationId: 'Test-Spec-Id',
stockRemaining: 100,
timestamp: new Date().toISOString(),
},
type: 'ManagementInformation',
}};
return requestBody;
}

export function miInvalidRequest() : MiRequestBody{
let requestBody: MiRequestBody;

requestBody = {
data: {
 attributes: {
groupId: 'group123',
lineItem: 'envelope-business-standard',
quantity: 10,
specificationId: 'Test-Spec-Id',
stockRemaining: 100,
timestamp: new Date().toISOString(),
},
type: '?',
}};
return requestBody;
}

export function miInvalidDateRequest() : MiRequestBody{
let requestBody: MiRequestBody;

requestBody = {
data: {
 attributes: {
groupId: 'group123',
lineItem: 'envelope-business-standard',
quantity: 10,
specificationId: 'Test-Spec-Id',
stockRemaining: 100,
timestamp: '2021-10-28T',
},
type: 'ManagementInformation',
}};
return requestBody;
}
38 changes: 20 additions & 18 deletions tests/component-tests/apiGateway-tests/updateLetterStatus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { test, expect } from '@playwright/test';
import { SUPPLIER_LETTERS, supplierId } from '../../constants/api_constants';
import { SUPPLIER_LETTERS, SUPPLIERID } from '../../constants/api_constants';
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
import { patch400ErrorResponseBody, patch500ErrorResponseBody, patchFailureRequestBody, patchRequestHeaders, patchValidRequestBody } from './testCases/UpdateLetterStatus';
import { patch400ErrorResponseBody, patch500ErrorResponseBody, patchFailureRequestBody, patchRequestHeaders, patchValidRequestBody } from './testCases/updateLetterStatus';
import { createTestData, deleteLettersBySupplier, getLettersBySupplier } from '../../helpers/generate_fetch_testData';
import { randomUUID } from 'crypto';
import { createInvalidRequestHeaders } from '../../constants/request_headers';
import { error403ResponseBody } from '../../helpers/commonTypes';

let baseUrl: string;

Expand All @@ -15,11 +16,11 @@ test.beforeAll(async () => {
test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
test(`Patch /letters returns 200 and status is updated to ACCEPTED`, async ({ request }) => {

await createTestData(supplierId);
const letters = await getLettersBySupplier(supplierId, 'PENDING', 1);
await createTestData(SUPPLIERID);
const letters = await getLettersBySupplier(SUPPLIERID, 'PENDING', 1);

if (!letters?.length) {
test.fail(true, `No PENDING letters found for supplier ${supplierId}`);
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
return;
}
const letter = letters[0];
Expand All @@ -31,9 +32,9 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
data: body
});

const res = await response.json();
const responseBody = await response.json();
expect(response.status()).toBe(200);
expect(res).toMatchObject({
expect(responseBody).toMatchObject({
data:{
attributes: {
status: 'ACCEPTED',
Expand All @@ -50,11 +51,11 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {

test(`Patch /letters returns 200 and status is updated to REJECTED`, async ({ request }) => {

await createTestData(supplierId);
const letters = await getLettersBySupplier(supplierId, 'PENDING', 1);
await createTestData(SUPPLIERID);
const letters = await getLettersBySupplier(SUPPLIERID, 'PENDING', 1);

if (!letters?.length) {
test.fail(true, `No PENDING letters found for supplier ${supplierId}`);
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
return;
}
const letter = letters[0];
Expand All @@ -66,9 +67,9 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
data: body
});

const res = await response.json();
const responseBody = await response.json();
expect(response.status()).toBe(200);
expect(res).toMatchObject({
expect(responseBody).toMatchObject({
data:{
attributes: {
status: 'REJECTED',
Expand All @@ -94,10 +95,10 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
data: body
});

const res = await response.json();
const responseBody = await response.json();

expect(response.status()).toBe(400);
expect(res).toMatchObject(patch400ErrorResponseBody());
expect(responseBody).toMatchObject(patch400ErrorResponseBody());
});

test(`Patch /letters returns 500 if Id doesn't exist for SupplierId`, async ({ request }) => {
Expand All @@ -110,13 +111,13 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
data: body
});

const res = await response.json();
const responseBody = await response.json();
expect(response.status()).toBe(500);
expect(res).toMatchObject(patch500ErrorResponseBody(id));
expect(responseBody).toMatchObject(patch500ErrorResponseBody(id));
});

test(`Patch /letters returns 403 for invalid headers`, async ({ request }) => {
const headers = await createInvalidRequestHeaders();
const headers = createInvalidRequestHeaders();
const id = randomUUID()
const body = patchValidRequestBody(id, 'PENDING');

Expand All @@ -125,7 +126,8 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
data: body
});

const res = await response.json();
const responseBody = await response.json();
expect(response.status()).toBe(403);
expect(responseBody).toMatchObject(error403ResponseBody());
});
});
Loading
Loading