Skip to content

Commit 1170785

Browse files
CCM-15148 - Add BillingId to variant map
1 parent c8e0e9e commit 1170785

7 files changed

Lines changed: 51 additions & 17 deletions

File tree

infrastructure/terraform/components/api/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ variable "eventpub_control_plane_bus_arn" {
136136
}
137137

138138
variable "letter_variant_map" {
139-
type = map(object({ supplierId = string, specId = string, priority = number }))
139+
type = map(object({ supplierId = string, specId = string, priority = number, billingId = string }))
140140
default = {
141-
"lv1" = { supplierId = "supplier1", specId = "spec1", priority = 10 },
142-
"lv2" = { supplierId = "supplier1", specId = "spec2", priority = 10 },
143-
"lv3" = { supplierId = "supplier2", specId = "spec3", priority = 10 }
141+
"lv1" = { supplierId = "supplier1", specId = "spec1", priority = 10, billingId = "billing1" },
142+
"lv2" = { supplierId = "supplier1", specId = "spec2", priority = 10, billingId = "billing1" },
143+
"lv3" = { supplierId = "supplier2", specId = "spec3", priority = 10, billingId = "billing1" }
144144
}
145145
}
146146

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe("createDependenciesContainer", () => {
66
lv1: {
77
supplierId: "supplier1",
88
specId: "spec1",
9+
billingId: "billing1",
910
},
1011
},
1112
};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ describe("lambdaEnv", () => {
1919
"lv1": {
2020
"supplierId": "supplier1",
2121
"specId": "spec1",
22-
"priority": 10
22+
"priority": 10,
23+
"billingId": "billing1"
2324
}
2425
}`;
2526

@@ -31,6 +32,7 @@ describe("lambdaEnv", () => {
3132
supplierId: "supplier1",
3233
specId: "spec1",
3334
priority: 10,
35+
billingId: "billing1",
3436
},
3537
},
3638
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const LetterVariantSchema = z.record(
66
supplierId: z.string(),
77
specId: z.string(),
88
priority: z.int().min(0).max(99), // Lower number represents a higher priority
9+
billingId: z.string(),
910
}),
1011
);
1112
export type LetterVariant = z.infer<typeof LetterVariantSchema>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Unit } from "aws-embedded-metrics";
88
import { MetricEntry, MetricStatus, buildEMFObject } from "@internal/helpers";
99
import { Deps } from "../config/deps";
1010

11-
type SupplierSpec = { supplierId: string; specId: string; priority: number };
11+
type SupplierSpec = { supplierId: string; specId: string; priority: number; billingId: string };
1212
type PreparedEvents = LetterRequestPreparedEventV2 | LetterRequestPreparedEvent;
1313

1414
// small envelope that must exist in all inputs

lambdas/upsert-letter/src/handler/__tests__/upsert-handler.test.ts

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,21 @@ describe("createUpsertLetterHandler", () => {
213213
test("processes all records successfully and returns no batch failures", async () => {
214214
const v2message = {
215215
letterEvent: createPreparedV2Event(),
216-
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
216+
supplierSpec: {
217+
supplierId: "supplier1",
218+
specId: "spec1",
219+
priority: 10,
220+
billingId: "billing1",
221+
},
217222
};
218223
const v1message = {
219224
letterEvent: createPreparedV1Event(),
220-
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
225+
supplierSpec: {
226+
supplierId: "supplier1",
227+
specId: "spec1",
228+
priority: 10,
229+
billingId: "billing1",
230+
},
221231
};
222232

223233
const evt: SQSEvent = createSQSEvent([
@@ -251,20 +261,20 @@ describe("createUpsertLetterHandler", () => {
251261
expect(insertedV2Letter.status).toBe("PENDING");
252262
expect(insertedV2Letter.groupId).toBe("client1campaign1template1");
253263
expect(insertedV2Letter.source).toBe("/data-plane/letter-rendering/test");
254-
expect(insertedV2Letter.specificationBillingId).toBe("spec1");
264+
expect(insertedV2Letter.specificationBillingId).toBe("billing1");
255265
expect(insertedV2Letter.priority).toBe(10);
256266

257267
const insertedV1Letter = (mockedDeps.letterRepo.putLetter as jest.Mock).mock
258268
.calls[1][0];
259269
expect(insertedV1Letter.id).toBe("letter1");
260-
expect(insertedV1Letter.supplierId).toBe("supplier1");
261-
expect(insertedV1Letter.specificationId).toBe("spec1");
262-
expect(insertedV1Letter.billingRef).toBe("spec1");
270+
expect(insertedV1Letter.supplierId).toBe("supplier2");
271+
expect(insertedV1Letter.specificationId).toBe("spec2");
272+
expect(insertedV1Letter.billingRef).toBe("spec2");
263273
expect(insertedV1Letter.url).toBe("s3://letterDataBucket/letter1.pdf");
264274
expect(insertedV1Letter.status).toBe("PENDING");
265275
expect(insertedV1Letter.groupId).toBe("client1campaign1template1");
266276
expect(insertedV1Letter.source).toBe("/data-plane/letter-rendering/test");
267-
expect(insertedV1Letter.specificationBillingId).toBe("spec1");
277+
expect(insertedV1Letter.specificationBillingId).toBe("billing2");
268278
expect(insertedV1Letter.priority).toBe(10);
269279

270280
const updatedLetter = (
@@ -281,7 +291,12 @@ describe("createUpsertLetterHandler", () => {
281291
});
282292
expect(mockMetrics.putMetric).toHaveBeenCalledWith(
283293
"MessagesProcessed",
284-
3,
294+
2,
295+
"Count",
296+
);
297+
expect(mockMetrics.putMetric).toHaveBeenCalledWith(
298+
"MessagesProcessed",
299+
1,
285300
"Count",
286301
);
287302
});
@@ -478,14 +493,24 @@ describe("createUpsertLetterHandler", () => {
478493
id: "7b9a03ca-342a-4150-b56b-989109c45615",
479494
domainId: "ok",
480495
}),
481-
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
496+
supplierSpec: {
497+
supplierId: "supplier1",
498+
specId: "spec1",
499+
priority: 10,
500+
billingId: "billing1",
501+
},
482502
};
483503
const message2 = {
484504
letterEvent: createPreparedV2Event({
485505
id: "7b9a03ca-342a-4150-b56b-989109c45616",
486506
domainId: "fail",
487507
}),
488-
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
508+
supplierSpec: {
509+
supplierId: "supplier1",
510+
specId: "spec1",
511+
priority: 10,
512+
billingId: "billing1",
513+
},
489514
};
490515
const evt: SQSEvent = createSQSEvent([
491516
createSqsRecord("ok-msg", JSON.stringify(message1)),

lambdas/upsert-letter/src/handler/upsert-handler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ import z from "zod";
1616
import { MetricsLogger, Unit, metricScope } from "aws-embedded-metrics";
1717
import { Deps } from "../config/deps";
1818

19+
type SupplierSpec = { supplierId: string; specId: string; priority: number; billingId: string };
1920
type PreparedEvents = LetterRequestPreparedEventV2 | LetterRequestPreparedEvent;
2021

2122
const SupplierSpecSchema = z.object({
2223
supplierId: z.string().min(1),
2324
specId: z.string().min(1),
2425
priority: z.int().min(0).max(99).default(10),
26+
billingId: z.string().min(1),
2527
});
2628

2729
type SupplierSpec = z.infer<typeof SupplierSpecSchema>;
@@ -66,6 +68,7 @@ function getOperationFromType(type: string): UpsertOperation {
6668
supplierSpec.specId,
6769
supplierSpec.specId, // use specId for now
6870
supplierSpec.priority,
71+
supplierSpec.billingId, // use billingId for now
6972
);
7073
await deps.letterRepo.putLetter(letterToInsert);
7174

@@ -103,6 +106,7 @@ function mapToInsertLetter(
103106
spec: string,
104107
billingRef: string,
105108
priority: number,
109+
billingId: string,
106110
): InsertLetter {
107111
const now = new Date().toISOString();
108112
return {
@@ -122,7 +126,7 @@ function mapToInsertLetter(
122126
createdAt: now,
123127
updatedAt: now,
124128
billingRef,
125-
specificationBillingId: spec,
129+
specificationBillingId: billingId,
126130
};
127131
}
128132

@@ -245,6 +249,7 @@ export default function createUpsertLetterHandler(deps: Deps): SQSHandler {
245249
supplierId: "unknown",
246250
specId: "unknown",
247251
priority: 10,
252+
billingId: "unknown",
248253
},
249254
deps,
250255
);

0 commit comments

Comments
 (0)