Skip to content

Commit 6d48fae

Browse files
CCM-15148 - Add BillingId to variant map
1 parent 5c4a9cb commit 6d48fae

8 files changed

Lines changed: 34 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
@@ -35,7 +35,7 @@ No requirements.
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_event_source"></a> [letter\_event\_source](#input\_letter\_event\_source) | Source value to use for the letter status event updates | `string` | `"/data-plane/supplier-api/nhs-supplier-api-prod/main/update-status"` | no |
3737
| <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 |
38-
| <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 |
38+
| <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 |
3939
| <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 |
4040
| <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 |
4141
| <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
@@ -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
@@ -18,7 +18,8 @@ describe("lambdaEnv", () => {
1818
process.env.VARIANT_MAP = `{
1919
"lv1": {
2020
"supplierId": "supplier1",
21-
"specId": "spec1"
21+
"specId": "spec1",
22+
"billingId": "billing1"
2223
}
2324
}`;
2425

@@ -29,6 +30,7 @@ describe("lambdaEnv", () => {
2930
lv1: {
3031
supplierId: "supplier1",
3132
specId: "spec1",
33+
billingId: "billing1",
3234
},
3335
},
3436
});

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/allocate-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { LetterRequestPreparedEventV2 } from "@nhsdigital/nhs-notify-event-schem
66
import z from "zod";
77
import { Deps } from "../config/deps";
88

9-
type SupplierSpec = { supplierId: string; specId: string };
9+
type SupplierSpec = { supplierId: string; specId: string; billingId: string };
1010
type PreparedEvents = LetterRequestPreparedEventV2 | LetterRequestPreparedEvent;
1111

1212
// 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)