Skip to content

Commit 77a6544

Browse files
review fixes
1 parent 4d5d4e7 commit 77a6544

File tree

7 files changed

+95
-18
lines changed

7 files changed

+95
-18
lines changed
Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { test, expect } from '@playwright/test';
2-
import { SUPPLIER_LETTERS, AWS_REGION } from '../../constants/api_constants';
2+
import { SUPPLIER_LETTERS } from '../../constants/api_constants';
33
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
4-
import { validateApiResponse } from '../../helpers/validateJsonSchema';
54
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
5+
import { validateApiResponse } from '../../helpers/validateJsonSchema';
6+
import { link } from 'fs';
67

78
let baseUrl: string;
89

910
test.beforeAll(async () => {
10-
const region = AWS_REGION;
1111
baseUrl = await getRestApiGatewayBaseUrl();
1212
});
1313

1414
test.describe('API Gateway Tests To Get List Of Pending Letters', () =>
1515
{
1616
test('GET /letters should return 200 and list items', async ({ request }) =>
1717
{
18-
const header = await createValidRequestHeaders();
18+
const header = createValidRequestHeaders();
1919
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
2020
headers: header,
2121
params: {
@@ -25,10 +25,17 @@ test.describe('API Gateway Tests To Get List Of Pending Letters', () =>
2525

2626
expect(response.status()).toBe(200);
2727
const responseBody = await response.json();
28+
expect(responseBody.data.length.toString()).toEqual('2');
29+
30+
const validationResult = validateApiResponse("get", "/letters", response.status(), responseBody);
31+
if (validationResult) {
32+
console.error("API response validation failed:", validationResult);
33+
}
34+
expect(validationResult).toBeUndefined();
2835
});
2936

3037
test('GET /letters with invalid authentication should return 403', async ({ request }) => {
31-
const header = await createInvalidRequestHeaders();
38+
const header = createInvalidRequestHeaders();
3239
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
3340
headers: header,
3441
params:{
@@ -37,11 +44,14 @@ test.describe('API Gateway Tests To Get List Of Pending Letters', () =>
3744
},
3845
);
3946
expect(response.status()).toBe(403);
47+
const responseBody = await response.json();
48+
expect(responseBody).toMatchObject({
49+
Message : 'User is not authorized to access this resource with an explicit deny in an identity-based policy' }
50+
);
4051
});
4152

42-
4353
test('GET /letters with empty correlationId should return 500', async ({ request }) => {
44-
const header = await createHeaderWithNoCorrelationId();
54+
const header = createHeaderWithNoCorrelationId();
4555
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
4656
headers: header,
4757
params:{
@@ -51,10 +61,13 @@ test.describe('API Gateway Tests To Get List Of Pending Letters', () =>
5161
);
5262
expect(response.status()).toBe(500);
5363
const responseBody = await response.json();
64+
expect(responseBody.errors[0].code).toBe('NOTIFY_INTERNAL_SERVER_ERROR');
65+
expect(responseBody.errors[0].detail).toBe("The request headers don't contain the APIM correlation id");
66+
5467
});
5568

5669
test('GET /letters with invalid query param return 400', async ({ request }) => {
57-
const header = await createValidRequestHeaders();
70+
const header = createValidRequestHeaders();
5871
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{
5972
headers: header,
6073
params:{
@@ -63,6 +76,19 @@ test.describe('API Gateway Tests To Get List Of Pending Letters', () =>
6376
});
6477
expect(response.status()).toBe(400);
6578
const responseBody = await response.json();
79+
expect(responseBody).toMatchObject({
80+
errors: [
81+
{
82+
id: '12345',
83+
code: 'NOTIFY_INVALID_REQUEST',
84+
links: {
85+
about: 'https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier'
86+
},
87+
status: '400',
88+
title: 'Invalid request',
89+
detail: 'The limit parameter is not a number'
90+
}
91+
]
92+
});
6693
});
67-
6894
});

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import { RequestHeaders } from '../../../constants/request_headers';
33
import { supplierId } from '../../../constants/api_constants';
4+
import { ErrorMessageBody } from '../../../helpers/commonTypes';
45

56
export type PatchMessageRequestBody = {
67
data: {
@@ -73,3 +74,41 @@ export function patchFailureRequestBody (id: string, status: string) : PatchMess
7374
};
7475
return requestBody;
7576
}
77+
78+
export function patch400ErrorResponseBody () : ErrorMessageBody{
79+
let responseBody: ErrorMessageBody;
80+
responseBody = {
81+
errors: [
82+
{
83+
id : '12344',
84+
code : 'NOTIFY_INVALID_REQUEST',
85+
"links": {
86+
"about": "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
87+
},
88+
"status": "400",
89+
"title": "Invalid request",
90+
"detail": "The request body is invalid"
91+
}
92+
]
93+
};
94+
return responseBody;
95+
};
96+
97+
export function patch500ErrorResponseBody (id: string) : ErrorMessageBody{
98+
let responseBody: ErrorMessageBody;
99+
responseBody = {
100+
errors: [
101+
{
102+
id: "12344",
103+
code: "NOTIFY_INTERNAL_SERVER_ERROR",
104+
links: {
105+
"about": "https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier"
106+
},
107+
status: "500",
108+
title: "Internal server error",
109+
detail: `Letter with id ${id} not found for supplier ${supplierId}`
110+
}
111+
]
112+
};
113+
return responseBody;
114+
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { test, expect } from '@playwright/test';
22
import { SUPPLIER_LETTERS, supplierId } from '../../constants/api_constants';
33
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
4-
import { 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';
@@ -68,6 +68,18 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
6868

6969
const res = await response.json();
7070
expect(response.status()).toBe(200);
71+
expect(res).toMatchObject({
72+
data:{
73+
attributes: {
74+
status: 'REJECTED',
75+
specificationId: letter.specificationId,
76+
groupId: letter.groupId,
77+
},
78+
id: letter.id,
79+
type: 'Letter'
80+
}
81+
});
82+
7183
await deleteLettersBySupplier(letter.id);
7284
});
7385

@@ -85,7 +97,8 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
8597
const res = await response.json();
8698

8799
expect(response.status()).toBe(400);
88-
});
100+
expect(res).toMatchObject(patch400ErrorResponseBody());
101+
});
89102

