Skip to content

Commit 1086bb7

Browse files
CCM-20032: Letter Variant SupplierId Not Honoured
1 parent a714c75 commit 1086bb7

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ describe("eligibleSuppliers", () => {
196196
"Supplier service error",
197197
);
198198
});
199+
it("should filter allocations by letterVariantSupplierId if provided", async () => {
200+
(
201+
supplierConfigService.getSupplierAllocationsForVolumeGroup as jest.Mock
202+
).mockResolvedValue(mockSupplierAllocations);
203+
(supplierConfigService.getSupplierDetails as jest.Mock).mockResolvedValue(
204+
mockSuppliers,
205+
);
206+
207+
const letterVariantSupplierId = "supplier-1";
208+
await eligibleSuppliers(mockVolumeGroup, mockDeps, letterVariantSupplierId);
209+
expect(supplierConfigService.getSupplierDetails).toHaveBeenCalledWith(
210+
["supplier-1"],
211+
mockDeps,
212+
);
213+
});
214+
it("should log a warning if no allocations found for specified letter variant supplier", async () => {
215+
(
216+
supplierConfigService.getSupplierAllocationsForVolumeGroup as jest.Mock
217+
).mockResolvedValue([]);
218+
(supplierConfigService.getSupplierDetails as jest.Mock).mockResolvedValue(
219+
[],
220+
);
221+
222+
const letterVariantSupplierId = "supplier-1";
223+
await eligibleSuppliers(mockVolumeGroup, mockDeps, letterVariantSupplierId);
224+
expect(mockDeps.logger.warn).toHaveBeenCalledWith({
225+
description: "No allocations found for specified letter variant supplier",
226+
volumeGroupId: mockVolumeGroup.id,
227+
letterVariantSupplierId,
228+
});
229+
});
199230
});
200231

201232
describe("preferredSupplierPack", () => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async function getSupplierFromConfig(
9494
);
9595

9696
const { supplierAllocations, suppliers: allocatedSuppliers } =
97-
await eligibleSuppliers(volumeGroup, deps);
97+
await eligibleSuppliers(volumeGroup, deps, letterVariant.supplierId);
9898

9999
const preferredPack: PackSpecification = await preferredSupplierPack(
100100
letterEvent,
@@ -391,6 +391,9 @@ export default function createSupplierAllocatorHandler(deps: Deps): SQSHandler {
391391

392392
({ priority, supplier } = supplierAllocationResult);
393393
} catch (error) {
394+
console.log(
395+
`Error processing allocation of record ${record.messageId}: ${error}`,
396+
);
394397
deps.logger.error({
395398
description: "Error processing allocation of record",
396399
err: error,

lambdas/supplier-allocator/src/handler/allocation-config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { PreparedEvents } from "./types";
2323
export async function eligibleSuppliers(
2424
volumeGroup: VolumeGroup,
2525
deps: Deps,
26+
letterVariantSupplierId?: string,
2627
): Promise<{
2728
supplierAllocations: SupplierAllocation[];
2829
suppliers: Supplier[];
@@ -31,6 +32,32 @@ export async function eligibleSuppliers(
3132
volumeGroup.id,
3233
deps,
3334
);
35+
if (letterVariantSupplierId) {
36+
deps.logger.info({
37+
description: "Filtering allocations for letter variant supplier",
38+
volumeGroupId: volumeGroup.id,
39+
letterVariantSupplierId,
40+
});
41+
const filteredAllocations = supplierAllocations.filter(
42+
(alloc) => alloc.supplier === letterVariantSupplierId,
43+
);
44+
if (filteredAllocations.length === 0) {
45+
deps.logger.warn({
46+
description:
47+
"No allocations found for specified letter variant supplier",
48+
volumeGroupId: volumeGroup.id,
49+
letterVariantSupplierId,
50+
});
51+
}
52+
return {
53+
supplierAllocations: filteredAllocations,
54+
suppliers: await getSupplierDetails(
55+
filteredAllocations.map((alloc) => alloc.supplier),
56+
deps,
57+
),
58+
};
59+
}
60+
3461
const allocationPercentageSum = supplierAllocations.reduce(
3562
(sum, alloc) => sum + alloc.allocationPercentage,
3663
0,

0 commit comments

Comments
 (0)