Skip to content

Commit ce133f3

Browse files
CCM-8579: Misc
1 parent 4fa5b19 commit ce133f3

File tree

19 files changed

+138
-148
lines changed

19 files changed

+138
-148
lines changed

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
"@aws-amplify/adapter-nextjs": "^1.4.3",
2222
"@aws-amplify/ui-react": "^6.9.1",
2323
"@aws-sdk/client-ses": "^3.637.0",
24-
"clsx": "^2.1.1",
2524
"aws-amplify": "^6.12.3",
25+
"clsx": "^2.1.1",
2626
"date-fns": "^4.1.0",
2727
"jsonwebtoken": "^9.0.2",
2828
"jwt-decode": "^4.0.0",
2929
"markdown-it": "^13.0.1",
3030
"mimetext": "^3.0.24",
3131
"next": "^15.1.7",
3232
"next-client-cookies": "^2.0.1",
33+
"nhs-notify-backend-client": "*",
3334
"nhs-notify-web-template-management-utils": "*",
3435
"nhsuk-frontend": "^9.1.0",
3536
"nhsuk-react-components": "^5.0.0",

frontend/src/__tests__/app/preview-text-message-template/page.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('PreviewSMSTemplatePage', () => {
8080
message: null as unknown as string,
8181
},
8282
])(
83-
'should redirect to invalid-template when template is $templateType and name is $smsTemplateName and message is $smsTemplateMessage',
83+
'should redirect to invalid-template when template is $templateType and name is $name and message is $message',
8484
async (value) => {
8585
getTemplateMock.mockResolvedValueOnce(value);
8686

frontend/src/__tests__/components/forms/CopyTemplate/CopyTemplate.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { mockDeep } from 'jest-mock-extended';
55
import { render, screen, fireEvent } from '@testing-library/react';
66
import { CopyTemplate, ValidCopyType } from '@forms/CopyTemplate/CopyTemplate';
77
import { TemplateFormState } from 'nhs-notify-web-template-management-utils';
8-
import { TemplateDto } from 'nhs-notify-backend-client';
8+
import { ValidatedTemplateDto } from 'nhs-notify-backend-client';
99

1010
jest.mock('@utils/amplify-utils');
1111

@@ -32,7 +32,9 @@ describe('Choose template page', () => {
3232
it('selects one radio button at a time', () => {
3333
const container = render(
3434
<CopyTemplate
35-
template={mockDeep<TemplateDto & { templateType: ValidCopyType }>()}
35+
template={mockDeep<
36+
ValidatedTemplateDto & { templateType: ValidCopyType }
37+
>()}
3638
/>
3739
);
3840
expect(container.asFragment()).toMatchSnapshot();
@@ -82,7 +84,9 @@ describe('Choose template page', () => {
8284

8385
const container = render(
8486
<CopyTemplate
85-
template={mockDeep<TemplateDto & { templateType: ValidCopyType }>()}
87+
template={mockDeep<
88+
ValidatedTemplateDto & { templateType: ValidCopyType }
89+
>()}
8690
/>
8791
);
8892
expect(container.asFragment()).toMatchSnapshot();

frontend/src/__tests__/utils/form-actions.test.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,29 +283,14 @@ describe('form-actions', () => {
283283
{ ...baseTemplate, id: '08', createdAt: '2020-01-01T00:00:00.000Z' },
284284
{ ...baseTemplate, id: '05', createdAt: '2021-01-01T00:00:00.000Z' },
285285
{ ...baseTemplate, id: '02', createdAt: '2021-01-01T00:00:00.000Z' },
286-
{ ...baseTemplate, id: '09', createdAt: '' },
287-
{ ...baseTemplate, id: '10', createdAt: '' },
288286
{ ...baseTemplate, id: '01', createdAt: '2021-01-01T00:00:00.000Z' },
289-
{ ...baseTemplate, id: '07', createdAt: '' },
290287
{ ...baseTemplate, id: '03', createdAt: '2021-01-01T00:00:00.000Z' },
291288
{ ...baseTemplate, id: '04', createdAt: '2021-01-01T00:00:00.000Z' },
292289
];
293290

294291
// 06 is the newest, 08 is the oldest.
295-
// Templates without a createdAt, 07, 09 and 10, go at the end.
296292
// 01 - 05 all have the same createdAt.
297-
const expectedOrder = [
298-
'06',
299-
'01',
300-
'02',
301-
'03',
302-
'04',
303-
'05',
304-
'08',
305-
'07',
306-
'09',
307-
'10',
308-
];
293+
const expectedOrder = ['06', '01', '02', '03', '04', '05', '08'];
309294

310295
mockedTemplateClient.listTemplates.mockResolvedValueOnce({
311296
data: templates,

frontend/src/components/forms/CopyTemplate/CopyTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { templateTypeDisplayMappings } from 'nhs-notify-web-template-management-
99
import { getBasePath } from '@utils/get-base-path';
1010
import { NHSNotifyMain } from '@atoms/NHSNotifyMain/NHSNotifyMain';
1111
import { copyTemplateAction } from './server-action';
12-
import { TemplateDto, TemplateType } from 'nhs-notify-backend-client';
12+
import { TemplateType, ValidatedTemplateDto } from 'nhs-notify-backend-client';
1313

1414
export type ValidCopyType = Exclude<TemplateType, 'LETTER'>;
1515

1616
type CopyTemplate = {
17-
template: TemplateDto & { templateType: ValidCopyType };
17+
template: ValidatedTemplateDto & { templateType: ValidCopyType };
1818
};
1919

2020
export const CopyTemplate = ({ template }: CopyTemplate) => {

frontend/src/components/forms/CopyTemplate/server-action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { createTemplate } from '@utils/form-actions';
77
import { format } from 'date-fns/format';
88
import {
99
TEMPLATE_TYPE_LIST,
10-
TemplateDto,
1110
TemplateType,
11+
ValidatedTemplateDto,
1212
} from 'nhs-notify-backend-client';
1313

1414
const [firstType, ...remainingTypes] = TEMPLATE_TYPE_LIST;
@@ -20,7 +20,7 @@ const $CopyTemplate = z.object({
2020
});
2121

2222
type CopyTemplateActionState = FormState & {
23-
template: TemplateDto & {
23+
template: ValidatedTemplateDto & {
2424
templateType: Exclude<TemplateType, 'LETTER'>;
2525
};
2626
};

frontend/src/utils/form-actions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
CreateTemplate,
66
isTemplateDtoValid,
77
TemplateDto,
8+
ValidatedTemplateDto,
89
} from 'nhs-notify-backend-client';
910
import { logger } from 'nhs-notify-web-template-management-utils/logger';
1011
import { TemplateClient } from 'nhs-notify-backend-client/src/template-api-client';
@@ -84,7 +85,9 @@ export async function getTemplates(): Promise<TemplateDto[]> {
8485

8586
const sortedData = data
8687
.map((template) => isTemplateDtoValid(template))
87-
.filter((template): template is TemplateDto => template !== undefined)
88+
.filter(
89+
(template): template is ValidatedTemplateDto => template !== undefined
90+
)
8891
.sort((a, b) => {
8992
const aCreatedAt = a.createdAt;
9093
const bCreatedAt = b.createdAt;

infrastructure/terraform/modules/backend-api/spec.tmpl.json

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,7 @@
479479
{
480480
"$ref": "#/components/schemas/LetterProperties"
481481
}
482-
],
483-
"discriminator": {
484-
"propertyName": "templateType",
485-
"mapping": {
486-
"NHS_APP": "#/components/schemas/NhsAppProperties",
487-
"EMAIL": "#/components/schemas/EmailProperties",
488-
"SMS": "#/components/schemas/SmsProperties",
489-
"LETTER": "#/components/schemas/LetterProperties"
490-
}
491-
}
482+
]
492483
}
493484
]
494485
},
@@ -523,16 +514,7 @@
523514
{
524515
"$ref": "#/components/schemas/LetterProperties"
525516
}
526-
],
527-
"discriminator": {
528-
"propertyName": "templateType",
529-
"mapping": {
530-
"NHS_APP": "#/components/schemas/NhsAppProperties",
531-
"EMAIL": "#/components/schemas/EmailProperties",
532-
"SMS": "#/components/schemas/SmsProperties",
533-
"LETTER": "#/components/schemas/LetterProperties"
534-
}
535-
}
517+
]
536518
}
537519
]
538520
},
@@ -581,16 +563,7 @@
581563
{
582564
"$ref": "#/components/schemas/LetterProperties"
583565
}
584-
],
585-
"discriminator": {
586-
"propertyName": "templateType",
587-
"mapping": {
588-
"NHS_APP": "#/components/schemas/NhsAppProperties",
589-
"EMAIL": "#/components/schemas/EmailProperties",
590-
"SMS": "#/components/schemas/SmsProperties",
591-
"LETTER": "#/components/schemas/LetterProperties"
592-
}
593-
}
566+
]
594567
}
595568
]
596569
},

