-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsupplier-allocation.spec.ts
More file actions
124 lines (106 loc) · 4.46 KB
/
Copy pathsupplier-allocation.spec.ts
File metadata and controls
124 lines (106 loc) · 4.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { expect, test } from "@playwright/test";
import {
getTotalAllocationForVolumeGroup,
getTotalDailyAllocation,
} from "tests/helpers/supplier-quotas-helper";
import {
pollSupplierAllocatorForAllocationDetails,
supplierIdFromSupplierAllocatorLog,
} from "tests/helpers/aws-cloudwatch-helper";
import { logger } from "tests/helpers/pino-logger";
import { format } from "date-fns";
import { toZonedTime } from "date-fns-tz";
import { randomUUID } from "node:crypto";
import { createPreparedV1Event } from "tests/helpers/event-fixtures";
import { sendSnsBatchEvent } from "tests/helpers/send-sns-event";
test.describe("Supplier Allocation Tests", () => {
test("Verify that successful supplier allocation emits a PENDING event for the allocated supplier", async () => {
test.setTimeout(180_000); // 3 minutes for long running polling
const domainId = randomUUID();
logger.info(`Testing supplier allocation with domainId: ${domainId}`);
const preparedEvent = createPreparedV1Event({ domainId });
const response = await sendSnsBatchEvent([
{ id: preparedEvent.id, message: preparedEvent },
]);
expect(response.Successful).toHaveLength(1);
// poll supplier allocator to check if supplier has been allocated
const allocationDetails =
await pollSupplierAllocatorForAllocationDetails(domainId);
const supplierId = allocationDetails?.supplierSpec?.supplierId;
const status = allocationDetails?.allocationStatus?.status;
expect(supplierId).toBeTruthy();
expect(status).toBe("PENDING");
logger.info(
`Supplier ${supplierId} allocated with status ${status} for domainId ${domainId} in supplier allocator lambda`,
);
});
test("Verify that supplier allocator emits a rejected request for an unknown letter variant", async () => {
test.setTimeout(180_000); // 3 minutes for long running polling
const domainId = randomUUID();
logger.info(
`Testing supplier allocation with unknown letter variant for domainId: ${domainId}`,
);
const preparedEvent = createPreparedV1Event({
domainId,
letterVariantId: "unknown-letter-variant",
});
const response = await sendSnsBatchEvent([
{ id: preparedEvent.id, message: preparedEvent },
]);
expect(response.Successful).toHaveLength(1);
const allocationDetails =
await pollSupplierAllocatorForAllocationDetails(domainId);
const supplierId = allocationDetails?.supplierSpec?.supplierId;
const status = allocationDetails?.allocationStatus?.status;
expect(supplierId).toBe("unknown");
expect(status).toBe("REJECTED");
});
test("Verify that supplier allocations are correctly updated only once for a volume group for multiple messages", async () => {
test.setTimeout(180_000);
const volumeGroupId = "volumeGroup-test1";
const originalTotalAllocation =
await getTotalAllocationForVolumeGroup(volumeGroupId);
logger.info(
`Total allocation for volume group ${volumeGroupId}: ${originalTotalAllocation}`,
);
const allocationDate = format(
toZonedTime(new Date(), "Europe/London"),
"yyyy-MM-dd",
);
const originalTotalDailyAllocation =
await getTotalDailyAllocation(allocationDate);
logger.info(
`Total daily allocation for date ${allocationDate}: ${originalTotalDailyAllocation}`,
);
// Create 2 messages with same domain id
const domainId = randomUUID();
const message1 = createPreparedV1Event({
domainId,
letterVariantId: "notify-standard-test1",
});
const message2 = createPreparedV1Event({
domainId,
letterVariantId: "notify-standard-test1",
});
const eventBatch = [message1, message2];
const response = await sendSnsBatchEvent(
eventBatch.map((event) => ({ id: event.id, message: event })),
);
expect(response.Successful).toHaveLength(eventBatch.length);
await supplierIdFromSupplierAllocatorLog(domainId);
const newTotalAllocation =
await getTotalAllocationForVolumeGroup(volumeGroupId);
logger.info(
`New total allocation for volume group ${volumeGroupId}: ${newTotalAllocation}`,
);
expect(newTotalAllocation).toBe(originalTotalAllocation + 1);
const newTotalDailyAllocation =
await getTotalDailyAllocation(allocationDate);
logger.info(
`New total daily allocation for date ${allocationDate}: ${newTotalDailyAllocation}`,
);
expect(newTotalDailyAllocation).toBeGreaterThanOrEqual(
originalTotalDailyAllocation + 1,
);
});
});