90103
test(`Patch /letters returns 500 if Id doesn't exist for SupplierId`, async ({ request }) => {
91104
const headers = patchRequestHeaders();
@@ -99,6 +112,7 @@ test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => {
99112

100113
const res = await response.json();
101114
expect(response.status()).toBe(500);
115+
expect(res).toMatchObject(patch500ErrorResponseBody(id));
102116
});
103117

104118
test(`Patch /letters returns 403 for invalid headers`, async ({ request }) => {

tests/constants/api_constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const SUPPLIER_LETTERS = 'letters';
2-
export const SUPPLIER_API_URL = 'https://internal-dev.api.service.nhs.uk/nhs-notify-supplier/';
32
export const SUPPLIER_API_URL_SANDBOX = 'https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier';
43
export const AWS_REGION = 'eu-west-2';
54

tests/constants/request_headers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface RequestSandBoxHeaders {
2121
[key: string]: string;
2222
}
2323

24-
export async function createInvalidRequestHeaders(): Promise<RequestHeaders> {
24+
export function createInvalidRequestHeaders(): RequestHeaders {
2525
let requestHeaders: RequestHeaders;
2626
requestHeaders = {
2727
headerauth1: '',
@@ -32,7 +32,7 @@ export async function createInvalidRequestHeaders(): Promise<RequestHeaders> {
3232
return requestHeaders;
3333
}
3434

35-
export async function createHeaderWithNoCorrelationId(): Promise<RequestHeaders> {
35+
export function createHeaderWithNoCorrelationId(): RequestHeaders {
3636
let requestHeaders: RequestHeaders;
3737
requestHeaders = {
3838
headerauth1: process.env.HEADERAUTH || '',
@@ -43,7 +43,7 @@ export async function createHeaderWithNoCorrelationId(): Promise<RequestHeaders>
4343
return requestHeaders;
4444
}
4545

46-
export async function createValidRequestHeaders(): Promise<RequestHeaders> {
46+
export function createValidRequestHeaders(): RequestHeaders{
4747
let requestHeaders: RequestHeaders;
4848
requestHeaders = {
4949
headerauth1: process.env.HEADERAUTH || '',

tests/helpers/awsGatewayHelper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ export async function getRestApiGatewayBaseUrl(): Promise<string> {
1111

1212
if (!api?.id) throw new Error(`API with name "${API_NAME}" not found.`);
1313

14-
const url = `https://${api.id}.execute-api.${region}.amazonaws.com/main`;
15-
return url;
14+
return `https://${api.id}.execute-api.${region}.amazonaws.com/main`;
1615
}

tests/sandbox/testCases/updateMultipleStatus_testCases.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export const apiSandboxMultipleLetterStatusTestData: ApiSandboxUpdateLetterStatu
109109
expectedStatus: 200
110110
},
111111
{
112-
testCase: '400 response if invalid request is passed',
112+
testCase: '404 response if invalid request is passed',
113113
header: sandBoxHeader,
114114
body:{
115115
data :

0 commit comments

Comments
 (0)