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

Revert "feat: API changes for handling new submission_email location" #3606

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions api.planx.uk/modules/send/downloadApplicationFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 6 additions & 16 deletions api.planx.uk/modules/send/email/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ describe(`sending an application by email to a planning office`, () => {
data: {
teams: [
{
notifyPersonalisation: {
emailReplyToId: "abc123",
sendToEmail: "[email protected]",
},
sendToEmail: "[email protected]",
settings: { emailReplyToId: "abc123" },
},
],
},
Expand Down Expand Up @@ -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" },
},
],
},
Expand Down Expand Up @@ -204,13 +200,7 @@ describe(`downloading application data received by email`, () => {
name: "GetTeamEmailSettings",
matchOnVariables: false,
data: {
teams: [
{
notifyPersonalisation: {
sendToEmail: "[email protected]",
},
},
],
teams: [{ sendToEmail: "[email protected]" }],
},
variables: { slug: "southwark" },
});
Expand Down
19 changes: 7 additions & 12 deletions api.planx.uk/modules/send/email/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})`,
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions api.planx.uk/modules/send/email/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { EmailSubmissionNotifyConfig } from "../../../types.js";

interface GetTeamEmailSettings {
teams: {
notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string };
sendToEmail: string;
notifyPersonalisation: NotifyPersonalisation;
}[];
}

Expand All @@ -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
}
}
}
Expand All @@ -31,6 +32,7 @@ export async function getTeamEmailSettings(localAuthority: string) {
slug: localAuthority,
},
);

return response?.teams[0];
}

Expand Down
3 changes: 1 addition & 2 deletions e2e/tests/api-driven/src/globalHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/ui-driven/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const contextDefaults: Context = {
},
settings: {
homepage: "planx.uk",
submissionEmail: "[email protected]",
},
submissionEmail: "[email protected]",
},
};

Expand All @@ -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,
},
});
}
Expand Down
Loading