Skip to content

Commit 100dfb3

Browse files
CCM-15148 - Add BillingId to variant map
1 parent 4bdf23d commit 100dfb3

9 files changed

Lines changed: 36 additions & 17 deletions

File tree

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ No requirements.
3434
| <a name="input_group"></a> [group](#input\_group) | The group variables are being inherited from (often synonmous with account short-name) | `string` | n/a | yes |
3535
| <a name="input_kms_deletion_window"></a> [kms\_deletion\_window](#input\_kms\_deletion\_window) | When a kms key is deleted, how long should it wait in the pending deletion state? | `string` | `"30"` | no |
3636
| <a name="input_letter_table_ttl_hours"></a> [letter\_table\_ttl\_hours](#input\_letter\_table\_ttl\_hours) | Number of hours to set as TTL on letters table | `number` | `24` | no |
37-
| <a name="input_letter_variant_map"></a> [letter\_variant\_map](#input\_letter\_variant\_map) | n/a | `map(object({ supplierId = string, specId = string }))` | <pre>{<br/> "lv1": {<br/> "specId": "spec1",<br/> "supplierId": "supplier1"<br/> },<br/> "lv2": {<br/> "specId": "spec2",<br/> "supplierId": "supplier1"<br/> },<br/> "lv3": {<br/> "specId": "spec3",<br/> "supplierId": "supplier2"<br/> }<br/>}</pre> | no |
37+
| <a name="input_letter_variant_map"></a> [letter\_variant\_map](#input\_letter\_variant\_map) | n/a | `map(object({ supplierId = string, specId = string, billingId = string }))` | <pre>{<br/> "lv1": {<br/> "billingId": "billing1",<br/> "specId": "spec1",<br/> "supplierId": "supplier1"<br/> },<br/> "lv2": {<br/> "billingId": "billing2",<br/> "specId": "spec2",<br/> "supplierId": "supplier1"<br/> },<br/> "lv3": {<br/> "billingId": "billing3",<br/> "specId": "spec3",<br/> "supplierId": "supplier2"<br/> }<br/>}</pre> | no |
3838
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | The log level to be used in lambda functions within the component. Any log with a lower severity than the configured value will not be logged: https://docs.python.org/3/library/logging.html#levels | `string` | `"INFO"` | no |
3939
| <a name="input_log_retention_in_days"></a> [log\_retention\_in\_days](#input\_log\_retention\_in\_days) | The retention period in days for the Cloudwatch Logs events to be retained, default of 0 is indefinite | `number` | `0` | no |
4040
| <a name="input_manually_configure_mtls_truststore"></a> [manually\_configure\_mtls\_truststore](#input\_manually\_configure\_mtls\_truststore) | Manually manage the truststore used for API Gateway mTLS (e.g. for prod environment) | `bool` | `false` | no |

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 }))
139+
type = map(object({ supplierId = string, specId = string, billingId = string }))
140140
default = {
141-
"lv1" = { supplierId = "supplier1", specId = "spec1" },
142-
"lv2" = { supplierId = "supplier1", specId = "spec2" },
143-
"lv3" = { supplierId = "supplier2", specId = "spec3" }
141+
"lv1" = { supplierId = "supplier1", specId = "spec1", billingId = "billing1" },
142+
"lv2" = { supplierId = "supplier1", specId = "spec2", billingId = "billing2" },
143+
"lv3" = { supplierId = "supplier2", specId = "spec3", billingId = "billing3" }
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
@@ -7,6 +7,7 @@ describe("createDependenciesContainer", () => {
77
lv1: {
88
supplierId: "supplier1",
99
specId: "spec1",
10+
billingId: "billing1",
1011
},
1112
},
1213
};

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ 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",
3536
specId: "spec-2",
37+
billingId: "billing-2",
3638
},
3739
},
3840
};

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)