Skip to content

Commit 4b1a883

Browse files
comments for merge
1 parent d470154 commit 4b1a883

6 files changed

Lines changed: 347 additions & 30 deletions

File tree

scripts/utilities/letter-test-data/src/helpers/create_letter_helpers.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ export async function createLetter(params: {
1616
letterRepository: LetterRepository;
1717
}) {
1818
const {
19-
letterId,
2019
bucketName,
21-
supplierId,
22-
targetFilename,
23-
specificationId,
2420
groupId,
25-
status,
21+
letterId,
2622
letterRepository,
23+
specificationId,
24+
status,
25+
supplierId,
26+
targetFilename,
2727
} = params;
2828

2929
await uploadFile(
@@ -39,7 +39,7 @@ export async function createLetter(params: {
3939
specificationId,
4040
groupId,
4141
url: `s3://${bucketName}/${supplierId}/${targetFilename}`,
42-
status: status,
42+
status,
4343
createdAt: new Date().toISOString(),
4444
updatedAt: new Date().toISOString(),
4545
};
@@ -56,22 +56,16 @@ export function createLetterDto(params: {
5656
status: LetterStatusType;
5757
url: string;
5858
}) {
59-
const {
60-
letterId,
61-
supplierId,
62-
specificationId,
63-
groupId,
64-
status,
65-
url,
66-
} = params;
59+
const { groupId, letterId, specificationId, status, supplierId, url } =
60+
params;
6761

6862
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
6963
id: letterId,
7064
supplierId,
7165
specificationId,
7266
groupId,
73-
url: url,
74-
status: status,
67+
url,
68+
status,
7569
createdAt: new Date().toISOString(),
7670
updatedAt: new Date().toISOString(),
7771
};

test-results/.last-run.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"failedTests": [],
3+
"status": "passed"
4+
}
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import { RequestHeaders } from "../../../constants/request-headers";
2+
import { SUPPLIERID } from "../../../constants/api-constants";
3+
import {
4+
ErrorMessageBody,
5+
PostMessageRequestBody,
6+
} from "../../../helpers/common-types";
7+
import { SupplierApiLetters } from "../../../helpers/generate-fetch-test-data";
8+
9+
export type PostMessageResponseBody = {
10+
data: {
11+
type: string;
12+
id: string;
13+
attributes: {
14+
reasonCode?: string;
15+
reasonText?: string;
16+
status: string;
17+
specificationId: string;
18+
groupId?: string;
19+
};
20+
};
21+
};
22+
23+
export function postRequestHeaders(): RequestHeaders {
24+
let requestHeaders: RequestHeaders;
25+
requestHeaders = {
26+
"NHSD-Supplier-ID": SUPPLIERID,
27+
"NHSD-Correlation-ID": "12344",
28+
"X-Request-ID": "requestId1",
29+
};
30+
return requestHeaders;
31+
}
32+
33+
export function postInvalidRequestHeaders(): RequestHeaders {
34+
let requestHeaders: RequestHeaders;
35+
requestHeaders = {
36+
"NHSD-Supplier-ID": SUPPLIERID,
37+
"NHSD-Correlation-ID": "12344",
38+
// Request Id is missing
39+
};
40+
return requestHeaders;
41+
}
42+
43+
export function postValidRequestBody(
44+
letters: SupplierApiLetters[],
45+
): PostMessageRequestBody {
46+
let requestBody: PostMessageRequestBody;
47+
48+
requestBody = {
49+
data: [
50+
{
51+
type: "Letter",
52+
id: letters[0].id,
53+
attributes: {
54+
status: "ACCEPTED",
55+
},
56+
},
57+
{
58+
type: "Letter",
59+
id: letters[1].id,
60+
attributes: {
61+
status: "REJECTED",
62+
},
63+
},
64+
{
65+
type: "Letter",
66+
id: letters[2].id,
67+
attributes: {
68+
status: "PRINTED",
69+
},
70+
},
71+
{
72+
type: "Letter",
73+
id: letters[3].id,
74+
attributes: {
75+
status: "CANCELLED",
76+
},
77+
},
78+
],
79+
};
80+
return requestBody;
81+
}
82+
83+
export function postInvalidStatusRequestBody(
84+
letters: SupplierApiLetters[],
85+
): PostMessageRequestBody {
86+
let requestBody: PostMessageRequestBody;
87+
88+
requestBody = {
89+
data: [
90+
{
91+
type: "Letter",
92+
id: letters[0].id,
93+
attributes: {
94+
status: "ACCEPTED",
95+
},
96+
},
97+
{
98+
type: "Letter",
99+
id: letters[1].id,
100+
attributes: {
101+
status: "SENDING", // Invalid letter status
102+
},
103+
},
104+
],
105+
};
106+
return requestBody;
107+
}
108+
109+
export function postDuplicateIDRequestBody(
110+
letters: SupplierApiLetters[],
111+
): PostMessageRequestBody {
112+
let requestBody: PostMessageRequestBody;
113+
114+
requestBody = {
115+
data: [
116+
{
117+
type: "Letter",
118+
id: letters[0].id,
119+
attributes: {
120+
status: "ACCEPTED",
121+
},
122+
},
123+
{
124+
type: "Letter",
125+
id: letters[0].id, // Duplicate id
126+
attributes: {
127+
status: "REJECTED",
128+
},
129+
},
130+
],
131+
};
132+
return requestBody;
133+
}
134+
135+
export function postInvalidStatusResponseBody(): ErrorMessageBody {
136+
let responseBody: ErrorMessageBody;
137+
138+
responseBody = {
139+
errors: [
140+
{
141+
id: "12344",
142+
code: "NOTIFY_INVALID_REQUEST",
143+
links: {
144+
about:
145+
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
146+
},
147+
status: "400",
148+
title: "Invalid request",
149+
detail: "The request body is invalid",
150+
},
151+
],
152+
};
153+
return responseBody;
154+
}
155+
156+
export function postDuplicateIDResponseBody(): ErrorMessageBody {
157+
let responseBody: ErrorMessageBody;
158+
159+
responseBody = {
160+
errors: [
161+
{
162+
id: "12344",
163+
code: "NOTIFY_INVALID_REQUEST",
164+
links: {
165+
about:
166+
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
167+
},
168+
status: "400",
169+
title: "Invalid request",
170+
detail:
171+
"The request cannot include multiple letter objects with the same id",
172+
},
173+
],
174+
};
175+
return responseBody;
176+
}
177+
178+
export function post500ErrorResponseBody(): ErrorMessageBody {
179+
let responseBody: ErrorMessageBody;
180+
181+
responseBody = {
182+
errors: [
183+
{
184+
id: "12344",
185+
code: "NOTIFY_INTERNAL_SERVER_ERROR",
186+
links: {
187+
about:
188+
"https://digital.nhs.uk/developer/api-catalogue/nhs-notify-supplier",
189+
},
190+
status: "500",
191+
title: "Internal server error",
192+
detail: "Unexpected error",
193+
},
194+
],
195+
};
196+
return responseBody;
197+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import { expect, test } from "@playwright/test";
2+
import { SUPPLIERID, SUPPLIER_LETTERS } from "../../constants/api-constants";
3+
import getRestApiGatewayBaseUrl from "../../helpers/aws-gateway-helper";
4+
import {
5+
post500ErrorResponseBody,
6+
postDuplicateIDRequestBody,
7+
postDuplicateIDResponseBody,
8+
postInvalidRequestHeaders,
9+
postInvalidStatusRequestBody,
10+
postInvalidStatusResponseBody,
11+
postRequestHeaders,
12+
postValidRequestBody,
13+
} from "./testCases/update-multiple-letter-status";
14+
import {
15+
createTestData,
16+
getLettersBySupplier,
17+
} from "../../helpers/generate-fetch-test-data";
18+
19+
let baseUrl: string;
20+
21+
test.beforeAll(async () => {
22+
baseUrl = await getRestApiGatewayBaseUrl();
23+
});
24+
25+
test.describe("API Gateway Tests to Verify post Status Endpoint", () => {
26+
test(`post /letters returns 202 and status is updated for multiple letters`, async ({
27+
request,
28+
}) => {
29+
await createTestData(SUPPLIERID, 4);
30+
const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 4);
31+
32+
if (!letters?.length) {
33+
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
34+
return;
35+
}
36+
37+
const headers = postRequestHeaders();
38+
const body = postValidRequestBody(letters);
39+
40+
const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, {
41+
headers,
42+
data: body,
43+
});
44+
45+
expect(response.status()).toBe(202);
46+
});
47+
48+
test(`Post /letters returns 400 if request has invalid status`, async ({
49+
request,
50+
}) => {
51+
await createTestData(SUPPLIERID, 2);
52+
const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 2);
53+
54+
if (!letters?.length) {
55+
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
56+
return;
57+
}
58+
59+
const headers = postRequestHeaders();
60+
const body = postInvalidStatusRequestBody(letters);
61+
62+
const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, {
63+
headers,
64+
data: body,
65+
});
66+
67+
const responseBody = await response.json();
68+
69+
expect(response.status()).toBe(400);
70+
expect(responseBody).toMatchObject(postInvalidStatusResponseBody());
71+
});
72+
73+
test(`Post /letters returns 400 if request has duplicate id`, async ({
74+
request,
75+
}) => {
76+
await createTestData(SUPPLIERID, 2);
77+
const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 2);
78+
79+
if (!letters?.length) {
80+
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
81+
return;
82+
}
83+
84+
const headers = postRequestHeaders();
85+
const body = postDuplicateIDRequestBody(letters);
86+
87+
const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, {
88+
headers,
89+
data: body,
90+
});
91+
92+
const responseBody = await response.json();
93+
94+
expect(response.status()).toBe(400);
95+
expect(responseBody).toMatchObject(postDuplicateIDResponseBody());
96+
});
97+
98+
test(`Post /letters returns 500 if request has invalid header`, async ({
99+
request,
100+
}) => {
101+
await createTestData(SUPPLIERID, 4);
102+
const letters = await getLettersBySupplier(SUPPLIERID, "PENDING", 4);
103+
104+
if (!letters?.length) {
105+
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
106+
return;
107+
}
108+
109+
const headers = postInvalidRequestHeaders();
110+
const body = postValidRequestBody(letters);
111+
112+
const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, {
113+
headers,
114+
data: body,
115+
});
116+
117+
const responseBody = await response.json();
118+
119+
expect(response.status()).toBe(500);
120+
expect(responseBody).toMatchObject(post500ErrorResponseBody());
121+
});
122+
});

tests/helpers/common-types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
export type PostMessageRequestBody = {
2+
data: PostRequest[];
3+
};
4+
5+
type PostRequest = {
6+
type: string;
7+
id: string;
8+
attributes: {
9+
reasonCode?: string;
10+
reasonText?: string;
11+
status: string;
12+
};
13+
};
114

215
export type ErrorLink = {
316
about: string;

0 commit comments

Comments
 (0)