From de5a5dca605140c1551fb35284f44a1bd231e77f Mon Sep 17 00:00:00 2001 From: David Wass Date: Thu, 25 Jun 2026 10:35:53 +0100 Subject: [PATCH 1/7] CCM-20032: Letter Variant SupplierId Not Honoured --- .../__tests__/allocation-config.test.ts | 31 +++++++++++++++++++ .../src/handler/allocate-handler.ts | 5 ++- .../src/handler/allocation-config.ts | 27 ++++++++++++++++ .../supplier-allocation.spec.ts | 4 ++- 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts b/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts index 17ce944a5..87b58584f 100644 --- a/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts +++ b/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts @@ -196,6 +196,37 @@ describe("eligibleSuppliers", () => { "Supplier service error", ); }); + it("should filter allocations by letterVariantSupplierId if provided", async () => { + ( + supplierConfigService.getSupplierAllocationsForVolumeGroup as jest.Mock + ).mockResolvedValue(mockSupplierAllocations); + (supplierConfigService.getSupplierDetails as jest.Mock).mockResolvedValue( + mockSuppliers, + ); + + const letterVariantSupplierId = "supplier-1"; + await eligibleSuppliers(mockVolumeGroup, mockDeps, letterVariantSupplierId); + expect(supplierConfigService.getSupplierDetails).toHaveBeenCalledWith( + ["supplier-1"], + mockDeps, + ); + }); + it("should log a warning if no allocations found for specified letter variant supplier", async () => { + ( + supplierConfigService.getSupplierAllocationsForVolumeGroup as jest.Mock + ).mockResolvedValue([]); + (supplierConfigService.getSupplierDetails as jest.Mock).mockResolvedValue( + [], + ); + + const letterVariantSupplierId = "supplier-1"; + await eligibleSuppliers(mockVolumeGroup, mockDeps, letterVariantSupplierId); + expect(mockDeps.logger.warn).toHaveBeenCalledWith({ + description: "No allocations found for specified letter variant supplier", + volumeGroupId: mockVolumeGroup.id, + letterVariantSupplierId, + }); + }); }); describe("preferredSupplierPack", () => { diff --git a/lambdas/supplier-allocator/src/handler/allocate-handler.ts b/lambdas/supplier-allocator/src/handler/allocate-handler.ts index 397a53abe..fc8cd4692 100644 --- a/lambdas/supplier-allocator/src/handler/allocate-handler.ts +++ b/lambdas/supplier-allocator/src/handler/allocate-handler.ts @@ -94,7 +94,7 @@ async function getSupplierFromConfig( ); const { supplierAllocations, suppliers: allocatedSuppliers } = - await eligibleSuppliers(volumeGroup, deps); + await eligibleSuppliers(volumeGroup, deps, letterVariant.supplierId); const preferredPack: PackSpecification = await preferredSupplierPack( letterEvent, @@ -391,6 +391,9 @@ export default function createSupplierAllocatorHandler(deps: Deps): SQSHandler { ({ priority, supplier } = supplierAllocationResult); } catch (error) { + console.log( + `Error processing allocation of record ${record.messageId}: ${error}`, + ); deps.logger.error({ description: "Error processing allocation of record", err: error, diff --git a/lambdas/supplier-allocator/src/handler/allocation-config.ts b/lambdas/supplier-allocator/src/handler/allocation-config.ts index f029b619a..f912fe0ec 100644 --- a/lambdas/supplier-allocator/src/handler/allocation-config.ts +++ b/lambdas/supplier-allocator/src/handler/allocation-config.ts @@ -23,6 +23,7 @@ import { PreparedEvents } from "./types"; export async function eligibleSuppliers( volumeGroup: VolumeGroup, deps: Deps, + letterVariantSupplierId?: string, ): Promise<{ supplierAllocations: SupplierAllocation[]; suppliers: Supplier[]; @@ -31,6 +32,32 @@ export async function eligibleSuppliers( volumeGroup.id, deps, ); + if (letterVariantSupplierId) { + deps.logger.info({ + description: "Filtering allocations for letter variant supplier", + volumeGroupId: volumeGroup.id, + letterVariantSupplierId, + }); + const filteredAllocations = supplierAllocations.filter( + (alloc) => alloc.supplier === letterVariantSupplierId, + ); + if (filteredAllocations.length === 0) { + deps.logger.warn({ + description: + "No allocations found for specified letter variant supplier", + volumeGroupId: volumeGroup.id, + letterVariantSupplierId, + }); + } + return { + supplierAllocations: filteredAllocations, + suppliers: await getSupplierDetails( + filteredAllocations.map((alloc) => alloc.supplier), + deps, + ), + }; + } + const allocationPercentageSum = supplierAllocations.reduce( (sum, alloc) => sum + alloc.allocationPercentage, 0, diff --git a/tests/component-tests/allocation-tests/supplier-allocation.spec.ts b/tests/component-tests/allocation-tests/supplier-allocation.spec.ts index d33a6cc7c..fc1f03c27 100644 --- a/tests/component-tests/allocation-tests/supplier-allocation.spec.ts +++ b/tests/component-tests/allocation-tests/supplier-allocation.spec.ts @@ -117,6 +117,8 @@ test.describe("Supplier Allocation Tests", () => { logger.info( `New total daily allocation for date ${allocationDate}: ${newTotalDailyAllocation}`, ); - expect(newTotalDailyAllocation).toBe(originalTotalDailyAllocation + 1); + expect(newTotalDailyAllocation).toBeGreaterThanOrEqual( + originalTotalDailyAllocation + 1, + ); }); }); From 4ae60cb280ebc80c920abee2a2af312fbbc206cf Mon Sep 17 00:00:00 2001 From: David Wass Date: Thu, 25 Jun 2026 15:17:34 +0100 Subject: [PATCH 2/7] add supplierId to notify-standard-colour --- config/suppliers/letter-variant/notify-standard-colour.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/suppliers/letter-variant/notify-standard-colour.json b/config/suppliers/letter-variant/notify-standard-colour.json index 772a4146c..056e56f67 100644 --- a/config/suppliers/letter-variant/notify-standard-colour.json +++ b/config/suppliers/letter-variant/notify-standard-colour.json @@ -29,6 +29,7 @@ ], "priority": 99, "status": "INT", + "supplierId": "supplier1", "type": "STANDARD", - "volumeGroupId": "volumeGroup-test3" + "volumeGroupId": "volumeGroup-test1" } From 6fba14860f7b09598dceb544e2b4c8ba31f649b0 Mon Sep 17 00:00:00 2001 From: David Wass Date: Thu, 25 Jun 2026 16:13:11 +0100 Subject: [PATCH 3/7] CCM-20188: Give delete item permission to idempotency --- .../api/module_lambda_upsert_letter.tf | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/infrastructure/terraform/components/api/module_lambda_upsert_letter.tf b/infrastructure/terraform/components/api/module_lambda_upsert_letter.tf index 7519d1556..eeaed3420 100644 --- a/infrastructure/terraform/components/api/module_lambda_upsert_letter.tf +++ b/infrastructure/terraform/components/api/module_lambda_upsert_letter.tf @@ -67,11 +67,26 @@ data "aws_iam_policy_document" "upsert_letter_lambda" { resources = [ aws_dynamodb_table.letters.arn, - aws_dynamodb_table.idempotency.arn, "${aws_dynamodb_table.letters.arn}/index/supplierStatus-index" ] } + statement { + sid = "AllowIdempotencyTableWrite" + effect = "Allow" + + actions = [ + "dynamodb:PutItem", + "dynamodb:GetItem", + "dynamodb:UpdateItem", + "dynamodb:DeleteItem" + ] + + resources = [ + aws_dynamodb_table.idempotency.arn, + ] + } + statement { sid = "AllowSQSRead" effect = "Allow" From 0d10e90cc9d5c68e234691d454aa99b31ac24df1 Mon Sep 17 00:00:00 2001 From: David Wass Date: Tue, 30 Jun 2026 09:46:42 +0100 Subject: [PATCH 4/7] component tests --- .../src/handler/allocate-handler.ts | 2 +- .../allocation-letter-variant.spec.ts | 35 +++++++++++++++++++ tests/helpers/allocation-helper.ts | 26 ++++++++++++++ tests/helpers/aws-cloudwatch-helper.ts | 10 ++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts diff --git a/lambdas/supplier-allocator/src/handler/allocate-handler.ts b/lambdas/supplier-allocator/src/handler/allocate-handler.ts index fc8cd4692..326f20bb2 100644 --- a/lambdas/supplier-allocator/src/handler/allocate-handler.ts +++ b/lambdas/supplier-allocator/src/handler/allocate-handler.ts @@ -29,7 +29,6 @@ import { selectSupplierByFactor, suppliersWithValidPack, } from "./allocation-config"; - import { Deps } from "../config/deps"; import { PreparedEventSchema, PreparedEvents, SupplierDetails } from "./types"; @@ -136,6 +135,7 @@ async function getSupplierFromConfig( deps.logger.info({ description: "Fetched supplier details for supplier allocations", + domainId: letterEvent.data.domainId, variantId: letterEvent.data.letterVariantId, volumeGroupId: volumeGroup.id, supplierAllocationIds: supplierAllocations.map((a) => a.id), diff --git a/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts b/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts new file mode 100644 index 000000000..880fc543d --- /dev/null +++ b/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts @@ -0,0 +1,35 @@ +import { randomUUID } from "node:crypto"; +import { expect, test } from "@playwright/test"; +import { + FetchedSupplierLog, + getAllocationDetailsForDomainId, + getVariantsForAllocation, +} from "tests/helpers/allocation-helper"; + +import { createPreparedV1Event } from "tests/helpers/event-fixtures"; +import { sendSnsEvent } from "tests/helpers/send-sns-event"; + +test.describe("Letter Variant Tests", () => { + test.setTimeout(180_000); // 3 minutes for long running polling + + test("Verify that supplierId on letter variant takes pecedence over volume group", async () => { + const letterVariant = getVariantsForAllocation(3); + const domainId = randomUUID(); + const preparedEvent = createPreparedV1Event({ + domainId, + letterVariantId: letterVariant, + }); + + const response = await sendSnsEvent(preparedEvent); + + expect(response.MessageId).toBeTruthy(); + + const allocationDetails: FetchedSupplierLog = + await getAllocationDetailsForDomainId(domainId); + + expect(allocationDetails.allocatedSuppliers).toHaveLength(1); + + const allocatedSupplierId = allocationDetails.allocatedSuppliers?.[0]?.id; + expect(allocatedSupplierId).toBe("supplier1"); + }); +}); diff --git a/tests/helpers/allocation-helper.ts b/tests/helpers/allocation-helper.ts index bed146780..e73ccb1fc 100644 --- a/tests/helpers/allocation-helper.ts +++ b/tests/helpers/allocation-helper.ts @@ -9,6 +9,7 @@ import { import { envName } from "tests/constants/api-constants"; import { pollAllocatorLogWithOptions, + pollSupplierAllocatorLogForAllocationDetails, pollSupplierAllocatorLogForExceededDailyCapacity, pollSupplierAllocatorLogForResolvedSpec, } from "./aws-cloudwatch-helper"; @@ -83,6 +84,22 @@ export type AllocationLogOptions = { extraPatterns?: string[]; }; +export type AllocatedSuppliersLogEntry = { + id: string; + name: string; + channelType: string; + dailyCapacity: number; + status: string; +}; + +export type FetchedSupplierLog = { + supplierAllocationIds?: string[]; + allocatedSuppliers?: AllocatedSuppliersLogEntry[]; + allSuppliersForPack?: string[]; + supplierForPackWithCapacity?: string[]; + selectedSupplierId?: string; +}; + type LetterVariantConfig = { id: string; packSpecificationIds: string[]; @@ -137,6 +154,15 @@ export async function getAllocationLogForDomainId( return supplierAllocatorLog; } +export async function getAllocationDetailsForDomainId( + domainId: string, +): Promise { + const message = await pollSupplierAllocatorLogForAllocationDetails(domainId); + const fetchedSupplierLog = JSON.parse(message) as FetchedSupplierLog; + + return fetchedSupplierLog; +} + export async function getAllocationLog< TLog extends { description: string } = PackSpecificationLog, >(description: string, options?: AllocationLogOptions): Promise { diff --git a/tests/helpers/aws-cloudwatch-helper.ts b/tests/helpers/aws-cloudwatch-helper.ts index af9c56553..c31d0933b 100644 --- a/tests/helpers/aws-cloudwatch-helper.ts +++ b/tests/helpers/aws-cloudwatch-helper.ts @@ -60,6 +60,16 @@ export async function pollSupplierAllocatorLogForResolvedSpec( `"${domainId}"`, ]); } + +export async function pollSupplierAllocatorLogForAllocationDetails( + domainId: string, +): Promise { + return pollLambdaLog("supplier-allocator", [ + '"Fetched supplier details for supplier allocations"', + `"${domainId}"`, + ]); +} + export async function pollSupplierAllocatorLogForError( msgToCheck: string, domainId?: string, From 9d8519d196792bfe71d7ff2a85585a2dd06c63a8 Mon Sep 17 00:00:00 2001 From: David Wass Date: Tue, 30 Jun 2026 11:21:52 +0100 Subject: [PATCH 5/7] config integrity --- config/suppliers/letter-variant/client3-colour-admail.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/suppliers/letter-variant/client3-colour-admail.json b/config/suppliers/letter-variant/client3-colour-admail.json index 4d05b6272..2cd385c2b 100644 --- a/config/suppliers/letter-variant/client3-colour-admail.json +++ b/config/suppliers/letter-variant/client3-colour-admail.json @@ -26,7 +26,7 @@ "id": "client3-colour-admail", "name": "Client 3 Colour Admail", "packSpecificationIds": [ - "notify-admail-colour-whitemail" + "notify-admail-whitemail" ], "priority": 50, "status": "INT", From 1e2e2e36bcb2ab340fec3280442265bb9d775618 Mon Sep 17 00:00:00 2001 From: David Wass Date: Tue, 30 Jun 2026 12:03:53 +0100 Subject: [PATCH 6/7] add domainid to flakey tests --- .../__tests__/allocate-handler.test.ts | 1 + .../__tests__/allocation-config.test.ts | 30 +++++++++++++++++-- .../src/handler/allocate-handler.ts | 2 ++ .../src/handler/allocation-config.ts | 2 ++ .../src/services/supplier-config.ts | 1 + .../letter-allocation-capacity.spec.ts | 1 + .../letter-allocation-weighting.spec.ts | 1 + 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/lambdas/supplier-allocator/src/handler/__tests__/allocate-handler.test.ts b/lambdas/supplier-allocator/src/handler/__tests__/allocate-handler.test.ts index cc02087cd..97d6e391a 100644 --- a/lambdas/supplier-allocator/src/handler/__tests__/allocate-handler.test.ts +++ b/lambdas/supplier-allocator/src/handler/__tests__/allocate-handler.test.ts @@ -744,6 +744,7 @@ describe("createSupplierAllocatorHandler", () => { expect(allocationConfig.selectSupplierByFactor).toHaveBeenCalledWith( expect.any(Array), expect.any(Array), + "letter1", mockedDeps, ); }); diff --git a/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts b/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts index 87b58584f..f90dbbbcf 100644 --- a/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts +++ b/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts @@ -875,6 +875,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, + "domainId", mockDeps, ); @@ -906,6 +907,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, allocationsWithMissingSupplier, + "domainId", mockDeps, ); @@ -937,6 +939,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, allocationsWithZeroPercentage, + "domainId", mockDeps, ); @@ -967,7 +970,12 @@ describe("selectSupplierByFactor", () => { ]; await expect( - selectSupplierByFactor(mockSuppliers, zeroAllocations, mockDeps), + selectSupplierByFactor( + mockSuppliers, + zeroAllocations, + "domainId", + mockDeps, + ), ).rejects.toThrow( "No valid supplier allocations found for suppliers with valid pack", ); @@ -987,6 +995,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, + "domainId", mockDeps, ); @@ -1006,6 +1015,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( singleSupplier, singleAllocation, + "domainId", mockDeps, ); @@ -1026,6 +1036,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, + "domainId", mockDeps, ); @@ -1046,6 +1057,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, + "domainId", mockDeps, ); @@ -1059,7 +1071,12 @@ describe("selectSupplierByFactor", () => { ).mockRejectedValue(error); await expect( - selectSupplierByFactor(mockSuppliers, mockSupplierAllocations, mockDeps), + selectSupplierByFactor( + mockSuppliers, + mockSupplierAllocations, + "domainId", + mockDeps, + ), ).rejects.toThrow("Factor calculation error"); }); @@ -1084,6 +1101,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, allocationsWithUnrelatedSupplier, + "domainId", mockDeps, ); @@ -1124,6 +1142,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( manySuppliers, manyAllocations, + "domainId", mockDeps, ); @@ -1136,7 +1155,12 @@ describe("selectSupplierByFactor", () => { ).mockResolvedValue([]); await expect( - selectSupplierByFactor(mockSuppliers, mockSupplierAllocations, mockDeps), + selectSupplierByFactor( + mockSuppliers, + mockSupplierAllocations, + "domainId", + mockDeps, + ), ).rejects.toThrow("No supplier factors could be calculated for allocation"); }); }); diff --git a/lambdas/supplier-allocator/src/handler/allocate-handler.ts b/lambdas/supplier-allocator/src/handler/allocate-handler.ts index 326f20bb2..de532ae06 100644 --- a/lambdas/supplier-allocator/src/handler/allocate-handler.ts +++ b/lambdas/supplier-allocator/src/handler/allocate-handler.ts @@ -124,12 +124,14 @@ async function getSupplierFromConfig( ? await selectSupplierByFactor( suppliersForPackWithCapacity, supplierAllocations, + letterEvent.data.domainId, deps, ) : undefined) ?? (await selectSupplierByFactor( allSuppliersForPack, supplierAllocations, + letterEvent.data.domainId, deps, )); diff --git a/lambdas/supplier-allocator/src/handler/allocation-config.ts b/lambdas/supplier-allocator/src/handler/allocation-config.ts index f912fe0ec..938ecc820 100644 --- a/lambdas/supplier-allocator/src/handler/allocation-config.ts +++ b/lambdas/supplier-allocator/src/handler/allocation-config.ts @@ -148,6 +148,7 @@ export async function filterSuppliersWithCapacity( export async function selectSupplierByFactor( suppliers: Supplier[], supplierAllocations: SupplierAllocation[], + domainId: string, deps: Deps, ): Promise { const supplierAllocationsForPack = supplierAllocations.filter((alloc) => { @@ -175,6 +176,7 @@ export async function selectSupplierByFactor( deps.logger.info({ description: "Calculated supplier factors for allocation", + domainId, supplierFactors, }); let selectedSupplierId = supplierFactors[0].supplierId; diff --git a/lambdas/supplier-allocator/src/services/supplier-config.ts b/lambdas/supplier-allocator/src/services/supplier-config.ts index 52ac1c434..7ed2509bd 100644 --- a/lambdas/supplier-allocator/src/services/supplier-config.ts +++ b/lambdas/supplier-allocator/src/services/supplier-config.ts @@ -301,6 +301,7 @@ export async function filterPacksForLetter( if (violatedConstraints.length > 0) { deps.logger.info({ description: `Pack specification filtered out based on pageCount constraints`, + dommainId: letterEvent.data.domainId, packSpecId, pageCount, violatedConstraints, diff --git a/tests/component-tests/allocation-tests/letter-allocation-capacity.spec.ts b/tests/component-tests/allocation-tests/letter-allocation-capacity.spec.ts index 7a172a4a8..616ab1df9 100644 --- a/tests/component-tests/allocation-tests/letter-allocation-capacity.spec.ts +++ b/tests/component-tests/allocation-tests/letter-allocation-capacity.spec.ts @@ -66,6 +66,7 @@ test.describe("Allocator Lambda Tests", () => { const supplierAllocatorLog = await getAllocationLog( "Pack specification filtered out based on pageCount constraints", + { extraPatterns: [domainId] }, ); const filteredPackSpecId = supplierAllocatorLog.packSpecId; logger.info(`Pack spec filtered out ${filteredPackSpecId}`); diff --git a/tests/component-tests/allocation-tests/letter-allocation-weighting.spec.ts b/tests/component-tests/allocation-tests/letter-allocation-weighting.spec.ts index d51cbedbd..25340aada 100644 --- a/tests/component-tests/allocation-tests/letter-allocation-weighting.spec.ts +++ b/tests/component-tests/allocation-tests/letter-allocation-weighting.spec.ts @@ -97,6 +97,7 @@ test.describe("Allocator Weighting Tests", () => { "Calculated supplier factors for allocation", { startTimeMs: testStartedAt, + extraPatterns: [domainId], }, ); From b59f07cac708559530ba355517f5ce795062d73d Mon Sep 17 00:00:00 2001 From: David Wass Date: Wed, 1 Jul 2026 15:57:30 +0100 Subject: [PATCH 7/7] review changes --- .../__tests__/allocation-config.test.ts | 25 ++++++++++--------- .../src/handler/allocation-config.ts | 8 +++--- .../allocation-letter-variant.spec.ts | 2 +- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts b/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts index f90dbbbcf..ef3e576f2 100644 --- a/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts +++ b/lambdas/supplier-allocator/src/handler/__tests__/allocation-config.test.ts @@ -810,6 +810,7 @@ describe("selectSupplierByFactor", () => { let mockDeps: jest.Mocked; let mockSuppliers: Supplier[]; let mockSupplierAllocations: SupplierAllocation[]; + const domainId = "test-domain-id"; beforeEach(() => { jest.clearAllMocks(); @@ -875,7 +876,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, - "domainId", + domainId, mockDeps, ); @@ -907,7 +908,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, allocationsWithMissingSupplier, - "domainId", + domainId, mockDeps, ); @@ -939,7 +940,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, allocationsWithZeroPercentage, - "domainId", + domainId, mockDeps, ); @@ -973,7 +974,7 @@ describe("selectSupplierByFactor", () => { selectSupplierByFactor( mockSuppliers, zeroAllocations, - "domainId", + domainId, mockDeps, ), ).rejects.toThrow( @@ -995,7 +996,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, - "domainId", + domainId, mockDeps, ); @@ -1015,7 +1016,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( singleSupplier, singleAllocation, - "domainId", + domainId, mockDeps, ); @@ -1036,7 +1037,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, - "domainId", + domainId, mockDeps, ); @@ -1057,7 +1058,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, - "domainId", + domainId, mockDeps, ); @@ -1074,7 +1075,7 @@ describe("selectSupplierByFactor", () => { selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, - "domainId", + domainId, mockDeps, ), ).rejects.toThrow("Factor calculation error"); @@ -1101,7 +1102,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( mockSuppliers, allocationsWithUnrelatedSupplier, - "domainId", + domainId, mockDeps, ); @@ -1142,7 +1143,7 @@ describe("selectSupplierByFactor", () => { const result = await selectSupplierByFactor( manySuppliers, manyAllocations, - "domainId", + domainId, mockDeps, ); @@ -1158,7 +1159,7 @@ describe("selectSupplierByFactor", () => { selectSupplierByFactor( mockSuppliers, mockSupplierAllocations, - "domainId", + domainId, mockDeps, ), ).rejects.toThrow("No supplier factors could be calculated for allocation"); diff --git a/lambdas/supplier-allocator/src/handler/allocation-config.ts b/lambdas/supplier-allocator/src/handler/allocation-config.ts index 938ecc820..f9e7f92d1 100644 --- a/lambdas/supplier-allocator/src/handler/allocation-config.ts +++ b/lambdas/supplier-allocator/src/handler/allocation-config.ts @@ -38,10 +38,10 @@ export async function eligibleSuppliers( volumeGroupId: volumeGroup.id, letterVariantSupplierId, }); - const filteredAllocations = supplierAllocations.filter( + const filteredAllocations = supplierAllocations.find( (alloc) => alloc.supplier === letterVariantSupplierId, ); - if (filteredAllocations.length === 0) { + if (!filteredAllocations) { deps.logger.warn({ description: "No allocations found for specified letter variant supplier", @@ -50,9 +50,9 @@ export async function eligibleSuppliers( }); } return { - supplierAllocations: filteredAllocations, + supplierAllocations: filteredAllocations ? [filteredAllocations] : [], suppliers: await getSupplierDetails( - filteredAllocations.map((alloc) => alloc.supplier), + filteredAllocations ? [filteredAllocations.supplier] : [], deps, ), }; diff --git a/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts b/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts index 880fc543d..d1489014b 100644 --- a/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts +++ b/tests/component-tests/allocation-tests/allocation-letter-variant.spec.ts @@ -12,7 +12,7 @@ import { sendSnsEvent } from "tests/helpers/send-sns-event"; test.describe("Letter Variant Tests", () => { test.setTimeout(180_000); // 3 minutes for long running polling - test("Verify that supplierId on letter variant takes pecedence over volume group", async () => { + test("Verify that supplierId on letter variant takes precedence over volume group", async () => { const letterVariant = getVariantsForAllocation(3); const domainId = randomUUID(); const preparedEvent = createPreparedV1Event({