Skip to content

Commit 6664aa7

Browse files
committed
CCM-8574: handle test data file format
1 parent 79b1ee9 commit 6664aa7

File tree

14 files changed

+152
-124
lines changed

14 files changed

+152
-124
lines changed

infrastructure/terraform/modules/backend-api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ No requirements.
4343
| <a name="module_s3bucket_internal"></a> [s3bucket\_internal](#module\_s3bucket\_internal) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
4444
| <a name="module_s3bucket_quarantine"></a> [s3bucket\_quarantine](#module\_s3bucket\_quarantine) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v1.0.8 |
4545
| <a name="module_sftp_upload_queue"></a> [sftp\_upload\_queue](#module\_sftp\_upload\_queue) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
46-
| <a name="module_sqs_validate_letter_template_files"></a> [sqs\_validate\_letter\_template\_files](#module\_sqs\_validate\_letter\_template\_files) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
46+
| <a name="module_sqs_validate_letter_template_files"></a> [sqs\_validate\_letter\_template\_files](#module\_sqs\_validate\_letter\_template\_files) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v2.0.1 |
4747
| <a name="module_sqs_virus_scan_failed_delete_object_dlq"></a> [sqs\_virus\_scan\_failed\_delete\_object\_dlq](#module\_sqs\_virus\_scan\_failed\_delete\_object\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
4848
| <a name="module_sqs_virus_scan_passed_copy_object_dlq"></a> [sqs\_virus\_scan\_passed\_copy\_object\_dlq](#module\_sqs\_virus\_scan\_passed\_copy\_object\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |
4949
| <a name="module_sqs_virus_scan_set_file_status_dlq"></a> [sqs\_virus\_scan\_set\_file\_status\_dlq](#module\_sqs\_virus\_scan\_set\_file\_status\_dlq) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs | v1.0.8 |

infrastructure/terraform/modules/backend-api/module_sqs_validate_letter_template_files.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "sqs_validate_letter_template_files" {
2-
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs?ref=v1.0.8"
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/sqs?ref=v2.0.1"
33

44
aws_account_id = var.aws_account_id
55
component = var.component
@@ -9,6 +9,7 @@ module "sqs_validate_letter_template_files" {
99
name = "validate-letter-template-files"
1010
create_dlq = true
1111
visibility_timeout_seconds = 10
12+
delay_seconds = 1
1213

1314
sqs_kms_key_arn = var.kms_key_arn
1415
}

lambdas/backend-api/src/__tests__/templates/api/validate-letter-template-files.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('guard duty handler', () => {
9090
});
9191
mocks.TemplatePdf.mockImplementation(() => pdf);
9292

93-
const csv = mock<TestDataCsv>({ headers: ['parameter_1'] });
93+
const csv = mock<TestDataCsv>({ parameters: ['parameter_1'] });
9494
mocks.TestDataCsv.mockImplementation(() => csv);
9595

9696
mocks.validateLetterTemplateFiles.mockReturnValueOnce(true);
@@ -129,7 +129,7 @@ describe('guard duty handler', () => {
129129
versionId,
130130
true,
131131
pdf.personalisationParameters,
132-
csv.headers
132+
csv.parameters
133133
);
134134
});
135135

@@ -958,7 +958,7 @@ describe('guard duty handler', () => {
958958
});
959959
mocks.TemplatePdf.mockImplementation(() => pdf);
960960

961-
const csv = mock<TestDataCsv>({ headers: ['parameter_1'] });
961+
const csv = mock<TestDataCsv>({ parameters: ['parameter_1'] });
962962
mocks.TestDataCsv.mockImplementation(() => csv);
963963

964964
mocks.validateLetterTemplateFiles.mockReturnValue(false);
@@ -972,7 +972,7 @@ describe('guard duty handler', () => {
972972
versionId,
973973
false,
974974
pdf.personalisationParameters,
975-
csv.headers
975+
csv.parameters
976976
);
977977
});
978978
});

lambdas/backend-api/src/__tests__/templates/domain/test-data-csv.test.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ test('parse', async () => {
1212

1313
csv.parse();
1414

15-
expect(csv.headers).toEqual([
15+
expect(csv.parameters).toEqual([
1616
'appointment_date',
1717
'appointment_time',
1818
'appointment_location',
1919
'contact_telephone_number',
2020
]);
2121

22-
expect(csv.rows).toEqual([
23-
[
24-
'Wednesday 10 September 2025',
25-
'12:56pm',
26-
'City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH',
27-
'020 3299 9010',
28-
],
29-
[
30-
'Saturday 10 April 2025',
31-
'11:56am',
32-
'The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ',
33-
'020 3299 9010',
34-
],
35-
[
36-
'Monday 1 May 2025',
37-
'1:56pm',
38-
"The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN",
39-
'020 3299 9010',
40-
],
22+
expect(csv.short).toEqual([
23+
'Wednesday 10 September 2025',
24+
'12:56pm',
25+
'City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH',
26+
'020 3299 9010',
27+
]);
28+
29+
expect(csv.medium).toEqual([
30+
'Saturday 10 April 2025',
31+
'11:56am',
32+
'The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ',
33+
'020 3299 9010',
34+
]);
35+
36+
expect(csv.long).toEqual([
37+
'Monday 1 May 2025',
38+
'1:56pm',
39+
"The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN",
40+
'020 3299 9010',
4141
]);
4242
});
4343

@@ -48,16 +48,22 @@ test('errors if parse is not called before reading personalisation', () => {
4848

4949
const csv = new TestDataCsv(file);
5050

51-
expect(() => csv.headers).toThrow('CSV has not been parsed');
52-
expect(() => csv.rows).toThrow('CSV has not been parsed');
51+
expect(() => csv.parameters).toThrow('CSV has not been parsed');
52+
expect(() => csv.short).toThrow('CSV has not been parsed');
53+
expect(() => csv.medium).toThrow('CSV has not been parsed');
54+
expect(() => csv.long).toThrow('CSV has not been parsed');
5355
});
5456

55-
test('errors if file cannot be parsed', async () => {
56-
const file = fs.readFileSync(
57-
path.resolve(__dirname, '../fixtures/custom-personalisation.pdf')
58-
);
57+
test.each([
58+
['not a csv', '../fixtures/custom-personalisation.pdf'],
59+
['wrong file headers', '../fixtures/wrong-headers.csv'],
60+
['badly ordered file headers', '../fixtures/wrong-header-order.csv'],
61+
['missing example', '../fixtures/missing-example.csv'],
62+
['missing parameter in example', '../fixtures/missing-parameter.csv'],
63+
])('errors if file cannot be parsed - %s', async (_title, filepath) => {
64+
const file = fs.readFileSync(path.resolve(__dirname, filepath));
5965

6066
const csv = new TestDataCsv(file);
6167

62-
expect(csv.parse).toThrow();
68+
expect(() => csv.parse()).toThrow();
6369
});

lambdas/backend-api/src/__tests__/templates/domain/validate-letter-template-files.test.ts

Lines changed: 8 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('pdf has no custom personalisation', () => {
6868
],
6969
});
7070

71-
const csv = mock<TestDataCsv>({ headers: [], rows: [] });
71+
const csv = mock<TestDataCsv>({ parameters: [] });
7272

7373
expect(validateLetterTemplateFiles(pdf, csv)).toBe(true);
7474
});
@@ -88,8 +88,7 @@ describe('pdf has no custom personalisation', () => {
8888
});
8989

9090
const csv = mock<TestDataCsv>({
91-
headers: ['parameter_1'],
92-
rows: [['value_1']],
91+
parameters: ['parameter_1'],
9392
});
9493

9594
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
@@ -135,8 +134,7 @@ describe('pdf with custom personalisation', () => {
135134
});
136135

137136
const csv = mock<TestDataCsv>({
138-
headers: [value],
139-
rows: [['value_1']],
137+
parameters: [value],
140138
});
141139

142140
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
@@ -158,8 +156,7 @@ describe('pdf with custom personalisation', () => {
158156
});
159157

160158
const csv = mock<TestDataCsv>({
161-
headers: ['parameter_2'],
162-
rows: [['value_2']],
159+
parameters: ['parameter_2'],
163160
});
164161

165162
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
@@ -180,8 +177,7 @@ describe('pdf with custom personalisation', () => {
180177
});
181178

182179
const csv = mock<TestDataCsv>({
183-
headers: ['parameter_1', 'parameter_2'],
184-
rows: [['value_1', 'value_2']],
180+
parameters: ['parameter_1', 'parameter_2'],
185181
});
186182

187183
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
@@ -202,8 +198,7 @@ describe('pdf with custom personalisation', () => {
202198
});
203199

204200
const csv = mock<TestDataCsv>({
205-
headers: ['parameter_2'],
206-
rows: [['value_2']],
201+
parameters: ['parameter_2'],
207202
});
208203

209204
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
@@ -224,52 +219,7 @@ describe('pdf with custom personalisation', () => {
224219
});
225220

226221
const csv = mock<TestDataCsv>({
227-
headers: ['fullName'],
228-
rows: [['example name']],
229-
});
230-
231-
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
232-
});
233-
234-
test('returns false if csv row contains too few values', () => {
235-
const pdf = mock<TemplatePdf>({
236-
customPersonalisationParameters: ['parameter_1'],
237-
addressLinePersonalisationParameters: [
238-
'address_line_1',
239-
'address_line_2',
240-
'address_line_3',
241-
'address_line_4',
242-
'address_line_5',
243-
'address_line_6',
244-
'address_line_7',
245-
],
246-
});
247-
248-
const csv = mock<TestDataCsv>({
249-
headers: ['parameter_1'],
250-
rows: [['value_1'], []],
251-
});
252-
253-
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
254-
});
255-
256-
test('returns false if csv row contains too many values', () => {
257-
const pdf = mock<TemplatePdf>({
258-
customPersonalisationParameters: ['parameter_1'],
259-
addressLinePersonalisationParameters: [
260-
'address_line_1',
261-
'address_line_2',
262-
'address_line_3',
263-
'address_line_4',
264-
'address_line_5',
265-
'address_line_6',
266-
'address_line_7',
267-
],
268-
});
269-
270-
const csv = mock<TestDataCsv>({
271-
headers: ['parameter_1'],
272-
rows: [['value_1'], ['value_2', 'value_3']],
222+
parameters: ['fullName'],
273223
});
274224

275225
expect(validateLetterTemplateFiles(pdf, csv)).toBe(false);
@@ -290,11 +240,7 @@ describe('pdf with custom personalisation', () => {
290240
});
291241

292242
const csv = mock<TestDataCsv>({
293-
headers: ['parameter_1', 'parameter_2'],
294-
rows: [
295-
['value_1', 'value_2'],
296-
['value_3', 'value_4'],
297-
],
243+
parameters: ['parameter_1', 'parameter_2'],
298244
});
299245

300246
expect(validateLetterTemplateFiles(pdf, csv)).toBe(true);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Personalisation field,Short length data example,Medium length data example,Long length data example
2+
appointment_date,Wednesday 10 September 2025,Saturday 10 April 2025
3+
appointment_time,12:56pm,11:56am
4+
appointment_location,"City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH","The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ"
5+
contact_telephone_number,020 3299 9010,020 3299 9010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Personalisation field,Short length data example,Medium length data example,Long length data example
2+
appointment_date,Wednesday 10 September 2025,Saturday 10 April 2025,Monday 1 May 2025
3+
appointment_time,12:56pm,11:56am,1:56pm
4+
appointment_location,"City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH","The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ","The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN"
5+
contact_telephone_number,,020 3299 9010,020 3299 9010
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
appointment_date,appointment_time,appointment_location,contact_telephone_number
2-
Wednesday 10 September 2025,12:56pm,"City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH",020 3299 9010
3-
Saturday 10 April 2025,11:56am,"The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ",020 3299 9010
4-
Monday 1 May 2025,1:56pm,"The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN",020 3299 9010
1+
Personalisation field,Short length data example,Medium length data example,Long length data example
2+
appointment_date,Wednesday 10 September 2025,Saturday 10 April 2025,Monday 1 May 2025
3+
appointment_time,12:56pm,11:56am,1:56pm
4+
appointment_location,"City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH","The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ","The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN"
5+
contact_telephone_number,020 3299 9010,020 3299 9010,020 3299 9010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Personalisation field,Long length data example,Medium length data example,Short length data example
2+
appointment_date,Wednesday 10 September 2025,Saturday 10 April 2025,Monday 1 May 2025
3+
appointment_time,12:56pm,11:56am,1:56pm
4+
appointment_location,"City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH","The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ","The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN"
5+
contact_telephone_number,020 3299 9010,020 3299 9010,020 3299 9010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
personalisation_field,example_1,example_2,example_3
2+
appointment_date,Wednesday 10 September 2025,Saturday 10 April 2025,Monday 1 May 2025
3+
appointment_time,12:56pm,11:56am,1:56pm
4+
appointment_location,"City, Sandwell & Walsall BSS, The Rosewood Centre, Sandwell & West Birmingham Hospitals NHS Trust, The Birmingham Treatment Centre, City Hospital, Dudley Road, Birmingham, B18 7QH","The Royal Shrewsbury Hospital, Breast Screening Office, Treatment Centre, Mytton Oak Road, Shrewsbury, SY3 8XQ","The Epping Breast Screening Unit, St Margaret's Hospital, The Plain, Epping, Essex, CM16 6TN"
5+
contact_telephone_number,020 3299 9010,020 3299 9010,020 3299 9010

0 commit comments

Comments
 (0)