Skip to content

Commit 6f65a7c

Browse files
Remove VARIANT_MAP
1 parent 3c04502 commit 6f65a7c

7 files changed

Lines changed: 0 additions & 129 deletions

File tree

infrastructure/terraform/components/api/module_lambda_supplier_allocator.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ module "supplier_allocator" {
3535
log_subscription_role_arn = local.acct.log_subscription_role_arn
3636

3737
lambda_env_vars = merge(local.common_lambda_env_vars, {
38-
VARIANT_MAP = jsonencode(var.letter_variant_map)
3938
UPSERT_LETTERS_QUEUE_URL = module.sqs_letter_updates.sqs_queue_url
4039
})
4140
}

infrastructure/terraform/components/api/module_lambda_upsert_letter.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ module "upsert_letter" {
3333

3434
log_destination_arn = local.destination_arn
3535
log_subscription_role_arn = local.acct.log_subscription_role_arn
36-
37-
lambda_env_vars = merge(local.common_lambda_env_vars, {
38-
VARIANT_MAP = jsonencode(var.letter_variant_map)
39-
})
4036
}
4137

4238
data "aws_iam_policy_document" "upsert_letter_lambda" {

lambdas/supplier-allocator/src/config/__tests__/deps.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ describe("createDependenciesContainer", () => {
44
const env = {
55
SUPPLIER_CONFIG_TABLE_NAME: "SupplierConfigTable",
66
SUPPLIER_QUOTAS_TABLE_NAME: "SupplierQuotasTable",
7-
VARIANT_MAP: {
8-
lv1: {
9-
supplierId: "supplier1",
10-
specId: "spec1",
11-
billingId: "billing1",
12-
},
13-
},
147
};
158

169
beforeEach(() => {

lambdas/supplier-allocator/src/config/__tests__/env.test.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,12 @@ describe("lambdaEnv", () => {
1717
it("should load all environment variables successfully", () => {
1818
process.env.SUPPLIER_CONFIG_TABLE_NAME = "SupplierConfigTable";
1919
process.env.SUPPLIER_QUOTAS_TABLE_NAME = "SupplierQuotasTable";
20-
process.env.VARIANT_MAP = `{
21-
"lv1": {
22-
"supplierId": "supplier1",
23-
"specId": "spec1",
24-
"priority": 10,
25-
"billingId": "billing1"
26-
}
27-
}`;
2820

2921
const { envVars } = require("../env");
3022

3123
expect(envVars).toEqual({
3224
SUPPLIER_CONFIG_TABLE_NAME: "SupplierConfigTable",
3325
SUPPLIER_QUOTAS_TABLE_NAME: "SupplierQuotasTable",
34-
VARIANT_MAP: {
35-
lv1: {
36-
supplierId: "supplier1",
37-
specId: "spec1",
38-
priority: 10,
39-
billingId: "billing1",
40-
},
41-
},
4226
});
4327
});
44-
45-
it("should throw if a required env var is missing", () => {
46-
process.env.VARIANT_MAP = undefined;
47-
48-
expect(() => require("../env")).toThrow(ZodError);
49-
});
5028
});

lambdas/supplier-allocator/src/config/env.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ const EnvVarsSchema = z.object({
1515
SUPPLIER_CONFIG_TABLE_NAME: z.string(),
1616
SUPPLIER_QUOTAS_TABLE_NAME: z.string(),
1717
PINO_LOG_LEVEL: z.coerce.string().optional(),
18-
VARIANT_MAP: z.string().transform((str, _) => {
19-
const parsed = JSON.parse(str);
20-
return LetterVariantSchema.parse(parsed);
21-
}),
2218
});
2319

2420
export type EnvVars = z.infer<typeof EnvVarsSchema>;

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

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,6 @@ describe("createSupplierAllocatorHandler", () => {
222222
env: {
223223
SUPPLIER_CONFIG_TABLE_NAME: "SupplierConfigTable",
224224
SUPPLIER_QUOTAS_TABLE_NAME: "SupplierQuotasTable",
225-
VARIANT_MAP: {
226-
lv1: {
227-
supplierId: "supplier1",
228-
specId: "spec1",
229-
priority: 1,
230-
billingId: "billing1",
231-
},
232-
},
233225
} as EnvVars,
234226
sqsClient: mockSqsClient,
235227
supplierConfigRepo: mockedSupplierConfigRepo,
@@ -415,68 +407,6 @@ describe("createSupplierAllocatorHandler", () => {
415407
);
416408
});
417409

418-
test("returns batch failure when variant mapping is missing", async () => {
419-
const preparedEvent = createPreparedV2Event();
420-
preparedEvent.data.letterVariantId = "missing-variant";
421-
422-
const evt: SQSEvent = createSQSEvent([
423-
createSqsRecord("msg1", JSON.stringify(preparedEvent)),
424-
]);
425-
426-
process.env.UPSERT_LETTERS_QUEUE_URL = "https://sqs.test.queue";
427-
428-
// Override variant map to be empty for this test
429-
mockedDeps.env.VARIANT_MAP = {} as any;
430-
431-
const handler = createSupplierAllocatorHandler(mockedDeps);
432-
const result = await handler(evt, {} as any, {} as any);
433-
if (!result) throw new Error("expected BatchResponse, got void");
434-
435-
expect(result.batchItemFailures).toHaveLength(1);
436-
expect(result.batchItemFailures[0].itemIdentifier).toBe("msg1");
437-
expect(
438-
(mockedDeps.logger.error as jest.Mock).mock.calls.length,
439-
).toBeGreaterThan(0);
440-
expect((mockedDeps.logger.error as jest.Mock).mock.calls[0][0]).toEqual(
441-
expect.objectContaining({
442-
description: "No supplier mapping found for variant",
443-
}),
444-
);
445-
});
446-
447-
test("returns batch failure when variant mapping is missing for multiple events", async () => {
448-
const preparedEvent1 = createPreparedV2Event();
449-
preparedEvent1.data.letterVariantId = "missing-variant1";
450-
const preparedEvent2 = createPreparedV2Event();
451-
preparedEvent2.data.letterVariantId = "missing-variant2";
452-
453-
const evt: SQSEvent = createSQSEvent([
454-
createSqsRecord("msg1", JSON.stringify(preparedEvent1)),
455-
createSqsRecord("msg2", JSON.stringify(preparedEvent2)),
456-
]);
457-
458-
process.env.UPSERT_LETTERS_QUEUE_URL = "https://sqs.test.queue";
459-
460-
// Override variant map to be empty for this test
461-
mockedDeps.env.VARIANT_MAP = {} as any;
462-
463-
const handler = createSupplierAllocatorHandler(mockedDeps);
464-
const result = await handler(evt, {} as any, {} as any);
465-
if (!result) throw new Error("expected BatchResponse, got void");
466-
467-
expect(result.batchItemFailures).toHaveLength(2);
468-
expect(result.batchItemFailures[0].itemIdentifier).toBe("msg1");
469-
expect(result.batchItemFailures[1].itemIdentifier).toBe("msg2");
470-
expect(
471-
(mockedDeps.logger.error as jest.Mock).mock.calls.length,
472-
).toBeGreaterThan(0);
473-
expect((mockedDeps.logger.error as jest.Mock).mock.calls[0][0]).toEqual(
474-
expect.objectContaining({
475-
description: "No supplier mapping found for variant",
476-
}),
477-
);
478-
});
479-
480410
test("handles SQS send errors and returns batch failure", async () => {
481411
const preparedEvent = createPreparedV2Event();
482412

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ import { PreparedEvents, SupplierDetails, SupplierSpec } from "./types";
2828
// small envelope that must exist in all inputs
2929
const TypeEnvelope = z.object({ type: z.string().min(1) });
3030

31-
function resolveSupplierForVariant(
32-
variantId: string,
33-
deps: Deps,
34-
): SupplierSpec {
35-
const supplier = deps.env.VARIANT_MAP[variantId];
36-
if (!supplier) {
37-
deps.logger.error({
38-
description: "No supplier mapping found for variant",
39-
variantId,
40-
});
41-
throw new Error(`No supplier mapping for variantId: ${variantId}`);
42-
}
43-
44-
return supplier;
45-
}
46-
4731
function validateType(event: unknown) {
4832
const env = TypeEnvelope.safeParse(event);
4933
if (!env.success) {
@@ -138,10 +122,6 @@ async function getSupplierFromConfig(
138122
}
139123
}
140124

141-
function getSupplier(letterEvent: PreparedEvents, deps: Deps): SupplierSpec {
142-
return resolveSupplierForVariant(letterEvent.data.letterVariantId, deps);
143-
}
144-
145125
type AllocationMetrics = Map<string, Map<string, number>>;
146126
type VolumeGroupAllocation = Map<string, Record<string, number>>;
147127

@@ -232,7 +212,6 @@ export default function createSupplierAllocatorHandler(deps: Deps): SQSHandler {
232212

233213
validateType(letterEvent);
234214

235-
getSupplier(letterEvent as PreparedEvents, deps);
236215
const supplierDetails: SupplierDetails = await getSupplierFromConfig(
237216
letterEvent as PreparedEvents,
238217
deps,

0 commit comments

Comments
 (0)