Skip to content

Commit f67c939

Browse files
committed
Merge branch 'main' of https://github.com/NHSDigital/nhs-notify-web-template-management into feature/CCM-11352_test-template-events
2 parents 6ca6cb3 + 0c241a2 commit f67c939

File tree

5 files changed

+3
-112
lines changed

5 files changed

+3
-112
lines changed

lambdas/backend-client/src/__tests__/schemas/template-schema.test.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,6 @@ describe('Template schemas', () => {
212212
);
213213
});
214214

215-
test.each([
216-
'<element>failed</element>',
217-
'<element><nested>nested</nested></element>',
218-
'<element attribute="failed">failed</element>',
219-
])(
220-
'App template fields - should fail validation, when invalid characters are present %p',
221-
async (message) => {
222-
const result = $CreateUpdateTemplate.safeParse({
223-
name: 'Test Template',
224-
message,
225-
templateType: 'NHS_APP',
226-
});
227-
228-
expect(result.error?.flatten()).toEqual(
229-
expect.objectContaining({
230-
fieldErrors: {
231-
message: [
232-
'Message contains disallowed characters. Disallowed characters: <(.|\n)*?>',
233-
],
234-
},
235-
})
236-
);
237-
}
238-
);
239-
240215
describe('$CreateUpdateTemplate', () => {
241216
const commonFields = {
242217
name: 'Test Template',

lambdas/backend-client/src/schemas/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* Allowed character length and disallowed characters for NHS App, Email and SMS templates
2+
* Allowed character length for NHS App, Email and SMS templates
3+
* (app disallowed characters are handled by html encoding)
34
* https://digital.nhs.uk/developer/api-catalogue/nhs-app#post-/communication/in-app/FHIR/R4/CommunicationRequest
45
* https://digital.nhs.uk/developer/api-catalogue/nhs-notify#overview--message-character-limits
56
*/
6-
export const NHS_APP_DISALLOWED_CHARACTERS = '<(.|\n)*?>' as const;
77
export const MAX_NHS_APP_CHARACTER_LENGTH = 5000 as const;
88
export const MAX_SMS_CHARACTER_LENGTH = 918 as const;
99
export const MAX_EMAIL_CHARACTER_LENGTH = 100_000 as const;

lambdas/backend-client/src/schemas/template-schema.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
MAX_EMAIL_CHARACTER_LENGTH,
1717
MAX_NHS_APP_CHARACTER_LENGTH,
1818
MAX_SMS_CHARACTER_LENGTH,
19-
NHS_APP_DISALLOWED_CHARACTERS,
2019
} from './constants';
2120
import { schemaFor } from './schema-for';
2221
import {
@@ -68,15 +67,7 @@ export const $EmailProperties = schemaFor<EmailProperties>()(
6867
export const $NhsAppProperties = schemaFor<NhsAppProperties>()(
6968
z.object({
7069
templateType: z.literal('NHS_APP'),
71-
message: z
72-
.string()
73-
.trim()
74-
.min(1)
75-
.max(MAX_NHS_APP_CHARACTER_LENGTH)
76-
// eslint-disable-next-line security/detect-non-literal-regexp
77-
.refine((s) => !new RegExp(NHS_APP_DISALLOWED_CHARACTERS, 'gi').test(s), {
78-
message: `Message contains disallowed characters. Disallowed characters: ${NHS_APP_DISALLOWED_CHARACTERS}`,
79-
}),
70+
message: z.string().trim().min(1).max(MAX_NHS_APP_CHARACTER_LENGTH),
8071
})
8172
);
8273

tests/test-team/template-mgmt-api-tests/create-template.api.spec.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -315,34 +315,6 @@ test.describe('POST /v1/template', () => {
315315
},
316316
});
317317
});
318-
319-
test('returns 400 if template has message disallowed characters', async ({
320-
request,
321-
}) => {
322-
const response = await request.post(
323-
`${process.env.API_BASE_URL}/v1/template`,
324-
{
325-
headers: {
326-
Authorization: await user1.getAccessToken(),
327-
},
328-
data: TemplateAPIPayloadFactory.getCreateTemplatePayload({
329-
templateType: 'NHS_APP',
330-
message: '<>',
331-
}),
332-
}
333-
);
334-
335-
expect(response.status()).toBe(400);
336-
337-
expect(await response.json()).toEqual({
338-
statusCode: 400,
339-
technicalMessage: 'Request failed validation',
340-
details: {
341-
message:
342-
'Message contains disallowed characters. Disallowed characters: <(.|\n)*?>',
343-
},
344-
});
345-
});
346318
});
347319

348320
test.describe('SMS templates', () => {

tests/test-team/template-mgmt-api-tests/update-template.api.spec.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -776,53 +776,6 @@ test.describe('POST /v1/template/:templateId', () => {
776776
technicalMessage: 'Request failed validation',
777777
});
778778
});
779-
780-
test('returns 400 if template message has disallowed characters', async ({
781-
request,
782-
}) => {
783-
const createResponse = await request.post(
784-
`${process.env.API_BASE_URL}/v1/template`,
785-
{
786-
headers: {
787-
Authorization: await user1.getAccessToken(),
788-
},
789-
data: TemplateAPIPayloadFactory.getCreateTemplatePayload({
790-
templateType: 'NHS_APP',
791-
}),
792-
}
793-
);
794-
795-
expect(createResponse.status()).toBe(201);
796-
const created = await createResponse.json();
797-
templateStorageHelper.addAdHocTemplateKey({
798-
templateId: created.template.id,
799-
clientId: user1.clientId,
800-
});
801-
802-
const updateResponse = await request.post(
803-
`${process.env.API_BASE_URL}/v1/template/${created.template.id}`,
804-
{
805-
headers: {
806-
Authorization: await user1.getAccessToken(),
807-
},
808-
data: TemplateAPIPayloadFactory.getUpdateTemplatePayload({
809-
templateType: 'NHS_APP',
810-
message: '<>',
811-
}),
812-
}
813-
);
814-
815-
expect(updateResponse.status()).toBe(400);
816-
817-
expect(await updateResponse.json()).toEqual({
818-
details: {
819-
message:
820-
'Message contains disallowed characters. Disallowed characters: <(.|\n)*?>',
821-
},
822-
statusCode: 400,
823-
technicalMessage: 'Request failed validation',
824-
});
825-
});
826779
});
827780

828781
test.describe('SMS templates', () => {

0 commit comments

Comments
 (0)