Skip to content

Commit f0ce917

Browse files
committed
Allocate priority from supplier spec
1 parent aa624d6 commit f0ce917

8 files changed

Lines changed: 35 additions & 14 deletions

File tree

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
"**/Thumbs.db": true,
1111
".github": false,
1212
".vscode": false
13-
}
13+
},
14+
"typescript.tsdk": "node_modules/typescript/lib"
1415
}

infrastructure/terraform/components/api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ No requirements.
3030
| <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 |
3131
| <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 |
3232
| <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 |
33-
| <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 |
33+
| <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/> "priority": 10,<br/> "specId": "spec1",<br/> "supplierId": "supplier1"<br/> },<br/> "lv2": {<br/> "priority": 10,<br/> "specId": "spec2",<br/> "supplierId": "supplier1"<br/> },<br/> "lv3": {<br/> "priority": 10,<br/> "specId": "spec3",<br/> "supplierId": "supplier2"<br/> }<br/>}</pre> | no |
3434
| <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 |
3535
| <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 |
3636
| <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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ variable "eventpub_control_plane_bus_arn" {
138138
variable "letter_variant_map" {
139139
type = map(object({ supplierId = string, specId = 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", priority = 10 },
142+
"lv2" = { supplierId = "supplier1", specId = "spec2", priority = 10 },
143+
"lv3" = { supplierId = "supplier2", specId = "spec3", priority = 10 }
144144
}
145145
}
146146

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+
"priority": 10
2223
}
2324
}`;
2425

@@ -29,6 +30,7 @@ describe("lambdaEnv", () => {
2930
lv1: {
3031
supplierId: "supplier1",
3132
specId: "spec1",
33+
priority: 10,
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+
priority: z.int().min(0).max(99), // Lower number represents a higher priority
89
}),
910
);
1011
export type LetterVariant = z.infer<typeof LetterVariantSchema>;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ describe("createSupplierAllocatorHandler", () => {
145145
lv1: {
146146
supplierId: "supplier1",
147147
specId: "spec1",
148+
priority: 10,
148149
},
149150
},
150151
} as EnvVars,
@@ -179,6 +180,7 @@ describe("createSupplierAllocatorHandler", () => {
179180
expect(messageBody.supplierSpec).toEqual({
180181
supplierId: "supplier1",
181182
specId: "spec1",
183+
priority: 10,
182184
});
183185
});
184186

@@ -205,6 +207,7 @@ describe("createSupplierAllocatorHandler", () => {
205207
expect(messageBody.supplierSpec).toEqual({
206208
supplierId: "supplier1",
207209
specId: "spec1",
210+
priority: 10,
208211
});
209212
});
210213

@@ -259,8 +262,11 @@ describe("createSupplierAllocatorHandler", () => {
259262

260263
const sendCall = (mockSqsClient.send as jest.Mock).mock.calls[0][0];
261264
const messageBody = JSON.parse(sendCall.input.MessageBody);
262-
expect(messageBody.supplierSpec.supplierId).toBe("supplier1");
263-
expect(messageBody.supplierSpec.specId).toBe("spec1");
265+
expect(messageBody.supplierSpec).toEqual({
266+
supplierId: "supplier1",
267+
specId: "spec1",
268+
priority: 10,
269+
});
264270
});
265271

266272
test("processes multiple messages in batch", async () => {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ 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: { supplierId: "supplier1", specId: "spec1", priority: 10 },
215215
};
216216
const v1message = {
217217
letterEvent: createPreparedV1Event(),
218-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
218+
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
219219
};
220220

221221
const evt: SQSEvent = createSQSEvent([
@@ -249,6 +249,7 @@ describe("createUpsertLetterHandler", () => {
249249
expect(insertedV2Letter.status).toBe("PENDING");
250250
expect(insertedV2Letter.groupId).toBe("client1campaign1template1");
251251
expect(insertedV2Letter.source).toBe("/data-plane/letter-rendering/test");
252+
expect(insertedV2Letter.priority).toBe(10);
252253

253254
const insertedV1Letter = (mockedDeps.letterRepo.putLetter as jest.Mock).mock
254255
.calls[1][0];
@@ -260,6 +261,7 @@ describe("createUpsertLetterHandler", () => {
260261
expect(insertedV1Letter.status).toBe("PENDING");
261262
expect(insertedV1Letter.groupId).toBe("client1campaign1template1");
262263
expect(insertedV1Letter.source).toBe("/data-plane/letter-rendering/test");
264+
expect(insertedV1Letter.priority).toBe(10);
263265

264266
const updatedLetter = (
265267
mockedDeps.letterRepo.updateLetterStatus as jest.Mock
@@ -472,14 +474,14 @@ describe("createUpsertLetterHandler", () => {
472474
id: "7b9a03ca-342a-4150-b56b-989109c45615",
473475
domainId: "ok",
474476
}),
475-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
477+
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
476478
};
477479
const message2 = {
478480
letterEvent: createPreparedV2Event({
479481
id: "7b9a03ca-342a-4150-b56b-989109c45616",
480482
domainId: "fail",
481483
}),
482-
supplierSpec: { supplierId: "supplier1", specId: "spec1" },
484+
supplierSpec: { supplierId: "supplier1", specId: "spec1", priority: 10 },
483485
};
484486
const evt: SQSEvent = createSQSEvent([
485487
createSqsRecord("ok-msg", JSON.stringify(message1)),

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ 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 };
2019
type PreparedEvents = LetterRequestPreparedEventV2 | LetterRequestPreparedEvent;
2120

2221
const SupplierSpecSchema = z.object({
2322
supplierId: z.string().min(1),
2423
specId: z.string().min(1),
24+
priority: z.int(),
2525
});
2626

27+
type SupplierSpec = z.infer<typeof SupplierSpecSchema>;
28+
2729
const PreparedEventUnionSchema = z.discriminatedUnion("type", [
2830
$LetterRequestPreparedEventV2,
2931
$LetterRequestPreparedEvent,
@@ -63,6 +65,7 @@ function getOperationFromType(type: string): UpsertOperation {
6365
supplierSpec.supplierId,
6466
supplierSpec.specId,
6567
supplierSpec.specId, // use specId for now
68+
supplierSpec.priority,
6669
);
6770
await deps.letterRepo.putLetter(letterToInsert);
6871

@@ -99,6 +102,7 @@ function mapToInsertLetter(
99102
supplier: string,
100103
spec: string,
101104
billingRef: string,
105+
priority: number,
102106
): InsertLetter {
103107
const now = new Date().toISOString();
104108
return {
@@ -107,6 +111,7 @@ function mapToInsertLetter(
107111
supplierId: supplier,
108112
status: "PENDING",
109113
specificationId: spec,
114+
priority,
110115
groupId:
111116
upsertRequest.data.clientId +
112117
upsertRequest.data.campaignId +
@@ -235,7 +240,11 @@ export default function createUpsertLetterHandler(deps: Deps): SQSHandler {
235240
await runUpsert(
236241
operation,
237242
letterEvent,
238-
supplierSpec ?? { supplierId: "unknown", specId: "unknown" },
243+
supplierSpec ?? {
244+
supplierId: "unknown",
245+
specId: "unknown",
246+
priority: 10,
247+
},
239248
deps,
240249
);
241250

0 commit comments

Comments
 (0)