diff --git a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts index d44a73dd40..aede2c8369 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 { sendToEmail } = await getTeamEmailSettings( + const { notifyPersonalisation } = await getTeamEmailSettings( req.query.localAuthority as string, ); - if (sendToEmail !== req.query.email) { + if (notifyPersonalisation.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 6c19f24386..5338507a11 100644 --- a/api.planx.uk/modules/send/email/index.test.ts +++ b/api.planx.uk/modules/send/email/index.test.ts @@ -49,8 +49,10 @@ describe(`sending an application by email to a planning office`, () => { data: { teams: [ { - sendToEmail: "planning.office.example@council.gov.uk", - settings: { emailReplyToId: "abc123" }, + notifyPersonalisation: { + emailReplyToId: "abc123", + sendToEmail: "planning.office.example@council.gov.uk", + }, }, ], }, @@ -145,15 +147,17 @@ describe(`sending an application by email to a planning office`, () => { }); }); - it("errors if this team does not have a 'submission_email' configured in teams", async () => { + it("errors if this team does not have a 'submission_email' configured in team settings", async () => { queryMock.mockQuery({ name: "GetTeamEmailSettings", matchOnVariables: false, data: { teams: [ { - sendToEmail: null, - settings: { emailReplyToId: "abc123" }, + notifyPersonalisation: { + emailReplyToId: "abc123", + sendToEmail: null, + }, }, ], }, @@ -200,7 +204,13 @@ describe(`downloading application data received by email`, () => { name: "GetTeamEmailSettings", matchOnVariables: false, data: { - teams: [{ sendToEmail: "planning.office.example@council.gov.uk" }], + teams: [ + { + notifyPersonalisation: { + 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 20dfc83fd3..d1784564c7 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -27,10 +27,11 @@ export async function sendToEmail( } try { - // Confirm this local authority (aka team) has an email configured in teams.submission_email - const { sendToEmail, notifyPersonalisation } = + // Confirm this local authority (aka team) has an email configured in team_settings.submission_email + const { notifyPersonalisation } = await getTeamEmailSettings(localAuthority); - if (!sendToEmail) { + + if (!notifyPersonalisation.sendToEmail) { return next({ status: 400, message: `Send to email is not enabled for this local authority (${localAuthority})`, @@ -47,13 +48,17 @@ export async function sendToEmail( serviceName: flowName, sessionId: payload.sessionId, applicantEmail: email, - downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${sendToEmail}&localAuthority=${localAuthority}`, + downloadLink: `${process.env.API_URL_EXT}/download-application-files/${payload.sessionId}?email=${notifyPersonalisation.sendToEmail}&localAuthority=${localAuthority}`, ...notifyPersonalisation, }, }; // Send the email - const response = await sendEmail("submit", sendToEmail, config); + const response = await sendEmail( + "submit", + notifyPersonalisation.sendToEmail, + config, + ); // Mark session as submitted so that reminder and expiry emails are not triggered markSessionAsSubmitted(payload.sessionId); @@ -62,14 +67,14 @@ export async function sendToEmail( insertAuditEntry( payload.sessionId, localAuthority, - sendToEmail, + notifyPersonalisation.sendToEmail, config, response, ); return res.status(200).send({ message: `Successfully sent to email`, - inbox: sendToEmail, + inbox: notifyPersonalisation.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 e5b1776be4..2f8660db8d 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -8,8 +8,7 @@ import { EmailSubmissionNotifyConfig } from "../../../types.js"; interface GetTeamEmailSettings { teams: { - sendToEmail: string; - notifyPersonalisation: NotifyPersonalisation; + notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string }; }[]; } @@ -18,12 +17,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 } } } @@ -32,7 +31,6 @@ 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 88a0cafcb9..ee54a6e9f9 100644 --- a/e2e/tests/api-driven/src/globalHelpers.ts +++ b/e2e/tests/api-driven/src/globalHelpers.ts @@ -8,9 +8,10 @@ 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 7f08ccf25f..3ef2a4f3cf 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, }, }); }