Skip to content

Commit 75ae0c5

Browse files
Add wait status to post tests
1 parent bfb41a4 commit 75ae0c5

2 files changed

Lines changed: 48 additions & 35 deletions

File tree

tests/component-tests/apiGateway-tests/testCases/update-multiple-letter-status.ts

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import {
66
} from "../../../helpers/common-types";
77
import { SupplierApiLetters } from "../../../helpers/generate-fetch-test-data";
88

9+
export interface LetterUpdateAttributes {
10+
status: string;
11+
reasonCode?: string;
12+
reasonText?: string;
13+
}
14+
15+
export type LetterUpdatesById = Record<string, LetterUpdateAttributes>;
16+
917
export function postLettersRequestHeaders(): RequestHeaders {
1018
return {
1119
"NHSD-Supplier-ID": SUPPLIERID,
@@ -23,41 +31,14 @@ export function postLettersInvalidRequestHeaders(): RequestHeaders {
2331
}
2432

2533
export function postValidRequestBody(
26-
letters: SupplierApiLetters[],
34+
updatesById: LetterUpdatesById,
2735
): PostMessageRequestBody {
2836
return {
29-
data: [
30-
{
31-
type: "Letter",
32-
id: letters[0].id,
33-
attributes: {
34-
status: "ACCEPTED",
35-
},
36-
},
37-
{
38-
type: "Letter",
39-
id: letters[1].id,
40-
attributes: {
41-
status: "REJECTED",
42-
reasonCode: "R01",
43-
reasonText: "Test Reason",
44-
},
45-
},
46-
{
47-
type: "Letter",
48-
id: letters[2].id,
49-
attributes: {
50-
status: "PRINTED",
51-
},
52-
},
53-
{
54-
type: "Letter",
55-
id: letters[3].id,
56-
attributes: {
57-
status: "CANCELLED",
58-
},
59-
},
60-
],
37+
data: Object.entries(updatesById).map(([id, attributes]) => ({
38+
type: "Letter",
39+
id,
40+
attributes,
41+
})),
6142
};
6243
}
6344

tests/component-tests/apiGateway-tests/update-multiple-letter-status.spec.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import {
1515
createTestData,
1616
getLettersBySupplier,
17+
waitForLetterStatus,
1718
} from "../../helpers/generate-fetch-test-data";
1819

1920
let baseUrl: string;
@@ -35,14 +36,36 @@ test.describe("API Gateway Tests to Verify post Status Endpoint", () => {
3536
}
3637

3738
const headers = postLettersRequestHeaders();
38-
const body = postValidRequestBody(letters);
39+
const updatesById = {
40+
[letters[0].id]: { status: "ACCEPTED" },
41+
[letters[1].id]: {
42+
status: "REJECTED",
43+
reasonCode: "R01",
44+
reasonText: "Test Reason",
45+
},
46+
[letters[2].id]: { status: "PRINTED" },
47+
[letters[3].id]: { status: "CANCELLED" },
48+
};
49+
50+
const body = postValidRequestBody(updatesById);
3951

4052
const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, {
4153
headers,
4254
data: body,
4355
});
4456

4557
expect(response.status()).toBe(202);
58+
59+
await Promise.all(
60+
Object.entries(updatesById).map(async ([id, attributes]) => {
61+
const letter = await waitForLetterStatus(
62+
SUPPLIERID,
63+
id,
64+
attributes.status,
65+
);
66+
expect(letter.status).toBe(attributes.status);
67+
}),
68+
);
4669
});
4770

4871
test(`Post /letters returns 400 if request has invalid status`, async ({
@@ -107,7 +130,16 @@ test.describe("API Gateway Tests to Verify post Status Endpoint", () => {
107130
}
108131

109132
const headers = postLettersInvalidRequestHeaders();
110-
const body = postValidRequestBody(letters);
133+
const body = postValidRequestBody({
134+
[letters[0].id]: { status: "ACCEPTED" },
135+
[letters[1].id]: {
136+
status: "REJECTED",
137+
reasonCode: "R01",
138+
reasonText: "Test Reason",
139+
},
140+
[letters[2].id]: { status: "PRINTED" },
141+
[letters[3].id]: { status: "CANCELLED" },
142+
});
111143

112144
const response = await request.post(`${baseUrl}/${SUPPLIER_LETTERS}`, {
113145
headers,

0 commit comments

Comments
 (0)