-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathurgent-letter-priority.spec.ts
More file actions
72 lines (58 loc) · 2.48 KB
/
Copy pathurgent-letter-priority.spec.ts
File metadata and controls
72 lines (58 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { expect, test } from "@playwright/test";
import getRestApiGatewayBaseUrl from "tests/helpers/aws-gateway-helper";
import { pollForLetterStatus } from "tests/helpers/poll-for-letters-helper";
import { getLettersFromQueueViaIndex } from "tests/helpers/generate-fetch-test-data";
import {
getVariantsWithUrgency,
sendEventsForVariants,
supplier,
verifyAllocationLogsContainPriority,
verifyIndexPositionOfLetterVariants,
} from "tests/helpers/urgent-letter-priority-helper";
import { createValidRequestHeaders } from "tests/constants/request-headers";
import { SUPPLIER_LETTERS } from "tests/constants/api-constants";
import {
GetLettersResponse,
GetLettersResponseSchema,
} from "../../../lambdas/api-handler/src/contracts/letters";
let baseUrl: string;
test.beforeAll(async () => {
baseUrl = await getRestApiGatewayBaseUrl();
});
test.describe("Urgent Letter Priority Tests", () => {
test.setTimeout(180_000); // 3 minutes for long running polling
test("Letters with higher urgency get picked first", async ({ request }) => {
const variantsUrgencyTen = getVariantsWithUrgency(10);
const urgencyTenLetterIds = await sendEventsForVariants(variantsUrgencyTen);
const variantsUrgencyNine = getVariantsWithUrgency(9);
const urgencyNineLetterIds =
await sendEventsForVariants(variantsUrgencyNine);
await Promise.all(
[...urgencyNineLetterIds, ...urgencyTenLetterIds].map(async (domainId) =>
pollForLetterStatus(request, supplier, domainId, baseUrl),
),
);
await verifyAllocationLogsContainPriority(urgencyNineLetterIds, 9);
await verifyAllocationLogsContainPriority(urgencyTenLetterIds, 10);
const lettersFromQueue = await getLettersFromQueueViaIndex(supplier);
const letterIdsFromQueue = lettersFromQueue.map(
(letter) => letter.letterId,
);
const header = createValidRequestHeaders(supplier);
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}`, {
headers: header,
});
expect(response.status()).toBe(200);
const responseBody = await response.json();
expect(responseBody.data.length).toBeGreaterThanOrEqual(1);
const getLettersResponse: GetLettersResponse =
GetLettersResponseSchema.parse(responseBody);
const letterIds = getLettersResponse.data.map((letter) => letter.id);
expect(letterIds).toEqual(letterIdsFromQueue);
verifyIndexPositionOfLetterVariants(
letterIdsFromQueue,
urgencyTenLetterIds,
urgencyNineLetterIds,
);
});
});