Skip to content

Commit 8d813b0

Browse files
CCM-12600: Add sha256 to letters (#606)
1 parent 2259848 commit 8d813b0

31 files changed

Lines changed: 201 additions & 6 deletions

internal/datastore/src/__test__/letter-queue-repository.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function createLetter(
2121
specificationId: "specification1",
2222
groupId: "group1",
2323
priority: 10,
24+
sha256Hash: "hash1",
2425
...overrides,
2526
};
2627
}

internal/datastore/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const LetterSchemaBase = z.object({
4242
groupId: z.string(),
4343
reasonCode: z.string().optional(),
4444
reasonText: z.string().optional(),
45+
sha256Hash: z.string().optional(),
4546
});
4647

4748
export const LetterSchema = LetterSchemaBase.extend({
@@ -87,6 +88,7 @@ export const PendingLetterSchemaBase = z.object({
8788
letterId: idRef(LetterSchema, "id"),
8889
specificationId: z.string(),
8990
groupId: z.string(),
91+
sha256Hash: z.string().optional(),
9092
});
9193

9294
export const PendingLetterSchema = PendingLetterSchemaBase.extend({

internal/event-builders/src/letter-mapper.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export function mapLetterToCloudEvent(
1919
dataschemaversion,
2020
source,
2121
subject: `letter-origin/letter-rendering/letter/${letter.id}`,
22-
2322
data: {
2423
domainId: letter.id as LetterStatusChangeEvent["data"]["domainId"],
2524
status: letter.status,

lambdas/api-handler/src/contracts/letters.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const GetLetterResponseResourceSchema = z
5252
groupId: z.string().optional(),
5353
reasonCode: z.string().optional(),
5454
reasonText: z.string().optional(),
55+
sha256Hash: z.string().optional(),
5556
})
5657
.strict(),
5758
})
@@ -66,6 +67,7 @@ export const GetLettersResponseResourceSchema = z
6667
status: LetterStatusSchema,
6768
specificationId: z.string(),
6869
groupId: z.string().optional(),
70+
sha256Hash: z.string().optional(),
6971
})
7072
.strict(),
7173
})

lambdas/api-handler/src/mappers/__tests__/letter-mapper.test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,43 @@ describe("letter-mapper", () => {
120120
});
121121
});
122122

