Skip to content

Commit dcead20

Browse files
tests
1 parent d78a8c7 commit dcead20

File tree

8 files changed

+587
-475
lines changed

8 files changed

+587
-475
lines changed
Lines changed: 102 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,132 @@
1-
import {test, expect} from '@playwright/test';
1+
import { expect, test } from "@playwright/test";
22
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 { miInvalidDateRequest, miInvalidRequest, miValidRequest } from './testCases/createMi';
6-
import { time } from 'console';
7-
import { error400InvalidDate, error400ResponseBody, error403ResponseBody, error404ResponseBody, requestId500Error } from '../../helpers/commonTypes';
3+
import { MI_ENDPOINT } from "../../constants/api_constants";
4+
import {
5+
createHeaderWithNoCorrelationId,
6+
createHeaderWithNoRequestId,
7+
createInvalidRequestHeaders,
8+
createValidRequestHeaders,
9+
} from "../../constants/request_headers";
10+
import {
11+
miInvalidDateRequest,
12+
miInvalidRequest,
13+
miValidRequest,
14+
} from "./testCases/createMi";
15+
import {
16+
error400InvalidDate,
17+
error400ResponseBody,
18+
error403ResponseBody,
19+
requestId500Error,
20+
} from "../../helpers/commonTypes";
821

922
let baseUrl: string;
1023

1124
test.beforeAll(async () => {
1225
baseUrl = await getRestApiGatewayBaseUrl();
1326
});
1427

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 responseBody = await response.json();
27-
expect(response.status()).toBe(201);
28-
expect(responseBody.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(responseBody.data.type).toBe('ManagementInformation');
37-
});
28+
test.describe("API Gateway Tests to Verify Mi Endpoint", () => {
29+
test(`Post /mi returns 200 when a valid request is passed`, async ({
30+
request,
31+
}) => {
32+
const headers = createValidRequestHeaders();
33+
const body = miValidRequest();
34+
35+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
36+
headers,
37+
data: body,
38+
});
3839

39-
test(`Post /mi returns 400 when a invalid request is passed`, async ({ request }) => {
40-
const headers = createValidRequestHeaders();
41-
const body = miInvalidRequest();
40+
const responseBody = await response.json();
41+
expect(response.status()).toBe(201);
42+
expect(responseBody.data.attributes).toMatchObject({
43+
groupId: "group123",
44+
lineItem: "envelope-business-standard",
45+
quantity: 10,
46+
specificationId: "Test-Spec-Id",
47+
stockRemaining: 100,
48+
timestamp: body.data.attributes.timestamp,
49+
});
50+
expect(responseBody.data.type).toBe("ManagementInformation");
51+
});
4252

43-
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
44-
headers: headers,
45-
data: body
46-
});
53+
test(`Post /mi returns 400 when a invalid request is passed`, async ({
54+
request,
55+
}) => {
56+
const headers = createValidRequestHeaders();
57+
const body = miInvalidRequest();
4758

48-
const responseBody = await response.json();
49-
expect(response.status()).toBe(400);
50-
expect(responseBody).toMatchObject(error400ResponseBody());
59+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
60+
headers,
61+
data: body,
5162
});
5263

53-
test(`Post /mi returns 403 when a authentication header is not passed`, async ({ request }) => {
54-
const headers = createInvalidRequestHeaders();
55-
const body = miValidRequest();
64+
const responseBody = await response.json();
65+
expect(response.status()).toBe(400);
66+
expect(responseBody).toMatchObject(error400ResponseBody());
67+
});
5668

57-
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
58-
headers: headers,
59-
data: body
60-
});
69+
test(`Post /mi returns 403 when a authentication header is not passed`, async ({
70+
request,
71+
}) => {
72+
const headers = createInvalidRequestHeaders();
73+
const body = miValidRequest();
6174

62-
const responseBody = await response.json();
63-
expect(response.status()).toBe(403);
64-
expect(responseBody).toMatchObject(error403ResponseBody());
75+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
76+
headers,
77+
data: body,
6578
});
6679

