Skip to content

Commit a88f075

Browse files
committed
CCM-13146 simple ttl insertion and deletion
1 parent 14d87a9 commit a88f075

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed

.gitleaksignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ cd9c0efec38c5d63053dd865e5d4e207c0760d91:docs/guides/Perform_static_analysis.md:
1212
973c8a1feb76f3cd8743ce27b14e4acc4252240c:src/TESTING_PLAN.md:ipv4:2507
1313
cc74128e4207833109339e96f3aaebf3cd40dd65:src/TESTING_PLAN.md:ipv4:2507
1414
791619daf5af4806da7266fa301c0e82145b6de8:src/TESTING_PLAN.md:ipv4:2507
15+
f8546e35b77b69ba7b15dbe3174d2d7e375200ef:utils/utils/src/__tests__/key-generation/validate-private-key.test.ts:private-key:7
16+
f8546e35b77b69ba7b15dbe3174d2d7e375200ef:utils/utils/src/__tests__/key-generation/get-private-key.test.ts:private-key:23
17+
f8546e35b77b69ba7b15dbe3174d2d7e375200ef:utils/utils/src/__tests__/key-generation/get-private-key.test.ts:private-key:30
18+
f8546e35b77b69ba7b15dbe3174d2d7e375200ef:utils/utils/src/__tests__/key-generation/get-private-key.test.ts:private-key:46

tests/playwright/digital-letters-component-tests/create-ttl.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import getTtl from 'helpers/dynamodb-helpers';
2+
import { getTtl } from 'helpers/dynamodb-helpers';
33
import eventPublisher from 'helpers/event-bus-helpers';
44
import expectToPassEventually from 'helpers/expectations';
55
import { v4 as uuidv4 } from 'uuid';
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { expect, test } from '@playwright/test';
2+
import { deleteTtl, putTtl } from 'helpers/dynamodb-helpers';
3+
import expectToPassEventually from 'helpers/expectations';
4+
import { v4 as uuidv4 } from 'uuid';
5+
6+
test.describe('Digital Letters - Handle TTL', () => {
7+
const baseEvent = {
8+
profileversion: '1.0.0',
9+
profilepublished: '2025-10',
10+
specversion: '1.0',
11+
source:
12+
'/nhs/england/notify/production/primary/data-plane/digital-letters',
13+
subject:
14+
'customer/920fca11-596a-4eca-9c47-99f624614658/recipient/769acdd4-6a47-496f-999f-76a6fd2c3959',
15+
type: 'uk.nhs.notify.digital.letters.mesh.inbox.message.downloaded.v1',
16+
time: '2023-06-20T12:00:00Z',
17+
recordedtime: '2023-06-20T12:00:00.250Z',
18+
severitynumber: 2,
19+
traceparent: '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01',
20+
datacontenttype: 'application/json',
21+
dataschema:
22+
'https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10/digital-letter-base-data.schema.json',
23+
dataschemaversion: '1.0',
24+
severitytext: 'INFO',
25+
data: {
26+
messageReference: 'ref1',
27+
senderId: 'sender1',
28+
},
29+
}
30+
31+
32+
test('should handle withdrawn item', async () => {
33+
const letterId = uuidv4();
34+
const messageUri = `https://example.com/ttl/resource/${letterId}`;
35+
36+
const event = {
37+
...baseEvent,
38+
id: letterId,
39+
data: {
40+
...baseEvent.data,
41+
messageUri,
42+
'digital-letter-id': letterId,
43+
}
44+
}
45+
46+
const ttlItem = {
47+
PK: messageUri,
48+
SK: 'TTL',
49+
dateOfExpiry: '2023-12-31#0',
50+
event,
51+
ttl: (Date.now() / 1000) + 3600,
52+
withdrawn: true,
53+
}
54+
55+
56+
await expectToPassEventually(async () => {
57+
const putResponseCode = await putTtl(ttlItem);
58+
expect(putResponseCode).toBe(201);
59+
60+
const deleteResponseCode = await deleteTtl(messageUri);
61+
expect(deleteResponseCode).toBe(200);
62+
});
63+
});
64+
});

tests/playwright/helpers/dynamodb-helpers.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
1+
import { DeleteItemCommand, DeleteItemCommandOutput, DynamoDBClient, PutItemCommand, PutItemCommandOutput } from '@aws-sdk/client-dynamodb';
22
import { QueryCommand, QueryCommandOutput } from '@aws-sdk/lib-dynamodb';
3+
import { marshall } from '@aws-sdk/util-dynamodb';
34
import { REGION, TTL_TABLE_NAME } from 'constants/backend-constants';
5+
import { TtlDynamodbRecord } from 'utils';
46

57
const dynamoDbClient = new DynamoDBClient({ region: REGION });
68

7-
async function getTtl(messageUri: string) {
9+
export async function getTtl(messageUri: string) {
810
const params = {
911
TableName: TTL_TABLE_NAME,
1012
KeyConditionExpression: `PK = :messageUri`,
@@ -18,4 +20,31 @@ async function getTtl(messageUri: string) {
1820
return Items ?? [];
1921
}
2022

21-
export default getTtl;
23+
export async function putTtl(ttlItem: TtlDynamodbRecord) {
24+
const params = {
25+
TableName: TTL_TABLE_NAME,
26+
Item: marshall(ttlItem),
27+
};
28+
const request = new PutItemCommand(params);
29+
const output: PutItemCommandOutput = await dynamoDbClient.send(request);
30+
31+
return output.$metadata.httpStatusCode;
32+
}
33+
34+
export async function deleteTtl(messageUri: string) {
35+
const params = {
36+
TableName: TTL_TABLE_NAME,
37+
Key:{
38+
PK: {
39+
S: messageUri,
40+
},
41+
SK: {
42+
S: 'TTL',
43+
},
44+
}
45+
};
46+
const request = new DeleteItemCommand(params);
47+
const output : DeleteItemCommandOutput = await dynamoDbClient.send(request);
48+
49+
return output.$metadata.httpStatusCode;
50+
}

0 commit comments

Comments
 (0)