123+
it("maps an internal Letter to a GetLetterResponse with sha256Hash when present", () => {
124+
const date = new Date().toISOString();
125+
const letter: Letter = {
126+
id: "abc123",
127+
status: "PENDING",
128+
supplierId: "supplier1",
129+
specificationId: "spec123",
130+
billingRef: "spec123",
131+
groupId: "group123",
132+
url: "https://example.com/letter/abc123",
133+
createdAt: date,
134+
updatedAt: date,
135+
supplierStatus: "supplier1#PENDING",
136+
supplierStatusSk: date,
137+
ttl: 123,
138+
sha256Hash: "abc123hash",
139+
source: "/data-plane/letter-rendering/pdf",
140+
subject: "letter-rendering/source/letter/letter-id",
141+
specificationBillingId: "billing123",
142+
};
143+
144+
const result: GetLetterResponse = mapToGetLetterResponse(letter);
145+
146+
expect(result).toEqual({
147+
data: {
148+
id: "abc123",
149+
type: "Letter",
150+
attributes: {
151+
specificationId: "spec123",
152+
status: "PENDING",
153+
groupId: "group123",
154+
sha256Hash: "abc123hash",
155+
},
156+
},
157+
});
158+
});
159+
123160
it("maps an internal Letter to a GetLetterResponse with reasonCode and reasonText when present", () => {
124161
const date = new Date().toISOString();
125162
const letter: Letter = {
@@ -209,4 +246,57 @@ describe("letter-mapper", () => {
209246
],
210247
});
211248
});
249+
it("maps an internal Letter collection to a GetLettersResponse with sha256Hash when present", () => {
250+
const date = new Date().toISOString();
251+
const letter: Letter = {
252+
id: "abc123",
253+
status: "PENDING",
254+
supplierId: "supplier1",
255+
specificationId: "spec123",
256+
billingRef: "spec123",
257+
groupId: "group123",
258+
url: "https://example.com/letter/abc123",
259+
createdAt: date,
260+
updatedAt: date,
261+
supplierStatus: "supplier1#PENDING",
262+
supplierStatusSk: date,
263+
ttl: 123,
264+
reasonCode: "R01",
265+
reasonText: "Reason text",
266+
sha256Hash: "abc123hash",
267+
source: "/data-plane/letter-rendering/pdf",
268+
subject: "letter-rendering/source/letter/letter-id",
269+
specificationBillingId: "billing123",
270+
};
271+
272+
const result: GetLettersResponse = mapToGetLettersResponse([
273+
letter,
274+
letter,
275+
]);
276+
277+
expect(result).toEqual({
278+
data: [
279+
{
280+
id: "abc123",
281+
type: "Letter",
282+
attributes: {
283+
specificationId: "spec123",
284+
status: "PENDING",
285+
groupId: "group123",
286+
sha256Hash: "abc123hash",
287+
},
288+
},
289+
{
290+
id: "abc123",
291+
type: "Letter",
292+
attributes: {
293+
specificationId: "spec123",
294+
status: "PENDING",
295+
groupId: "group123",
296+
sha256Hash: "abc123hash",
297+
},
298+
},
299+
],
300+
});
301+
});
212302
});

lambdas/api-handler/src/mappers/letter-mapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function letterToResourceResponse(letter: LetterBase) {
2222
groupId: letter.groupId,
2323
...(letter.reasonCode != null && { reasonCode: letter.reasonCode }),
2424
...(letter.reasonText != null && { reasonText: letter.reasonText }),
25+
...(letter.sha256Hash != null && { sha256Hash: letter.sha256Hash }),
2526
},
2627
};
2728
}
@@ -34,6 +35,7 @@ function letterToGetLettersResourceResponse(letter: LetterBase) {
3435
status: letter.status,
3536
specificationId: letter.specificationId,
3637
groupId: letter.groupId,
38+
...(letter.sha256Hash != null && { sha256Hash: letter.sha256Hash }),
3739
},
3840
};
3941
}

lambdas/api-handler/src/services/letter-operations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function mapPendingLetterToLetterBase(pending: PendingLetterBase): LetterBase {
3636
status: "PENDING",
3737
specificationId: pending.specificationId,
3838
groupId: pending.groupId,
39+
sha256Hash: pending.sha256Hash,
3940
};
4041
}
4142

lambdas/update-letter-queue/src/update-letter-queue.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ function mapLetterToPendingLetter(letter: Letter): InsertPendingLetter {
191191
specificationId: letter.specificationId,
192192
groupId: letter.groupId,
193193
priority: letter.priority,
194+
sha256Hash: letter.sha256Hash,
194195
};
195196
}
196197

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ function mapToInsertLetter(
132132
upsertRequest.data.templateId,
133133
),
134134
url: upsertRequest.data.url,
135+
sha256Hash: upsertRequest.data.sha256Hash,
135136
source: upsertRequest.source,
136137
subject: upsertRequest.subject,
137138
createdAt: now,

sandbox/data/examples/getLetter/responses/getLetter-24L5eYSWGzCHlGmzNxuqVusPxDg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"data": {
33
"attributes": {
44
"groupId": "c5d93f917f5546d08beccf770a915d96",
5+
"sha256Hash": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c8f2f1d2d1e4f6e8f7e6e8f7e6",
56
"specificationId": "2WL5eYSWGzCHlGmzNxuqVusPxDg",
67
"status": "PENDING"
78
},

0 commit comments

Comments
 (0)