From 761f5c2a6b7c9053ddde343e0c0b2fbee0f2471f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Sat, 31 Aug 2024 09:51:40 +0100 Subject: [PATCH] Revert "feat: API changes for handling new `submission_email` location (#3582)" This reverts commit b27369d92e3ca3c8c11b7e2424f7b912e79a6779. --- .../send/downloadApplicationFiles/index.ts | 4 ++-- api.planx.uk/modules/send/email/index.test.ts | 22 +++++-------------- api.planx.uk/modules/send/email/index.ts | 19 ++++++---------- api.planx.uk/modules/send/email/service.ts | 6 +++-- e2e/tests/api-driven/src/globalHelpers.ts | 3 +-- e2e/tests/ui-driven/src/context.ts | 4 ++-- 6 files changed, 22 insertions(+), 36 deletions(-) diff --git a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts index aede2c8369..d44a73dd40 100644 --- a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts +++ b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts @@ -17,10 +17,10 @@ export async function downloadApplicationFiles( try { // Confirm that the provided email matches the stored team settings for the provided localAuthority - const { notifyPersonalisation } = await getTeamEmailSettings( + const { sendToEmail } = await getTeamEmailSettings( req.query.localAuthority as string, ); - if (notifyPersonalisation.sendToEmail !== req.query.email) { + if (sendToEmail !== req.query.email) { return next({ status: 403, message: diff --git a/api.planx.uk/modules/send/email/index.test.ts b/api.planx.uk/modules/send/email/index.test.ts index 5338507a11..6c19f24386 100644 --- a/api.planx.uk/modules/send/email/index.test.ts +++ b/api.planx.uk/modules/send/email/index.test.ts @@ -49,10 +49,8 @@ describe(`sending an application by email to a planning office`, () => { data: { teams: [ { - notifyPersonalisation: { - emailReplyToId: "abc123", - sendToEmail: "planning.office.example@council.gov.uk", - }, + sendToEmail: "planning.office.example@council.gov.uk", + settings: { emailReplyToId: "abc123" }, }, ], }, @@ -147,17 +145,15 @@ describe(`sending an application by email to a planning office`, () => { }); }); - it("errors if this team does not have a 'submission_email' configured in team settings", async () => { + it("errors if this team does not have a 'submission_email' configured in teams", async () => { queryMock.mockQuery({ name: "GetTeamEmailSettings", matchOnVariables: false, data: { teams: [ { - notifyPersonalisation: { - emailReplyToId: "abc123", - sendToEmail: null, - }, + sendToEmail: null, + settings: { emailReplyToId: "abc123" }, }, ], }, @@ -204,13 +200,7 @@ describe(`downloading application data received by email`, () => { name: "GetTeamEmailSettings", matchOnVariables: false, data: { - teams: [ - { - notifyPersonalisation: { - sendToEmail: "planning.office.example@council.gov.uk", - }, - }, - ], + teams: [{ sendToEmail: "planning.office.example@council.gov.uk" }], }, variables: { slug: "southwark" }, }); diff --git a/api.planx.uk/modules/send/email/index.ts b/api.planx.uk/modules/send/email/index.ts index d1784564c7..20dfc83fd3 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -27,11 +27,10 @@ export async function sendToEmail( } try { - // Confirm this local authority (aka team) has an email configured in team_settings.submission_email - const { notifyPersonalisation } = + // Confirm this local authority (aka team) has an email configured in teams.submission_email + const { sendToEmail, notifyPersonalisation } = await getTeamEmailSettings(localAuthority); - - if (!notifyPersonalisation.sendToEmail) { + if (!sendToEmail) { return next({ status: 400, message: `Send to email is not enabled for this local authority (${localAuthority})`, @@ -48,17 +47,13 @@ export async function sendToEmail( serviceName: flowName, sessionId: payload.sessionId, applicantEmail: email, - downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${notifyPersonalisation.sendToEmail}&localAuthority=${localAuthority}`, + downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${sendToEmail}&localAuthority=${localAuthority}`, ...notifyPersonalisation, }, }; // Send the email - const response = await sendEmail( - "submit", - notifyPersonalisation.sendToEmail, - config, - ); + const response = await sendEmail("submit", sendToEmail, config); // Mark session as submitted so that reminder and expiry emails are not triggered markSessionAsSubmitted(payload.sessionId); @@ -67,14 +62,14 @@ export async function sendToEmail( insertAuditEntry( payload.sessionId, localAuthority, - notifyPersonalisation.sendToEmail, + sendToEmail, config, response, ); return res.status(200).send({ message: `Successfully sent to email`, - inbox: notifyPersonalisation.sendToEmail, + inbox: sendToEmail, govuk_notify_template: "Submit", }); } catch (error) { diff --git a/api.planx.uk/modules/send/email/service.ts b/api.planx.uk/modules/send/email/service.ts index 2f8660db8d..e5b1776be4 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -8,7 +8,8 @@ import { EmailSubmissionNotifyConfig } from "../../../types.js"; interface GetTeamEmailSettings { teams: { - notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string }; + sendToEmail: string; + notifyPersonalisation: NotifyPersonalisation; }[]; } @@ -17,12 +18,12 @@ export async function getTeamEmailSettings(localAuthority: string) { gql` query GetTeamEmailSettings($slug: String) { teams(where: { slug: { _eq: $slug } }) { + sendToEmail: submission_email notifyPersonalisation: team_settings { helpEmail: help_email helpPhone: help_phone emailReplyToId: email_reply_to_id helpOpeningHours: help_opening_hours - sendToEmail: submission_email } } } @@ -31,6 +32,7 @@ export async function getTeamEmailSettings(localAuthority: string) { slug: localAuthority, }, ); + return response?.teams[0]; } diff --git a/e2e/tests/api-driven/src/globalHelpers.ts b/e2e/tests/api-driven/src/globalHelpers.ts index ee54a6e9f9..88a0cafcb9 100644 --- a/e2e/tests/api-driven/src/globalHelpers.ts +++ b/e2e/tests/api-driven/src/globalHelpers.ts @@ -8,10 +8,9 @@ export function createTeam( $admin.team.create({ name: "E2E Test Team", slug: "E2E", - + submissionEmail: TEST_EMAIL, settings: { homepage: "http://www.planx.uk", - submissionEmail: TEST_EMAIL, }, ...args, }), diff --git a/e2e/tests/ui-driven/src/context.ts b/e2e/tests/ui-driven/src/context.ts index 3ef2a4f3cf..7f08ccf25f 100644 --- a/e2e/tests/ui-driven/src/context.ts +++ b/e2e/tests/ui-driven/src/context.ts @@ -41,8 +41,8 @@ export const contextDefaults: Context = { }, settings: { homepage: "planx.uk", - submissionEmail: "simulate-delivered@notifications.service.gov.uk", }, + submissionEmail: "simulate-delivered@notifications.service.gov.uk", }, }; @@ -58,9 +58,9 @@ export async function setUpTestContext( context.team.id = await $admin.team.create({ slug: context.team.slug, name: context.team.name, + submissionEmail: context.team.submissionEmail, settings: { homepage: context.team.settings?.homepage, - submissionEmail: context.team.submissionEmail, }, }); }