Skip to content

Commit 7b02f4e

Browse files
review
1 parent 69a7224 commit 7b02f4e

File tree

5 files changed

+92
-34
lines changed

5 files changed

+92
-34
lines changed

tests/component-tests/apiGateway-tests/createMi.spec.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import {test, expect} from '@playwright/test';
22
import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper";
33
import { MI_ENDPOINT } from '../../constants/api_constants';
44
import { createHeaderWithNoCorrelationId, createHeaderWithNoRequestId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
5-
import { miInValidRequest, miValidRequest } from './testCases/createMi';
5+
import { miInvalidDateRequest, miInvalidRequest, miValidRequest } from './testCases/createMi';
66
import { time } from 'console';
7-
import { error400ResponseBody, error404ResponseBody, RequestId500Error } from '../../helpers/commonTypes';
7+
import { error400InvalidDate, error400ResponseBody, error403ResponseBody, error404ResponseBody, requestId500Error } from '../../helpers/commonTypes';
88

99
let baseUrl: string;
1010

@@ -23,34 +23,34 @@ test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
2323
data: body
2424
});
2525

26-
const res = await response.json();
26+
const responseBody = await response.json();
2727
expect(response.status()).toBe(201);
28-
expect(res.data.attributes).toMatchObject({
28+
expect(responseBody.data.attributes).toMatchObject({
2929
groupId: 'group123',
3030
lineItem: 'envelope-business-standard',
3131
quantity: 10,
3232
specificationId: 'Test-Spec-Id',
3333
stockRemaining: 100,
3434
timestamp: body.data.attributes.timestamp,
3535
});
36-
expect(res.data.type).toBe('ManagementInformation');
36+
expect(responseBody.data.type).toBe('ManagementInformation');
3737
});
3838

3939
test(`Post /mi returns 400 when a invalid request is passed`, async ({ request }) => {
4040
const headers = createValidRequestHeaders();
41-
const body = miInValidRequest();
41+
const body = miInvalidRequest();
4242

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

48-
const res = await response.json();
48+
const responseBody = await response.json();
4949
expect(response.status()).toBe(400);
50-
expect(res).toMatchObject(error400ResponseBody());
50+
expect(responseBody).toMatchObject(error400ResponseBody());
5151
});
5252

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

@@ -59,11 +59,9 @@ test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
5959
data: body
6060
});
6161

62-
const res = await response.json();
62+
const responseBody = await response.json();
6363
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-
);
64+
expect(responseBody).toMatchObject(error403ResponseBody());
6765
});
6866

6967
test(`Post /mi returns 500 when a correlationId is not passed`, async ({ request }) => {
@@ -89,9 +87,23 @@ test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
8987
data: body
9088
});
9189

92-
const res = await response.json();
90+
const responseBody = await response.json();
9391
expect(response.status()).toBe(500);
94-
expect(res).toMatchObject(RequestId500Error());
92+
expect(responseBody).toMatchObject(requestId500Error());
93+
});
94+
95+
test(`Post /mi returns 400 when a invalid Date is passed`, async ({ request }) => {
96+
const headers = createValidRequestHeaders();
97+
const body = miInvalidDateRequest();
98+
99+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
100+
headers: headers,
101+
data: body
102+
});
103+
104+
const responseBody = await response.json();
105+
expect(response.status()).toBe(400);
106+
expect(responseBody).toMatchObject(error400InvalidDate());
95107
});
96108

97109

tests/component-tests/apiGateway-tests/getLetterStatus.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test.describe('API Gateway Tests to Verify Get Letter Status Endpoint', () => {
2626
headers: headers,
2727
});
2828

29-
const res = await response.json();
29+
const responseBody = await response.json();
3030

