Skip to content

Commit 51cd442

Browse files
component tests
1 parent 363e664 commit 51cd442

4 files changed

Lines changed: 72 additions & 1 deletion

File tree

lambdas/supplier-allocator/src/handler/allocate-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
selectSupplierByFactor,
3030
suppliersWithValidPack,
3131
} from "./allocation-config";
32-
3332
import { Deps } from "../config/deps";
3433
import { PreparedEventSchema, PreparedEvents, SupplierDetails } from "./types";
3534

@@ -136,6 +135,7 @@ async function getSupplierFromConfig(
136135

137136
deps.logger.info({
138137
description: "Fetched supplier details for supplier allocations",
138+
domainId: letterEvent.data.domainId,
139139
variantId: letterEvent.data.letterVariantId,
140140
volumeGroupId: volumeGroup.id,
141141
supplierAllocationIds: supplierAllocations.map((a) => a.id),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { randomUUID } from "node:crypto";
2+
import { expect, test } from "@playwright/test";
3+
import {
4+
FetchedSupplierLog,
5+
getAllocationDetailsForDomainId,
6+
getVariantsForAllocation,
7+
} from "tests/helpers/allocation-helper";
8+
9+
import { createPreparedV1Event } from "tests/helpers/event-fixtures";
10+
import { sendSnsEvent } from "tests/helpers/send-sns-event";
11+
12+
test.describe("Letter Variant Tests", () => {
13+
test.setTimeout(180_000); // 3 minutes for long running polling
14+
15+
test("Verify that supplierId on letter variant takes pecedence over volume group", async () => {
16+
const letterVariant = getVariantsForAllocation(3);
17+
const domainId = randomUUID();
18+
const preparedEvent = createPreparedV1Event({
19+
domainId,
20+
letterVariantId: letterVariant,
21+
});
22+
23+
const response = await sendSnsEvent(preparedEvent);
24+
25+
expect(response.MessageId).toBeTruthy();
26+
27+
const allocationDetails: FetchedSupplierLog =
28+
await getAllocationDetailsForDomainId(domainId);
29+
30+
expect(allocationDetails.allocatedSuppliers).toHaveLength(1);
31+
32+
const allocatedSupplierId = allocationDetails.allocatedSuppliers?.[0]?.id;
33+
expect(allocatedSupplierId).toBe("supplier1");
34+
});
35+
});

tests/helpers/allocation-helper.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { envName } from "tests/constants/api-constants";
1010
import {
1111
pollAllocatorLogWithOptions,
12+
pollSupplierAllocatorLogForAllocationDetails,
1213
pollSupplierAllocatorLogForExceededDailyCapacity,
1314
pollSupplierAllocatorLogForResolvedSpec,
1415
} from "./aws-cloudwatch-helper";
@@ -83,6 +84,22 @@ export type AllocationLogOptions = {
8384
extraPatterns?: string[];
8485
};
8586

87+
export type AllocatedSuppliersLogEntry = {
88+
id: string;
89+
name: string;
90+
channelType: string;
91+
dailyCapacity: number;
92+
status: string;
93+
};
94+
95+
export type FetchedSupplierLog = {
96+
supplierAllocationIds?: string[];
97+
allocatedSuppliers?: AllocatedSuppliersLogEntry[];
98+
allSuppliersForPack?: string[];
99+
supplierForPackWithCapacity?: string[];
100+
selectedSupplierId?: string;
101+
};
102+
86103
type LetterVariantConfig = {
87104
id: string;
88105
packSpecificationIds: string[];
@@ -137,6 +154,15 @@ export async function getAllocationLogForDomainId(
137154
return supplierAllocatorLog;
138155
}
139156

157+
export async function getAllocationDetailsForDomainId(
158+
domainId: string,
159+
): Promise<FetchedSupplierLog> {
160+
const message = await pollSupplierAllocatorLogForAllocationDetails(domainId);
161+
const fetchedSupplierLog = JSON.parse(message) as FetchedSupplierLog;
162+
163+
return fetchedSupplierLog;
164+
}
165+
140166
export async function getAllocationLog<
141167
TLog extends { description: string } = PackSpecificationLog,
142168
>(description: string, options?: AllocationLogOptions): Promise<TLog> {

tests/helpers/aws-cloudwatch-helper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ export async function pollSupplierAllocatorLogForResolvedSpec(
6060
`"${domainId}"`,
6161
]);
6262
}
63+
64+
export async function pollSupplierAllocatorLogForAllocationDetails(
65+
domainId: string,
66+
): Promise<string> {
67+
return pollLambdaLog("supplier-allocator", [
68+
'"Fetched supplier details for supplier allocations"',
69+
`"${domainId}"`,
70+
]);
71+
}
72+
6373
export async function pollSupplierAllocatorLogForError(
6474
msgToCheck: string,
6575
domainId?: string,

0 commit comments

Comments
 (0)