Skip to content

Commit b5b258a

Browse files
CCM-13752 Added specificationBillingId
1 parent ebf8c67 commit b5b258a

7 files changed

Lines changed: 45 additions & 10 deletions

File tree

internal/datastore/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export const LetterSchema = LetterSchemaBase.extend({
5353
source: z.string(),
5454
subject: z.string(),
5555
billingRef: z.string(),
56+
specificationBillingId: z.string(),
5657
}).describe("Letter");
5758

5859
/**

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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ function makeDeps(overrides: Partial<Deps> = {}): Deps {
2626

2727
const env = {
2828
VARIANT_MAP: {
29-
"variant-1": { supplierId: "supplier-1", specId: "spec-1" },
30-
"variant-2": { supplierId: "supplier-2", specId: "spec-2" },
29+
"variant-1": {
30+
supplierId: "supplier-1",
31+
specId: "spec-1",
32+
billingId: "billing-1",
33+
},
34+
"variant-2": {
35+
supplierId: "supplier-2",
36+
specId: "spec-2",
37+
billingId: "billing-2",
38+
},
3139
},
3240
};
3341

@@ -87,6 +95,7 @@ function setupDefaultMocks() {
8795
(supplierConfig.getSupplierDetails as jest.Mock).mockResolvedValue({
8896
supplierId: "supplier-1",
8997
specId: "spec-1",
98+
billingId: "billing-1",
9099
});
91100
}
92101

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: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,19 @@ describe("createUpsertLetterHandler", () => {
211211
test("processes all records successfully and returns no batch failures", async () => {
212212
const v2message = {
213213
letterEvent: createPreparedV2Event(),
214-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
214+
supplierSpec: {
215+
supplierId: "supplier1",
216+
specId: "spec1",
217+
billingId: "billing1",
218+
},
215219
};
216220
const v1message = {
217221
letterEvent: createPreparedV1Event(),
218-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
222+
supplierSpec: {
223+
supplierId: "supplier1",
224+
specId: "spec1",
225+
billingId: "billing1",
226+
},
219227
};
220228

221229
const evt: SQSEvent = createSQSEvent([
@@ -249,6 +257,7 @@ describe("createUpsertLetterHandler", () => {
249257
expect(insertedV2Letter.status).toBe("PENDING");
250258
expect(insertedV2Letter.groupId).toBe("client1campaign1template1");
251259
expect(insertedV2Letter.source).toBe("/data-plane/letter-rendering/test");
260+
expect(insertedV2Letter.specificationBillingId).toBe("billing1");
252261

253262
const insertedV1Letter = (mockedDeps.letterRepo.putLetter as jest.Mock).mock
254263
.calls[1][0];
@@ -260,6 +269,7 @@ describe("createUpsertLetterHandler", () => {
260269
expect(insertedV1Letter.status).toBe("PENDING");
261270
expect(insertedV1Letter.groupId).toBe("client1campaign1template1");
262271
expect(insertedV1Letter.source).toBe("/data-plane/letter-rendering/test");
272+
expect(insertedV1Letter.specificationBillingId).toBe("billing1");
263273

264274
const updatedLetter = (
265275
mockedDeps.letterRepo.updateLetterStatus as jest.Mock
@@ -472,14 +482,22 @@ describe("createUpsertLetterHandler", () => {
472482
id: "7b9a03ca-342a-4150-b56b-989109c45615",
473483
domainId: "ok",
474484
}),
475-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
485+
supplierSpec: {
486+
supplierId: "supplier1",
487+
specId: "spec1",
488+
billingId: "billing1",
489+
},
476490
};
477491
const message2 = {
478492
letterEvent: createPreparedV2Event({
479493
id: "7b9a03ca-342a-4150-b56b-989109c45616",
480494
domainId: "fail",
481495
}),
482-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
496+
supplierSpec: {
497+
supplierId: "supplier1",
498+
specId: "spec1",
499+
billingId: "billing1",
500+
},
483501
};
484502
const evt: SQSEvent = createSQSEvent([
485503
createSqsRecord("ok-msg", JSON.stringify(message1)),

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", [
@@ -62,7 +63,8 @@ function getOperationFromType(type: string): UpsertOperation {
6263
preparedRequest,
6364
supplierSpec.supplierId,
6465
supplierSpec.specId,
65-
supplierSpec.specId, // use specId for now
66+
supplierSpec.specId,
67+
supplierSpec.billingId, // use specId 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,6 +120,7 @@ function mapToInsertLetter(
117120
createdAt: now,
118121
updatedAt: now,
119122
billingRef,
123+
specificationBillingId: billingId,
120124
};
121125
}
122126

0 commit comments

Comments
 (0)