Skip to content

Commit aea9a48

Browse files
CCM-15148 - Add BillingId to variant map
1 parent d6dc000 commit aea9a48

6 files changed

Lines changed: 29 additions & 12 deletions

File tree

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
process.env.VARIANT_MAP = `{
2020
"lv1": {
2121
"supplierId": "supplier1",
22-
"specId": "spec1"
22+
"specId": "spec1",
23+
"billingId": "billing1"
2324
}
2425
}`;
2526

@@ -31,6 +32,7 @@ describe("lambdaEnv", () => {
3132
lv1: {
3233
supplierId: "supplier1",
3334
specId: "spec1",
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
@@ -5,6 +5,7 @@ const LetterVariantSchema = z.record(
55
z.object({
66
supplierId: z.string(),
77
specId: z.string(),
8+
billingId: z.string(),
89
}),
910
);
1011
export type LetterVariant = z.infer<typeof LetterVariantSchema>;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function makeDeps(overrides: Partial<Deps> = {}): Deps {
2929
"variant-1": {
3030
supplierId: "supplier-1",
3131
specId: "spec-1",
32+
billingId: "billing-1",
3233
},
3334
"variant-2": {
3435
supplierId: "supplier-2",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from "../services/supplier-config";
1818
import { Deps } from "../config/deps";
1919

20-
type SupplierSpec = { supplierId: string; specId: string };
20+
type SupplierSpec = { supplierId: string; specId: string; billingId: string };
2121
type PreparedEvents = LetterRequestPreparedEventV2 | LetterRequestPreparedEvent;
2222

2323
// small envelope that must exist in all inputs

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,15 @@ describe("createUpsertLetterHandler", () => {
216216
supplierSpec: {
217217
supplierId: "supplier1",
218218
specId: "spec1",
219+
billingId: "billing1",
219220
},
220221
};
221222
const v1message = {
222223
letterEvent: createPreparedV1Event(),
223224
supplierSpec: {
224-
supplierId: "supplier1",
225-
specId: "spec1",
225+
supplierId: "supplier2",
226+
specId: "spec2",
227+
billingId: "billing2",
226228
},
227229
};
228230

@@ -257,19 +259,19 @@ describe("createUpsertLetterHandler", () => {
257259
expect(insertedV2Letter.status).toBe("PENDING");
258260
expect(insertedV2Letter.groupId).toBe("client1campaign1template1");
259261
expect(insertedV2Letter.source).toBe("/data-plane/letter-rendering/test");
260-
expect(insertedV2Letter.specificationBillingId).toBe("spec1");
262+
expect(insertedV2Letter.specificationBillingId).toBe("billing1");
261263

262264
const insertedV1Letter = (mockedDeps.letterRepo.putLetter as jest.Mock).mock
263265
.calls[1][0];
264266
expect(insertedV1Letter.id).toBe("letter1");
265-
expect(insertedV1Letter.supplierId).toBe("supplier1");
266-
expect(insertedV1Letter.specificationId).toBe("spec1");
267-
expect(insertedV1Letter.billingRef).toBe("spec1");
267+
expect(insertedV1Letter.supplierId).toBe("supplier2");
268+
expect(insertedV1Letter.specificationId).toBe("spec2");
269+
expect(insertedV1Letter.billingRef).toBe("spec2");
268270
expect(insertedV1Letter.url).toBe("s3://letterDataBucket/letter1.pdf");
269271
expect(insertedV1Letter.status).toBe("PENDING");
270272
expect(insertedV1Letter.groupId).toBe("client1campaign1template1");
271273
expect(insertedV1Letter.source).toBe("/data-plane/letter-rendering/test");
272-
expect(insertedV1Letter.specificationBillingId).toBe("spec1");
274+
expect(insertedV1Letter.specificationBillingId).toBe("billing2");
273275

274276
const updatedLetter = (
275277
mockedDeps.letterRepo.updateLetterStatus as jest.Mock
@@ -285,7 +287,12 @@ describe("createUpsertLetterHandler", () => {
285287
});
286288
expect(mockMetrics.putMetric).toHaveBeenCalledWith(
287289
"MessagesProcessed",
288-
3,
290+
2,
291+
"Count",
292+
);
293+
expect(mockMetrics.putMetric).toHaveBeenCalledWith(
294+
"MessagesProcessed",
295+
1,
289296
"Count",
290297
);
291298
});
@@ -485,6 +492,7 @@ describe("createUpsertLetterHandler", () => {
485492
supplierSpec: {
486493
supplierId: "supplier1",
487494
specId: "spec1",
495+
billingId: "billing1",
488496
},
489497
};
490498
const message2 = {
@@ -495,6 +503,7 @@ describe("createUpsertLetterHandler", () => {
495503
supplierSpec: {
496504
supplierId: "supplier1",
497505
specId: "spec1",
506+
billingId: "billing1",
498507
},
499508
};
500509
const evt: SQSEvent = createSQSEvent([

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ 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 };
19+
type SupplierSpec = { supplierId: string; specId: string; billingId: string };
2020
type PreparedEvents = LetterRequestPreparedEventV2 | LetterRequestPreparedEvent;
2121

2222
const SupplierSpecSchema = z.object({
2323
supplierId: z.string().min(1),
2424
specId: z.string().min(1),
25+
billingId: z.string().min(1),
2526
});
2627

2728
const PreparedEventUnionSchema = z.discriminatedUnion("type", [
@@ -63,6 +64,7 @@ function getOperationFromType(type: string): UpsertOperation {
6364
supplierSpec.supplierId,
6465
supplierSpec.specId,
6566
supplierSpec.specId, // use specId for now
67+
supplierSpec.billingId, // use billingId for now
6668
);
6769
await deps.letterRepo.putLetter(letterToInsert);
6870

@@ -99,6 +101,7 @@ function mapToInsertLetter(
99101
supplier: string,
100102
spec: string,
101103
billingRef: string,
104+
billingId: string,
102105
): InsertLetter {
103106
const now = new Date().toISOString();
104107
return {
@@ -117,7 +120,7 @@ function mapToInsertLetter(
117120
createdAt: now,
118121
updatedAt: now,
119122
billingRef,
120-
specificationBillingId: spec,
123+
specificationBillingId: billingId,
121124
};
122125
}
123126

@@ -239,6 +242,7 @@ export default function createUpsertLetterHandler(deps: Deps): SQSHandler {
239242
supplierSpec ?? {
240243
supplierId: "unknown",
241244
specId: "unknown",
245+
billingId: "unknown",
242246
},
243247
deps,
244248
);

0 commit comments

Comments
 (0)