lambdas/backend-api/src/__tests__/templates/infra/template-repository.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
LetterProperties,
1313
NhsAppProperties,
1414
SmsProperties,
15-
UpdateTemplate,
15+
ValidatedUpdateTemplate,
1616
} from 'nhs-notify-backend-client';
1717
import { ConditionalCheckFailedException } from '@aws-sdk/client-dynamodb';
1818
import { DatabaseTemplate, templateRepository } from '../../../templates/infra';
@@ -420,7 +420,7 @@ describe('templateRepository', () => {
420420
])(
421421
'should update template of type $templateType with name',
422422
async (channelProperties) => {
423-
const updatedTemplate: UpdateTemplate = {
423+
const updatedTemplate: ValidatedUpdateTemplate = {
424424
...channelProperties,
425425
...updateTemplateProperties,
426426
name: 'updated-name',
@@ -457,7 +457,7 @@ describe('templateRepository', () => {
457457
);
458458

459459
test('should update template to deleted state', async () => {
460-
const updatedTemplate: UpdateTemplate = {
460+
const updatedTemplate: ValidatedUpdateTemplate = {
461461
name: 'updated-name',
462462
message: 'updated-message',
463463
templateStatus: 'DELETED',

lambdas/backend-api/src/templates/infra/template-repository.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
NhsAppProperties,
88
SmsProperties,
99
UpdateTemplate,
10+
ValidatedUpdateTemplate,
1011
} from 'nhs-notify-backend-client';
1112
import {
1213
ConditionalCheckFailedException,
@@ -191,7 +192,7 @@ const attributeValuesFromMapAndTemplate = <T>(
191192
return attributeValues;
192193
};
193194

194-
const getChannelAttributeValues = (template: UpdateTemplate) => {
195+
const getChannelAttributeValues = (template: ValidatedUpdateTemplate) => {
195196
let values = {};
196197

197198
if (template.templateType === 'NHS_APP') {
@@ -224,7 +225,7 @@ const getChannelAttributeValues = (template: UpdateTemplate) => {
224225

225226
const update = async (
226227
templateId: string,
227-
template: UpdateTemplate,
228+
template: ValidatedUpdateTemplate,
228229
owner: string
229230
): Promise<ApplicationResult<DatabaseTemplate>> => {
230231
const updateExpression = [

0 commit comments

Comments
 (0)