67-
test(`Post /mi returns 500 when a correlationId is not passed`, async ({ request }) => {
68-
const headers = createHeaderWithNoCorrelationId();
69-
const body = miValidRequest();
80+
const responseBody = await response.json();
81+
expect(response.status()).toBe(403);
82+
expect(responseBody).toMatchObject(error403ResponseBody());
83+
});
7084

71-
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
72-
headers: headers,
73-
data: body
74-
});
85+
test(`Post /mi returns 500 when a correlationId is not passed`, async ({
86+
request,
87+
}) => {
88+
const headers = createHeaderWithNoCorrelationId();
89+
const body = miValidRequest();
7590

76-
const res = await response.json();
77-
expect(response.status()).toBe(500);
78-
expect(res.errors[0].detail).toBe("The request headers don't contain the APIM correlation id");
91+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
92+
headers,
93+
data: body,
7994
});
8095

81-
test(`Post /mi returns 500 when a x-request-id is not passed`, async ({ request }) => {
82-
const headers = createHeaderWithNoRequestId();
83-
const body = miValidRequest();
96+
const res = await response.json();
97+
expect(response.status()).toBe(500);
98+
expect(res.errors[0].detail).toBe("Unexpected error");
99+
});
84100

85-
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
86-
headers: headers,
87-
data: body
88-
});
101+
test(`Post /mi returns 500 when a x-request-id is not passed`, async ({
102+
request,
103+
}) => {
104+
const headers = createHeaderWithNoRequestId();
105+
const body = miValidRequest();
89106

90-
const responseBody = await response.json();
91-
expect(response.status()).toBe(500);
92-
expect(responseBody).toMatchObject(requestId500Error());
107+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
108+
headers,
109+
data: body,
93110
});
94111

95-
test(`Post /mi returns 400 when a invalid Date is passed`, async ({ request }) => {
96-
const headers = createValidRequestHeaders();
97-
const body = miInvalidDateRequest();
112+
const responseBody = await response.json();
113+
expect(response.status()).toBe(500);
114+
expect(responseBody).toMatchObject(requestId500Error());
115+
});
98116

99-
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
100-
headers: headers,
101-
data: body
102-
});
117+
test(`Post /mi returns 400 when a invalid Date is passed`, async ({
118+
request,
119+
}) => {
120+
const headers = createValidRequestHeaders();
121+
const body = miInvalidDateRequest();
103122

104-
const responseBody = await response.json();
105-
expect(response.status()).toBe(400);
106-
expect(responseBody).toMatchObject(error400InvalidDate());
123+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
124+
headers,
125+
data: body,
107126
});
108127

109-
128+
const responseBody = await response.json();
129+
expect(response.status()).toBe(400);
130+
expect(responseBody).toMatchObject(error400InvalidDate());
131+
});
110132
});
Lines changed: 59 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,105 @@
1-
import { test, expect } from '@playwright/test';
2-
import { SUPPLIER_LETTERS } from '../../constants/api_constants';
3-
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
4-
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
5-
import { validateApiResponse } from '../../helpers/validateJsonSchema';
1+
import { expect, test } from "@playwright/test";
2+
import { SUPPLIER_LETTERS } from "../../constants/api_constants";
3+
import {
4+
createHeaderWithNoCorrelationId,
5+
createInvalidRequestHeaders,
6+
createValidRequestHeaders,
7+
} from "../../constants/request_headers";
8+
import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper";
9+
import { validateApiResponse } from "../../helpers/validateJsonSchema";
610

711
let baseUrl: string;
812

913
test.beforeAll(async () => {
1014
baseUrl = await getRestApiGatewayBaseUrl();
1115
});
1216

