Skip to content

Commit 6ca6cb3

Browse files
committed
CCM-11352: pr comments
1 parent 72f78cb commit 6ca6cb3

File tree

5 files changed

+37
-70
lines changed

5 files changed

+37
-70
lines changed

infrastructure/terraform/components/sandbox/sns_topic_events.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# this is not sued for anything other than to keep the eventpub module happy
2+
# this is not used for anything other than to keep the eventpub module happy
33
resource "aws_sns_topic" "events" {
44
name = "${local.csi}-events-sns"
55

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { test as setup } from '@playwright/test';
1+
import { test as teardown } from '@playwright/test';
22
import { createAuthHelper } from '../../helpers/auth/cognito-auth-helper';
33

4-
setup('event test teardown', async () => {
4+
teardown('event test teardown', async () => {
55
await createAuthHelper().teardown();
66
});

tests/test-team/helpers/events/event-cache-helper.ts

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { z } from 'zod';
2-
import {
3-
S3Client,
4-
SelectObjectContentCommand,
5-
SelectObjectContentEventStream,
6-
} from '@aws-sdk/client-s3';
2+
import { SelectObjectContentEventStream } from '@aws-sdk/client-s3';
73
import {
84
$TemplateCompletedEventV1,
95
$TemplateDeletedEventV1,
@@ -26,7 +22,6 @@ const $NHSNotifyTemplateEvent = z.discriminatedUnion('type', [
2622
type NHSNotifyTemplateEvent = z.infer<typeof $NHSNotifyTemplateEvent>;
2723

2824
export class EventCacheHelper {
29-
private readonly s3 = new S3Client({ region: 'eu-west-2' });
3025
private readonly bucketName = process.env.EVENT_CACHE_BUCKET_NAME;
3126

3227
async findEvents(
@@ -58,21 +53,13 @@ export class EventCacheHelper {
5853
fileName: string,
5954
templateIds: string[]
6055
): Promise<NHSNotifyTemplateEvent[]> {
61-
const command = new SelectObjectContentCommand({
62-
Bucket: this.bucketName,
63-
Key: fileName,
64-
Expression: this.buildS3Query(templateIds),
65-
ExpressionType: 'SQL',
66-
InputSerialization: {
67-
JSON: { Type: 'LINES' },
68-
CompressionType: 'NONE',
69-
},
70-
OutputSerialization: {
71-
JSON: { RecordDelimiter: '\n' },
72-
},
73-
});
56+
const formattedIds = templateIds.map((r) => `'${r}'`);
7457

75-
const response = await this.s3.send(command);
58+
const response = await S3Helper.queryJSONLFile(
59+
this.bucketName,
60+
fileName,
61+
`SELECT * FROM S3Object s WHERE s.data.id IN (${formattedIds})`
62+
);
7663

7764
if (!response.Payload) {
7865
return [];
@@ -141,12 +128,6 @@ export class EventCacheHelper {
141128
return paths;
142129
}
143130

144-
private buildS3Query(templateIds: string[]): string {
145-
const formattedIds = templateIds.map((r) => `'${r}'`);
146-
147-
return `SELECT * FROM S3Object s WHERE s.data.id IN (${formattedIds})`;
148-
}
149-
150131
private buildPathPrefix(date: Date): string {
151132
return date
152133
.toISOString()

tests/test-team/helpers/s3-helper.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { _Object, ListObjectsV2Command, S3Client } from '@aws-sdk/client-s3';
1+
import {
2+
_Object,
3+
ListObjectsV2Command,
4+
S3Client,
5+
SelectObjectContentCommand,
6+
} from '@aws-sdk/client-s3';
27

38
export class S3Helper {
49
private static readonly client = new S3Client({ region: 'eu-west-2' });
@@ -26,6 +31,24 @@ export class S3Helper {
2631
return allItems;
2732
}
2833

34+
static async queryJSONLFile(bucket: string, fileName: string, query: string) {
35+
const command = new SelectObjectContentCommand({
36+
Bucket: bucket,
37+
Key: fileName,
38+
Expression: query,
39+
ExpressionType: 'SQL',
40+
InputSerialization: {
41+
JSON: { Type: 'LINES' },
42+
CompressionType: 'NONE',
43+
},
44+
OutputSerialization: {
45+
JSON: { RecordDelimiter: '\n' },
46+
},
47+
});
48+
49+
return S3Helper.client.send(command);
50+
}
51+
2952
static filterAndSort(files: _Object[], from: Date): _Object[] {
3053
return S3Helper.sort(S3Helper.filter([...files], from));
3154
}

tests/test-team/template-mgmt-event-tests/letter-templates.event.spec.ts

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,12 @@ import { readFileSync } from 'node:fs';
1212
import { SftpHelper } from '../helpers/sftp/sftp-helper';
1313
import { InvokeCommand, LambdaClient } from '@aws-sdk/client-lambda';
1414

15-
const sleep = (delaySeconds: number) =>
16-
new Promise((resolve) => setTimeout(resolve, delaySeconds * 1000));
17-
1815
test.describe('Event publishing - Letters', () => {
1916
const authHelper = createAuthHelper();
2017
const templateStorageHelper = new TemplateStorageHelper();
2118
const eventCacheHelper = new EventCacheHelper();
2219
const sftpHelper = new SftpHelper();
2320
const lambdaClient = new LambdaClient({ region: 'eu-west-2' });
24-
const NON_PUBLISHABLE_LETTER_STATUSES = [
25-
'PENDING_UPLOAD',
26-
'PENDING_VALIDATION',
27-
'VIRUS_SCAN_FAILED',
28-
'VALIDATION_FAILED',
29-
] as const;
3021

3122
let userProofingEnabled: TestUser;
3223
let userProofingDisabled: TestUser;
@@ -42,40 +33,12 @@ test.describe('Event publishing - Letters', () => {
4233
await templateStorageHelper.deleteSeededTemplates();
4334
});
4435

45-
test(`Expect no events for AnyOf: ${NON_PUBLISHABLE_LETTER_STATUSES}`, async () => {
46-
const templates = NON_PUBLISHABLE_LETTER_STATUSES.map((status) => {
47-
const templateId = randomUUID();
48-
49-
return {
50-
...TemplateFactory.uploadLetterTemplate(
51-
templateId,
52-
userProofingEnabled,
53-
`user-event-${status}-fails`,
54-
status
55-
),
56-
};
57-
});
58-
59-
const start = new Date();
60-
61-
await templateStorageHelper.seedTemplateData(templates);
62-
63-
// Note: not ideal - but we are expecting 0 events and there can be a delay
64-
// in events arriving. We should wait for a moment
65-
// 5 seconds seems to largest delay when testing locally
66-
await sleep(5);
67-
68-
const events = await eventCacheHelper.findEvents(
69-
start,
70-
templates.map((r) => r.id)
71-
);
72-
73-
expect(events).toHaveLength(0);
74-
});
75-
7636
test('Expect no events when proofingEnabled is false', async ({
7737
request,
7838
}) => {
39+
const sleep = (delaySeconds: number) =>
40+
new Promise((resolve) => setTimeout(resolve, delaySeconds * 1000));
41+
7942
const templateId = randomUUID();
8043

8144
const start = new Date();

0 commit comments

Comments
 (0)