Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCM-7572: Implement delete template #234

Merged
merged 6 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/amplify/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ const attachPolicy = new PolicyStatement({
});

sendEmailLambda.addToRolePolicy(attachPolicy);

backend.data.resources.cfnResources.amplifyDynamoDbTables.TemplateStorage.timeToLiveAttribute =
{
attributeName: 'ttl',
enabled: true,
};
4 changes: 3 additions & 1 deletion frontend/amplify/data/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum TemplateType {
enum TemplateStatus {
NOT_YET_SUBMITTED = 'NOT_YET_SUBMITTED',
SUBMITTED = 'SUBMITTED',
DELETED = 'DELETED',
}

const templateTypes = [
Expand All @@ -21,16 +22,17 @@ const templateTypes = [
const templateStatuses = [
TemplateStatus.NOT_YET_SUBMITTED,
TemplateStatus.SUBMITTED,
TemplateStatus.DELETED,
] as const;

const TemplateStorageModel = {
id: a.string().required(),
templateType: a.ref('TemplateType').required(),
templateStatus: a.ref('TemplateStatus').required(),
version: a.integer().required(),
name: a.string().required(),
subject: a.string(),
message: a.string().required(),
ttl: a.integer(),
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
1 change: 0 additions & 1 deletion frontend/src/__tests__/app/copy-template/page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('CopyTemplatePage', () => {
it('should load page', async () => {
const template: EmailTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports[`CreateEmailTemplatePage should render CreateEmailTemplatePage 1`] = `
"subject": "",
"templateStatus": "NOT_YET_SUBMITTED",
"templateType": "EMAIL",
"version": 1,
}
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`CreateNHSAppTemplatePage should render CreateNHSAppTemplatePage 1`] = `
"name": "",
"templateStatus": "NOT_YET_SUBMITTED",
"templateType": "NHS_APP",
"version": 1,
}
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports[`CreateSMSTemplatePage should render CreateSMSTemplatePage 1`] = `
"name": "",
"templateStatus": "NOT_YET_SUBMITTED",
"templateType": "SMS",
"version": 1,
}
}
/>
Expand Down
90 changes: 90 additions & 0 deletions frontend/src/__tests__/app/delete-template/page.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* @jest-environment node
*/
import DeleteTemplatePage from '@app/delete-template/[templateId]/page';
import { DeleteTemplate } from '@forms/DeleteTemplate/DeleteTemplate';
import {
EmailTemplate,
TemplateType,
TemplateStatus,
} from 'nhs-notify-web-template-management-utils';
import { redirect } from 'next/navigation';
import { getTemplate } from '@utils/form-actions';

jest.mock('@utils/form-actions');
jest.mock('next/navigation');
jest.mock('@forms/DeleteTemplate/DeleteTemplate');

const redirectMock = jest.mocked(redirect);
const getTemplateMock = jest.mocked(getTemplate);

describe('PreviewEmailTemplatePage', () => {
beforeEach(jest.resetAllMocks);

it('should load page', async () => {
const state: EmailTemplate = {
id: 'template-id',
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
subject: 'template-subject-line',
message: 'template-message',
};

getTemplateMock.mockResolvedValueOnce(state);

const page = await DeleteTemplatePage({
params: {
templateId: 'template-id',
},
});

expect(page).toEqual(<DeleteTemplate template={state} />);
});

it('should redirect to invalid-template when no templateId is found', async () => {
await DeleteTemplatePage({
params: {
templateId: 'template-id',
},
});

expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});

test('should redirect to invalid-template when template is already submitted', async () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.SUBMITTED,
templateType: TemplateType.NHS_APP,
name: 'template-name',
message: 'template-message',
});

await DeleteTemplatePage({
params: {
templateId: 'template-id',
},
});

expect(redirectMock).toHaveBeenCalledWith('/invalid-template', 'replace');
});

test('should redirect to manage-templates when template is already deleted', async () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.DELETED,
templateType: TemplateType.NHS_APP,
name: 'template-name',
message: 'template-message',
});

await DeleteTemplatePage({
params: {
templateId: 'template-id',
},
});

expect(redirectMock).toHaveBeenCalledWith('/manage-templates', 'push');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const redirectMock = jest.mocked(redirect);

const initialState: EmailTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('EditNhsAppTemplatePage', () => {
test('page loads', async () => {
const state: NHSAppTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.NHS_APP,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'name',
Expand Down Expand Up @@ -62,7 +61,6 @@ describe('EditNhsAppTemplatePage', () => {
async (templateType) => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
version: 1,
templateType,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'name',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const redirectMock = jest.mocked(redirect);

const initialState: SMSTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.SMS,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('EmailTemplateSubmittedPage', () => {
id: 'template-id',
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.SUBMITTED,
version: 1,
name: 'template-name',
message: 'example',
subject: 'subject',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const manageTemplatesContent = content.pages.manageTemplates;
const mockTemplates: Template[] = [
{
id: '1',
version: 1,
templateType: TemplateType.NHS_APP,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'Template 1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('NhsAppTemplateSubmittedPage', () => {
id: 'template-id',
templateType: TemplateType.NHS_APP,
templateStatus: TemplateStatus.SUBMITTED,
version: 1,
name: 'template-name',
message: 'example',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('PreviewEmailTemplatePage', () => {
it('should load page', async () => {
const state: EmailTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -96,7 +95,6 @@ describe('PreviewEmailTemplatePage', () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('PreviewNhsAppTemplatePage', () => {
it('should load page', async () => {
const state: NHSAppTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.NHS_APP,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -84,7 +83,6 @@ describe('PreviewNhsAppTemplatePage', () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ describe('PreviewSMSTemplatePage', () => {
it('should load page', async () => {
const state: SMSTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.SMS,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -84,7 +83,6 @@ describe('PreviewSMSTemplatePage', () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('SubmitEmailTemplatePage', () => {
test('should load page', async () => {
const state = {
id: 'template-id',
version: 1,
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -104,7 +103,6 @@ describe('SubmitEmailTemplatePage', () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('SubmitNhsAppTemplatePage', () => {
test('should load page', async () => {
const state = {
id: 'template-id',
version: 1,
templateType: TemplateType.NHS_APP,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -91,7 +90,6 @@ describe('SubmitNhsAppTemplatePage', () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('SubmitSmsTemplatePage', () => {
test('should load page', async () => {
const state = {
id: 'template-id',
version: 1,
templateType: TemplateType.SMS,
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -92,7 +91,6 @@ describe('SubmitSmsTemplatePage', () => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
templateStatus: TemplateStatus.NOT_YET_SUBMITTED,
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('TextMessageTemplateSubmittedPage', () => {
id: 'template-id',
templateType: TemplateType.SMS,
templateStatus: TemplateStatus.SUBMITTED,
version: 1,
name: 'template-name',
message: 'example',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('ViewSubmittedEmailTemplatePage', () => {
it('should load page', async () => {
const state: SubmittedEmailTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.EMAIL,
templateStatus: TemplateStatus.SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -107,7 +106,6 @@ describe('ViewSubmittedEmailTemplatePage', () => {
async (value) => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('ViewSubmittedNHSAppTemplatePage', () => {
it('should load page', async () => {
const state: SubmittedNHSAppTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.NHS_APP,
templateStatus: TemplateStatus.SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -99,7 +98,6 @@ describe('ViewSubmittedNHSAppTemplatePage', () => {
async (value) => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ describe('ViewSubmittedSMSTemplatePage', () => {
it('should load page', async () => {
const state: SubmittedSMSTemplate = {
id: 'template-id',
version: 1,
templateType: TemplateType.SMS,
templateStatus: TemplateStatus.SUBMITTED,
name: 'template-name',
Expand Down Expand Up @@ -93,7 +92,6 @@ describe('ViewSubmittedSMSTemplatePage', () => {
async (value) => {
getTemplateMock.mockResolvedValueOnce({
id: 'template-id',
version: 1,
...value,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ test('submit form - validation error', async () => {
templateType: TemplateType.NHS_APP,
name: 'template-name',
message: 'template-message',
version: 1,
};

const response = await copyTemplateAction(
Expand Down Expand Up @@ -64,7 +63,6 @@ test('submit form - create email template from non-email template', async () =>
templateType: TemplateType.NHS_APP,
name: 'template-name',
message: 'template-message',
version: 1,
};

await copyTemplateAction(
Expand Down Expand Up @@ -102,7 +100,6 @@ test('submit form - create email template from email template', async () => {
name: 'template-name',
message: 'template-message',
subject: 'template-subject',
version: 1,
};

await copyTemplateAction(
Expand Down Expand Up @@ -138,7 +135,6 @@ test('submit form - create non-email template', async () => {
templateType: TemplateType.NHS_APP,
name: 'template-name',
message: 'template-message',
version: 1,
};

await copyTemplateAction(
Expand Down
Loading
Loading