13-
test.describe('API Gateway Tests To Get List Of Pending Letters', () =>
14-
{
15-
test('GET /letters should return 200 and list items', async ({ request }) =>
16-
{
17+
test.describe("API Gateway Tests To Get List Of Pending Letters", () => {
18+
test("GET /letters should return 200 and list items", async ({ request }) => {
1719
const header = createValidRequestHeaders();
18-
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
20+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}`, {
1921
headers: header,
2022
params: {
21-
limit:'2'},
23+
limit: "2",
2224
},
23-
);
25+
});
2426

2527
expect(response.status()).toBe(200);
2628
const responseBody = await response.json();
27-
expect(responseBody.data.length.toString()).toEqual('2');
29+
expect(responseBody.data.length).toBeGreaterThanOrEqual(1);
2830

29-
const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
31+
const validationResult = validateApiResponse(
32+
"get",
33+
"/letters",
34+
response.status(),
35+
responseBody,
36+
);
3037
if (validationResult) {
3138
console.error("API response validation failed:", validationResult);
3239
}
3340
expect(validationResult).toBeUndefined();
3441
});
3542

36-
test('GET /letters with invalid authentication should return 403', async ({ request }) => {
43+
test("GET /letters with invalid authentication should return 403", async ({
44+
request,
45+
}) => {
3746
const header = createInvalidRequestHeaders();
38-
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
47+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}`, {
3948
headers: header,
40-
params:{
41-
limit:'2'
42-
},
49+
params: {
50+
limit: "2",
4351
},
44-
);
52+
});
4553
expect(response.status()).toBe(403);
4654
const responseBody = await response.json();
4755
expect(responseBody).toMatchObject({
48-
Message : 'User is not authorized to access this resource with an explicit deny in an identity-based policy' }
49-
);
56+
Message:
57+
"User is not authorized to access this resource with an explicit deny in an identity-based policy",
58+
});
5059
});
5160

52-
test('GET /letters with empty correlationId should return 500', async ({ request }) => {
61+
test("GET /letters with empty correlationId should return 500", async ({
62+
request,
63+
}) => {
5364
const header = createHeaderWithNoCorrelationId();
54-
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
65+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}`, {
5566
headers: header,
56-
params:{
57-
limit:'2'
58-
},
67+
params: {
68+
limit: "2",
5969
},
60-
);
70+
});
6171
expect(response.status()).toBe(500);
6272
const responseBody = await response.json();
63-
expect(responseBody.errors[0].code).toBe('NOTIFY_INTERNAL_SERVER_ERROR');
64-
expect(responseBody.errors[0].detail).toBe("The request headers don't contain the APIM correlation id");
65-
73+
expect(responseBody.errors[0].code).toBe("NOTIFY_INTERNAL_SERVER_ERROR");
74+
expect(responseBody.errors[0].detail).toBe("Unexpected error");
6675
});
6776

68-
test('GET /letters with invalid query param return 400', async ({ request }) => {
77+
test("GET /letters with invalid query param return 400", async ({
78+
request,
79+
}) => {
6980
const header = createValidRequestHeaders();
70-
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
71-
headers: header,
72-
params:{
73-
limit:'?'
74-
},
75-
});
81+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}`, {
82+
headers: header,
83+
params: {
84+
limit: "?",
85+
},
86+
});
7687
expect(response.status()).toBe(400);
7788
const responseBody = await response.json();
7889
expect(responseBody).toMatchObject({
7990
errors: [
8091
{
81-
id: '12345',
82-
code: 'NOTIFY_INVALID_REQUEST',
92+
id: "12345",
93+
code: "NOTIFY_INVALID_REQUEST",
8394
links: {
84-
about: 'https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier'
85-
},
86-
status: '400',
87-
title: 'Invalid request',
88-
detail: 'The limit parameter is not a number'
89-
}
90-
]
95+
about:
96+
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
97+
},
98+
status: "400",
99+
title: "Invalid request",
100+
detail: "The limit parameter is not a number",
101+
},
102+
],
91103
});
92104
});
93105
});

0 commit comments

Comments
 (0)