3131
expect(response.status()).toBe(200);
32-
expect(res).toMatchObject({
32+
expect(responseBody).toMatchObject({
3333
data:{
3434
attributes: {
3535
status: 'PENDING',
@@ -50,9 +50,9 @@ test.describe('API Gateway Tests to Verify Get Letter Status Endpoint', () => {
5050
headers: headers,
5151
});
5252

53-
const res = await response.json();
53+
const responseBody = await response.json();
5454
expect(response.status()).toBe(404);
55-
expect(res).toMatchObject(error404ResponseBody());
55+
expect(responseBody).toMatchObject(error404ResponseBody());
5656
});
5757

5858
test(`Get /letters/{id} returns 500 if letter is not found for supplierId ${SUPPLIERID}`, async ({ request }) =>
@@ -63,9 +63,9 @@ test.describe('API Gateway Tests to Verify Get Letter Status Endpoint', () => {
6363
headers: headers,
6464
});
6565

66-
const res = await response.json();
66+
const responseBody = await response.json();
6767
expect(response.status()).toBe(500);
68-
expect(res).toMatchObject(error500ResponseBody(id));
68+
expect(responseBody).toMatchObject(error500ResponseBody(id));
6969
});
7070

7171
});

tests/component-tests/apiGateway-tests/testCases/createMi.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function miValidRequest() : MiRequestBody{
3333
return requestBody;
3434
}
3535

36-
export function miInValidRequest() : MiRequestBody{
36+
export function miInvalidRequest() : MiRequestBody{
3737
let requestBody: MiRequestBody;
3838

3939
requestBody = {
@@ -50,3 +50,21 @@ export function miInValidRequest() : MiRequestBody{
5050
}};
5151
return requestBody;
5252
}
53+
54+
export function miInvalidDateRequest() : MiRequestBody{
55+
let requestBody: MiRequestBody;
56+
57+
requestBody = {
58+
data: {
59+
 attributes: {
60+
groupId: 'group123',
61+
lineItem: 'envelope-business-standard',
62+
quantity: 10,
63+
specificationId: 'Test-Spec-Id',
64+
stockRemaining: 100,
65+
timestamp: '2021-10-28T',
66+
},
67+
type: 'ManagementInformation',
68+
}};
69+
return requestBody;
70+
}

tests/component-tests/apiGateway-tests/updateLetterStatus.spec.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { test, expect } from '@playwright/test';
22
import { SUPPLIER_LETTERS, SUPPLIERID } from '../../constants/api_constants';
33
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
4-
import { patch400ErrorResponseBody, patch500ErrorResponseBody, patchFailureRequestBody, patchRequestHeaders, patchValidRequestBody } from './testCases/UpdateLetterStatus';
4+
import { patch400ErrorResponseBody, patch500ErrorResponseBody, patchFailureRequestBody, patchRequestHeaders, patchValidRequestBody } from './testCases/updateLetterStatus';
55
import { createTestData, deleteLettersBySupplier, getLettersBySupplier } from '../../helpers/generate_fetch_testData';
66
import { randomUUID } from 'crypto';
77
import { createInvalidRequestHeaders } from '../../constants/request_headers';
8+
import { error403ResponseBody } from '../../helpers/commonTypes';
89

910
let baseUrl: string;
1011

@@ -31,9 +32,9 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
3132
data: body
3233
});
3334

34-
const res = await response.json();
35+
const responseBody = await response.json();
3536
expect(response.status()).toBe(200);
36-
expect(res).toMatchObject({
37+
expect(responseBody).toMatchObject({
3738
data:{
3839
attributes: {
3940
status: 'ACCEPTED',
@@ -66,9 +67,9 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
6667
data: body
6768
});
6869

69-
const res = await response.json();
70+
const responseBody = await response.json();
7071
expect(response.status()).toBe(200);
71-
expect(res).toMatchObject({
72+
expect(responseBody).toMatchObject({
7273
data:{
7374
attributes: {
7475
status: 'REJECTED',
@@ -94,10 +95,10 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
9495
data: body
9596
});
9697

97-
const res = await response.json();
98+
const responseBody = await response.json();
9899

99100
expect(response.status()).toBe(400);
100-
expect(res).toMatchObject(patch400ErrorResponseBody());
101+
expect(responseBody).toMatchObject(patch400ErrorResponseBody());
101102
});
102103

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

113-
const res = await response.json();
114+
const responseBody = await response.json();
114115
expect(response.status()).toBe(500);
115-
expect(res).toMatchObject(patch500ErrorResponseBody(id));
116+
expect(responseBody).toMatchObject(patch500ErrorResponseBody(id));
116117
});
117118

118119
test(`Patch /letters returns 403 for invalid headers`, async ({ request }) => {
119-
const headers = await createInvalidRequestHeaders();
120+
const headers = createInvalidRequestHeaders();
120121
const id = randomUUID()
121122
const body = patchValidRequestBody(id, 'PENDING');
122123

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

128-
const res = await response.json();
129+
const responseBody = await response.json();
129130
expect(response.status()).toBe(403);
131+
expect(responseBody).toMatchObject(error403ResponseBody());
130132
});
131133
});

tests/helpers/commonTypes.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function error400ResponseBody () : ErrorMessageBody{
7777
return responseBody;
7878
}
7979

80-
export function RequestId500Error () : ErrorMessageBody{
80+
export function requestId500Error () : ErrorMessageBody{
8181
let responseBody: ErrorMessageBody;
8282

8383
responseBody = {
@@ -96,3 +96,29 @@ export function RequestId500Error () : ErrorMessageBody{
9696
};
9797
return responseBody;
9898
}
99+
100+
export function error403ResponseBody () : { Message: string }{
101+
return {
102+
Message : 'User is not authorized to access this resource with an explicit deny in an identity-based policy'
103+
};
104+
}
105+
106+
export function error400InvalidDate () : ErrorMessageBody{
107+
108+
let responseBody: ErrorMessageBody;
109+
responseBody = {
110+
errors: [
111+
{
112+
id: '12345',
113+
code: "NOTIFY_INVALID_REQUEST",
114+
links: {
115+
"about": "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
116+
},
117+
status: "400",
118+
title: "Invalid request",
119+
detail: "Timestamps should be UTC date/times in ISO8601 format, with a Z suffix"
120+
}
121+
]
122+
};
123+
return responseBody;
124+
}

0 commit comments

Comments
 (0)