From de310066b8391bddaa0103457171dee91b6d078f Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Tue, 27 Aug 2024 15:50:51 +0100 Subject: [PATCH 1/8] init api changes --- api.planx.uk/modules/send/email/index.test.ts | 19 +++---- api.planx.uk/modules/send/email/index.ts | 6 +-- api.planx.uk/modules/send/email/service.ts | 14 +++--- e2e/tests/api-driven/src/globalHelpers.ts | 15 +++--- e2e/tests/ui-driven/src/context.ts | 50 +++++++++---------- 5 files changed, 53 insertions(+), 51 deletions(-) diff --git a/api.planx.uk/modules/send/email/index.test.ts b/api.planx.uk/modules/send/email/index.test.ts index 6c19f24386..6cbe6c7a5f 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" }, + settings: { + emailReplyToId: "abc123", + sendToEmail: "planning.office.example@council.gov.uk", + }, }, ], }, @@ -145,15 +147,14 @@ 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" }, + settings: { emailReplyToId: "abc123", sendToEmail: null }, }, ], }, @@ -229,7 +230,7 @@ describe(`downloading application data received by email`, () => { it("errors if email query param does not match the stored database value for this team", async () => { await supertest(app) .get( - "/download-application-files/123?email=wrong@council.gov.uk&localAuthority=southwark", + "/download-application-files/123?email=wrong@council.gov.uk&localAuthority=southwark" ) .expect(403) .then((res) => { @@ -251,12 +252,12 @@ describe(`downloading application data received by email`, () => { await supertest(app) .get( - "/download-application-files/456?email=planning.office.example@council.gov.uk&localAuthority=southwark", + "/download-application-files/456?email=planning.office.example@council.gov.uk&localAuthority=southwark" ) .expect(400) .then((res) => { expect(res.body.error).toMatch( - /Failed to find session data for this sessionId/, + /Failed to find session data for this sessionId/ ); }); }); @@ -264,7 +265,7 @@ describe(`downloading application data received by email`, () => { it("calls addTemplateFilesToZip()", async () => { await supertest(app) .get( - "/download-application-files/123?email=planning.office.example@council.gov.uk&localAuthority=southwark", + "/download-application-files/123?email=planning.office.example@council.gov.uk&localAuthority=southwark" ) .expect(200) .then((_res) => { diff --git a/api.planx.uk/modules/send/email/index.ts b/api.planx.uk/modules/send/email/index.ts index 20dfc83fd3..0a20c801ec 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -11,7 +11,7 @@ import { export async function sendToEmail( req: Request, res: Response, - next: NextFunction, + next: NextFunction ) { req.setTimeout(120 * 1000); // Temporary bump to address submission timeouts @@ -27,7 +27,7 @@ export async function sendToEmail( } try { - // Confirm this local authority (aka team) has an email configured in teams.submission_email + // Confirm this local authority (aka team) has an email configured in team_settings.submission_email const { sendToEmail, notifyPersonalisation } = await getTeamEmailSettings(localAuthority); if (!sendToEmail) { @@ -64,7 +64,7 @@ export async function sendToEmail( localAuthority, sendToEmail, config, - response, + response ); return res.status(200).send({ diff --git a/api.planx.uk/modules/send/email/service.ts b/api.planx.uk/modules/send/email/service.ts index e5b1776be4..4988f2ef2e 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -18,19 +18,19 @@ 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 } } } `, { slug: localAuthority, - }, + } ); return response?.teams[0]; @@ -51,7 +51,7 @@ export async function getSessionData(sessionId: string) { `, { id: sessionId, - }, + } ); return response?.session?.data; @@ -82,12 +82,12 @@ export async function getSessionEmailDetailsById(sessionId: string) { `, { id: sessionId, - }, + } ); if (!response.session) throw Error( - `Cannot find session ${sessionId} in GetSessionEmailDetails query`, + `Cannot find session ${sessionId} in GetSessionEmailDetails query` ); return response.session; @@ -107,7 +107,7 @@ export async function insertAuditEntry( sendEmailResponse: { message: string; expiryDate?: string; - }, + } ) { const response = await $api.client.request( gql` @@ -137,7 +137,7 @@ export async function insertAuditEntry( recipient: recipient, request: notifyRequest, response: sendEmailResponse, - }, + } ); return response?.application?.id; diff --git a/e2e/tests/api-driven/src/globalHelpers.ts b/e2e/tests/api-driven/src/globalHelpers.ts index 88a0cafcb9..cd5aafefa4 100644 --- a/e2e/tests/api-driven/src/globalHelpers.ts +++ b/e2e/tests/api-driven/src/globalHelpers.ts @@ -2,23 +2,24 @@ import { TEST_EMAIL } from "../../ui-driven/src/globalHelpers"; import { $admin } from "./client"; export function createTeam( - args?: Partial[0]>, + args?: Partial[0]> ) { return safely(() => $admin.team.create({ name: "E2E Test Team", slug: "E2E", - submissionEmail: TEST_EMAIL, + settings: { homepage: "http://www.planx.uk", + submissionEmail: TEST_EMAIL, }, ...args, - }), + }) ); } export function createUser( - args?: Partial[0]>, + args?: Partial[0]> ) { return safely(() => $admin.user.create({ @@ -26,18 +27,18 @@ export function createUser( lastName: "Test", email: TEST_EMAIL, ...args, - }), + }) ); } export function createFlow( - args: Omit[0], "data">, + args: Omit[0], "data"> ) { return safely(() => $admin.flow.create({ data: { dummy: "flowData " }, ...args, - }), + }) ); } diff --git a/e2e/tests/ui-driven/src/context.ts b/e2e/tests/ui-driven/src/context.ts index 7f08ccf25f..2fb5a30c51 100644 --- a/e2e/tests/ui-driven/src/context.ts +++ b/e2e/tests/ui-driven/src/context.ts @@ -41,13 +41,13 @@ export const contextDefaults: Context = { }, settings: { homepage: "planx.uk", + submissionEmail: "simulate-delivered@notifications.service.gov.uk", }, - submissionEmail: "simulate-delivered@notifications.service.gov.uk", }, }; export async function setUpTestContext( - initialContext: Context, + initialContext: Context ): Promise { const $admin = getCoreDomainClient(); const context: Context = { ...initialContext }; @@ -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, }, }); } @@ -117,7 +117,7 @@ export function generateAuthenticationToken(userId: string) { "x-hasura-user-id": `${userId}`, }, }, - process.env.JWT_SECRET, + process.env.JWT_SECRET ); } @@ -127,7 +127,7 @@ export function getCoreDomainClient(): CoreDomainClient { const API = process.env.HASURA_GRAPHQL_URL!.replace( "${HASURA_PROXY_PORT}", - process.env.HASURA_PROXY_PORT!, + process.env.HASURA_PROXY_PORT! ); const SECRET = process.env.HASURA_GRAPHQL_ADMIN_SECRET!; return new CoreDomainClient({ @@ -142,7 +142,7 @@ export function getGraphQLClient(): GraphQLClient { export async function findSessionId( adminGQLClient: GraphQLClient, - context, + context ): Promise { // get the flow id which may have a session const flowResponse: { flows: { id: string }[] } = @@ -152,7 +152,7 @@ export async function findSessionId( id } }`, - { slug: context.flow?.slug }, + { slug: context.flow?.slug } ); if (!flowResponse.flows.length || !flowResponse.flows[0].id) { return; @@ -172,7 +172,7 @@ export async function findSessionId( } } `, - { flowId, email: context.user?.email }, + { flowId, email: context.user?.email } ); if (response.lowcal_sessions.length && response.lowcal_sessions[0].id) { return response.lowcal_sessions[0].id; @@ -188,7 +188,7 @@ async function deleteSession(adminGQLClient: GraphQLClient, context) { id } }`, - { sessionId }, + { sessionId } ); } } @@ -201,14 +201,14 @@ async function deleteSession(adminGQLClient: GraphQLClient, context) { id } }`, - { sessionId }, + { sessionId } ); } } async function deletePublishedFlow( adminGQLClient: GraphQLClient, - context: Context, + context: Context ) { if (context.flow?.publishedId) { log(`deleting published flow ${context.flow?.publishedId}`); @@ -218,7 +218,7 @@ async function deletePublishedFlow( id } }`, - { publishedFlowId: context.flow?.publishedId }, + { publishedFlowId: context.flow?.publishedId } ); } } @@ -232,7 +232,7 @@ async function deleteFlow(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { flowId: context.flow?.id }, + { flowId: context.flow?.id } ); } else if (context.flow?.slug) { // try deleting via slug (when cleaning up from a previously failed test) @@ -242,11 +242,11 @@ async function deleteFlow(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { slug: context.flow?.slug }, + { slug: context.flow?.slug } ); if (response.flows.length && response.flows[0].id) { log( - `deleting flow ${context.flow?.slug} flowId: ${response.flows[0].id}`, + `deleting flow ${context.flow?.slug} flowId: ${response.flows[0].id}` ); await adminGQLClient.request( `mutation DeleteTestFlow( $flowId: uuid!) { @@ -254,7 +254,7 @@ async function deleteFlow(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { flowId: response.flows[0].id }, + { flowId: response.flows[0].id } ); } } @@ -269,7 +269,7 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { userId: context.user?.id }, + { userId: context.user?.id } ); } else if (context.user?.email) { // try deleting via email (when cleaning up from a previously failed test) @@ -279,11 +279,11 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { email: context.user?.email }, + { email: context.user?.email } ); if (response.users.length && response.users[0].id) { log( - `deleting user ${context.user?.email} userId: ${response.users[0].id}`, + `deleting user ${context.user?.email} userId: ${response.users[0].id}` ); await adminGQLClient.request( `mutation DeleteTestUser($userId: Int!) { @@ -291,7 +291,7 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { userId: response.users[0].id }, + { userId: response.users[0].id } ); } } @@ -306,7 +306,7 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { teamId: context.team?.id }, + { teamId: context.team?.id } ); } else if (context.team?.slug) { // try deleting via slug (when cleaning up from a previously failed test) @@ -316,11 +316,11 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { slug: context.team?.slug }, + { slug: context.team?.slug } ); if (response.teams.length && response.teams[0].id) { log( - `deleting team ${context.team?.slug} teamId: ${response.teams[0].id}`, + `deleting team ${context.team?.slug} teamId: ${response.teams[0].id}` ); await adminGQLClient.request( `mutation DeleteTestTeam( $teamId: Int!) { @@ -328,7 +328,7 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { teamId: response.teams[0].id }, + { teamId: response.teams[0].id } ); } } @@ -353,7 +353,7 @@ async function setupGovPaySecret($admin: CoreDomainClient, context: Context) { { team_id: context.team.id, staging_govpay_secret: process.env.GOV_UK_PAY_SECRET_E2E, - }, + } ); } catch (error) { throw Error("Failed to setup GovPay secret for E2E team"); From 718e01192548b53162320a09a1e17d5caf755f28 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Wed, 28 Aug 2024 14:25:47 +0100 Subject: [PATCH 2/8] lint fix api files --- api.planx.uk/modules/send/email/index.ts | 4 ++-- api.planx.uk/modules/send/email/service.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/api.planx.uk/modules/send/email/index.ts b/api.planx.uk/modules/send/email/index.ts index 0a20c801ec..ce4f5578c1 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -11,7 +11,7 @@ import { export async function sendToEmail( req: Request, res: Response, - next: NextFunction + next: NextFunction, ) { req.setTimeout(120 * 1000); // Temporary bump to address submission timeouts @@ -64,7 +64,7 @@ export async function sendToEmail( localAuthority, sendToEmail, config, - response + response, ); return res.status(200).send({ diff --git a/api.planx.uk/modules/send/email/service.ts b/api.planx.uk/modules/send/email/service.ts index 4988f2ef2e..c3de8e8fa7 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -30,7 +30,7 @@ export async function getTeamEmailSettings(localAuthority: string) { `, { slug: localAuthority, - } + }, ); return response?.teams[0]; @@ -51,7 +51,7 @@ export async function getSessionData(sessionId: string) { `, { id: sessionId, - } + }, ); return response?.session?.data; @@ -82,12 +82,12 @@ export async function getSessionEmailDetailsById(sessionId: string) { `, { id: sessionId, - } + }, ); if (!response.session) throw Error( - `Cannot find session ${sessionId} in GetSessionEmailDetails query` + `Cannot find session ${sessionId} in GetSessionEmailDetails query`, ); return response.session; @@ -107,7 +107,7 @@ export async function insertAuditEntry( sendEmailResponse: { message: string; expiryDate?: string; - } + }, ) { const response = await $api.client.request( gql` @@ -137,7 +137,7 @@ export async function insertAuditEntry( recipient: recipient, request: notifyRequest, response: sendEmailResponse, - } + }, ); return response?.application?.id; From 0dbd0a849ea7ddab1ba48c43c0d4d5ec8a042d97 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 29 Aug 2024 14:28:32 +0100 Subject: [PATCH 3/8] alter getTeamEmailSettings to pull from new column --- api.planx.uk/modules/send/email/index.ts | 18 ++++++++++++------ api.planx.uk/modules/send/email/service.ts | 17 +++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/api.planx.uk/modules/send/email/index.ts b/api.planx.uk/modules/send/email/index.ts index ce4f5578c1..ecdbc153eb 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -11,7 +11,7 @@ import { export async function sendToEmail( req: Request, res: Response, - next: NextFunction, + next: NextFunction ) { req.setTimeout(120 * 1000); // Temporary bump to address submission timeouts @@ -27,10 +27,12 @@ export async function sendToEmail( } try { + console.log("before getEmailSettings..."); // Confirm this local authority (aka team) has an email configured in team_settings.submission_email - const { sendToEmail, notifyPersonalisation } = + 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})`, @@ -53,7 +55,11 @@ export async function sendToEmail( }; // 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,9 +68,9 @@ export async function sendToEmail( insertAuditEntry( payload.sessionId, localAuthority, - sendToEmail, + notifyPersonalisation.sendToEmail, config, - response, + response ); return res.status(200).send({ diff --git a/api.planx.uk/modules/send/email/service.ts b/api.planx.uk/modules/send/email/service.ts index c3de8e8fa7..bcd96a96be 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -9,11 +9,12 @@ import { EmailSubmissionNotifyConfig } from "../../../types.js"; interface GetTeamEmailSettings { teams: { sendToEmail: string; - notifyPersonalisation: NotifyPersonalisation; + notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string }; }[]; } export async function getTeamEmailSettings(localAuthority: string) { + console.log("inside getEmailSettings..."); const response = await $api.client.request( gql` query GetTeamEmailSettings($slug: String) { @@ -30,9 +31,9 @@ export async function getTeamEmailSettings(localAuthority: string) { `, { slug: localAuthority, - }, + } ); - + console.log(response?.teams[0]); return response?.teams[0]; } @@ -51,7 +52,7 @@ export async function getSessionData(sessionId: string) { `, { id: sessionId, - }, + } ); return response?.session?.data; @@ -82,12 +83,12 @@ export async function getSessionEmailDetailsById(sessionId: string) { `, { id: sessionId, - }, + } ); if (!response.session) throw Error( - `Cannot find session ${sessionId} in GetSessionEmailDetails query`, + `Cannot find session ${sessionId} in GetSessionEmailDetails query` ); return response.session; @@ -107,7 +108,7 @@ export async function insertAuditEntry( sendEmailResponse: { message: string; expiryDate?: string; - }, + } ) { const response = await $api.client.request( gql` @@ -137,7 +138,7 @@ export async function insertAuditEntry( recipient: recipient, request: notifyRequest, response: sendEmailResponse, - }, + } ); return response?.application?.id; From 72fb6fdddcb3113112c7e34724756c2cfba7b00c Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 29 Aug 2024 16:18:44 +0100 Subject: [PATCH 4/8] fix api tests --- api.planx.uk/modules/send/email/index.test.ts | 7 +++++-- api.planx.uk/modules/send/email/index.ts | 5 ++--- api.planx.uk/modules/send/email/service.ts | 3 --- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/api.planx.uk/modules/send/email/index.test.ts b/api.planx.uk/modules/send/email/index.test.ts index 6cbe6c7a5f..4490086b59 100644 --- a/api.planx.uk/modules/send/email/index.test.ts +++ b/api.planx.uk/modules/send/email/index.test.ts @@ -49,7 +49,7 @@ describe(`sending an application by email to a planning office`, () => { data: { teams: [ { - settings: { + notifyPersonalisation: { emailReplyToId: "abc123", sendToEmail: "planning.office.example@council.gov.uk", }, @@ -154,7 +154,10 @@ describe(`sending an application by email to a planning office`, () => { data: { teams: [ { - settings: { emailReplyToId: "abc123", sendToEmail: null }, + notifyPersonalisation: { + emailReplyToId: "abc123", + sendToEmail: null, + }, }, ], }, diff --git a/api.planx.uk/modules/send/email/index.ts b/api.planx.uk/modules/send/email/index.ts index ecdbc153eb..a9cdf6a450 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -27,7 +27,6 @@ export async function sendToEmail( } try { - console.log("before getEmailSettings..."); // Confirm this local authority (aka team) has an email configured in team_settings.submission_email const { notifyPersonalisation } = await getTeamEmailSettings(localAuthority); @@ -49,7 +48,7 @@ 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, }, }; @@ -75,7 +74,7 @@ export async function sendToEmail( 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 bcd96a96be..91947bb6a8 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -8,13 +8,11 @@ import { EmailSubmissionNotifyConfig } from "../../../types.js"; interface GetTeamEmailSettings { teams: { - sendToEmail: string; notifyPersonalisation: NotifyPersonalisation & { sendToEmail: string }; }[]; } export async function getTeamEmailSettings(localAuthority: string) { - console.log("inside getEmailSettings..."); const response = await $api.client.request( gql` query GetTeamEmailSettings($slug: String) { @@ -33,7 +31,6 @@ export async function getTeamEmailSettings(localAuthority: string) { slug: localAuthority, } ); - console.log(response?.teams[0]); return response?.teams[0]; } From de2d5e826565c800042071a1a70f6e3449822ece Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 29 Aug 2024 16:29:01 +0100 Subject: [PATCH 5/8] tidy sendEmail ts change --- .../modules/send/downloadApplicationFiles/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts index d44a73dd40..0d4e6f5fce 100644 --- a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts +++ b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts @@ -5,7 +5,7 @@ import { getSessionData, getTeamEmailSettings } from "../email/service.js"; export async function downloadApplicationFiles( req: Request, res: Response, - next: NextFunction, + next: NextFunction ) { const sessionId: string = req.params?.sessionId; if (!sessionId || !req.query?.email || !req.query?.localAuthority) { @@ -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( - req.query.localAuthority as string, + 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: From 3ed6729c6ac0fe4d0fa901b80afaf281e143564a Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 29 Aug 2024 16:34:58 +0100 Subject: [PATCH 6/8] update query mocks --- api.planx.uk/modules/send/email/index.test.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api.planx.uk/modules/send/email/index.test.ts b/api.planx.uk/modules/send/email/index.test.ts index 4490086b59..ce6b0fb584 100644 --- a/api.planx.uk/modules/send/email/index.test.ts +++ b/api.planx.uk/modules/send/email/index.test.ts @@ -204,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" }, }); From 477ec971cc669071d61cd5a9c4af490689eda49b Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 29 Aug 2024 16:38:02 +0100 Subject: [PATCH 7/8] lint fixing --- .../modules/send/downloadApplicationFiles/index.ts | 4 ++-- api.planx.uk/modules/send/email/index.test.ts | 8 ++++---- api.planx.uk/modules/send/email/index.ts | 6 +++--- api.planx.uk/modules/send/email/service.ts | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts index 0d4e6f5fce..aede2c8369 100644 --- a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts +++ b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts @@ -5,7 +5,7 @@ import { getSessionData, getTeamEmailSettings } from "../email/service.js"; export async function downloadApplicationFiles( req: Request, res: Response, - next: NextFunction + next: NextFunction, ) { const sessionId: string = req.params?.sessionId; if (!sessionId || !req.query?.email || !req.query?.localAuthority) { @@ -18,7 +18,7 @@ export async function downloadApplicationFiles( try { // Confirm that the provided email matches the stored team settings for the provided localAuthority const { notifyPersonalisation } = await getTeamEmailSettings( - req.query.localAuthority as string + req.query.localAuthority as string, ); if (notifyPersonalisation.sendToEmail !== req.query.email) { return next({ diff --git a/api.planx.uk/modules/send/email/index.test.ts b/api.planx.uk/modules/send/email/index.test.ts index ce6b0fb584..5338507a11 100644 --- a/api.planx.uk/modules/send/email/index.test.ts +++ b/api.planx.uk/modules/send/email/index.test.ts @@ -239,7 +239,7 @@ describe(`downloading application data received by email`, () => { it("errors if email query param does not match the stored database value for this team", async () => { await supertest(app) .get( - "/download-application-files/123?email=wrong@council.gov.uk&localAuthority=southwark" + "/download-application-files/123?email=wrong@council.gov.uk&localAuthority=southwark", ) .expect(403) .then((res) => { @@ -261,12 +261,12 @@ describe(`downloading application data received by email`, () => { await supertest(app) .get( - "/download-application-files/456?email=planning.office.example@council.gov.uk&localAuthority=southwark" + "/download-application-files/456?email=planning.office.example@council.gov.uk&localAuthority=southwark", ) .expect(400) .then((res) => { expect(res.body.error).toMatch( - /Failed to find session data for this sessionId/ + /Failed to find session data for this sessionId/, ); }); }); @@ -274,7 +274,7 @@ describe(`downloading application data received by email`, () => { it("calls addTemplateFilesToZip()", async () => { await supertest(app) .get( - "/download-application-files/123?email=planning.office.example@council.gov.uk&localAuthority=southwark" + "/download-application-files/123?email=planning.office.example@council.gov.uk&localAuthority=southwark", ) .expect(200) .then((_res) => { diff --git a/api.planx.uk/modules/send/email/index.ts b/api.planx.uk/modules/send/email/index.ts index a9cdf6a450..d1784564c7 100644 --- a/api.planx.uk/modules/send/email/index.ts +++ b/api.planx.uk/modules/send/email/index.ts @@ -11,7 +11,7 @@ import { export async function sendToEmail( req: Request, res: Response, - next: NextFunction + next: NextFunction, ) { req.setTimeout(120 * 1000); // Temporary bump to address submission timeouts @@ -57,7 +57,7 @@ export async function sendToEmail( const response = await sendEmail( "submit", notifyPersonalisation.sendToEmail, - config + config, ); // Mark session as submitted so that reminder and expiry emails are not triggered @@ -69,7 +69,7 @@ export async function sendToEmail( localAuthority, notifyPersonalisation.sendToEmail, config, - response + response, ); return res.status(200).send({ diff --git a/api.planx.uk/modules/send/email/service.ts b/api.planx.uk/modules/send/email/service.ts index 91947bb6a8..2f8660db8d 100644 --- a/api.planx.uk/modules/send/email/service.ts +++ b/api.planx.uk/modules/send/email/service.ts @@ -29,7 +29,7 @@ export async function getTeamEmailSettings(localAuthority: string) { `, { slug: localAuthority, - } + }, ); return response?.teams[0]; } @@ -49,7 +49,7 @@ export async function getSessionData(sessionId: string) { `, { id: sessionId, - } + }, ); return response?.session?.data; @@ -80,12 +80,12 @@ export async function getSessionEmailDetailsById(sessionId: string) { `, { id: sessionId, - } + }, ); if (!response.session) throw Error( - `Cannot find session ${sessionId} in GetSessionEmailDetails query` + `Cannot find session ${sessionId} in GetSessionEmailDetails query`, ); return response.session; @@ -105,7 +105,7 @@ export async function insertAuditEntry( sendEmailResponse: { message: string; expiryDate?: string; - } + }, ) { const response = await $api.client.request( gql` @@ -135,7 +135,7 @@ export async function insertAuditEntry( recipient: recipient, request: notifyRequest, response: sendEmailResponse, - } + }, ); return response?.application?.id; From f5d3f493f1a9e84fa0d84502f7c193b3ea3022f7 Mon Sep 17 00:00:00 2001 From: Rory Doak Date: Thu, 29 Aug 2024 16:45:33 +0100 Subject: [PATCH 8/8] lint fix e2e --- e2e/tests/api-driven/src/globalHelpers.ts | 12 +++--- e2e/tests/ui-driven/src/context.ts | 46 +++++++++++------------ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/e2e/tests/api-driven/src/globalHelpers.ts b/e2e/tests/api-driven/src/globalHelpers.ts index cd5aafefa4..ee54a6e9f9 100644 --- a/e2e/tests/api-driven/src/globalHelpers.ts +++ b/e2e/tests/api-driven/src/globalHelpers.ts @@ -2,7 +2,7 @@ import { TEST_EMAIL } from "../../ui-driven/src/globalHelpers"; import { $admin } from "./client"; export function createTeam( - args?: Partial[0]> + args?: Partial[0]>, ) { return safely(() => $admin.team.create({ @@ -14,12 +14,12 @@ export function createTeam( submissionEmail: TEST_EMAIL, }, ...args, - }) + }), ); } export function createUser( - args?: Partial[0]> + args?: Partial[0]>, ) { return safely(() => $admin.user.create({ @@ -27,18 +27,18 @@ export function createUser( lastName: "Test", email: TEST_EMAIL, ...args, - }) + }), ); } export function createFlow( - args: Omit[0], "data"> + args: Omit[0], "data">, ) { return safely(() => $admin.flow.create({ data: { dummy: "flowData " }, ...args, - }) + }), ); } diff --git a/e2e/tests/ui-driven/src/context.ts b/e2e/tests/ui-driven/src/context.ts index 2fb5a30c51..3ef2a4f3cf 100644 --- a/e2e/tests/ui-driven/src/context.ts +++ b/e2e/tests/ui-driven/src/context.ts @@ -47,7 +47,7 @@ export const contextDefaults: Context = { }; export async function setUpTestContext( - initialContext: Context + initialContext: Context, ): Promise { const $admin = getCoreDomainClient(); const context: Context = { ...initialContext }; @@ -117,7 +117,7 @@ export function generateAuthenticationToken(userId: string) { "x-hasura-user-id": `${userId}`, }, }, - process.env.JWT_SECRET + process.env.JWT_SECRET, ); } @@ -127,7 +127,7 @@ export function getCoreDomainClient(): CoreDomainClient { const API = process.env.HASURA_GRAPHQL_URL!.replace( "${HASURA_PROXY_PORT}", - process.env.HASURA_PROXY_PORT! + process.env.HASURA_PROXY_PORT!, ); const SECRET = process.env.HASURA_GRAPHQL_ADMIN_SECRET!; return new CoreDomainClient({ @@ -142,7 +142,7 @@ export function getGraphQLClient(): GraphQLClient { export async function findSessionId( adminGQLClient: GraphQLClient, - context + context, ): Promise { // get the flow id which may have a session const flowResponse: { flows: { id: string }[] } = @@ -152,7 +152,7 @@ export async function findSessionId( id } }`, - { slug: context.flow?.slug } + { slug: context.flow?.slug }, ); if (!flowResponse.flows.length || !flowResponse.flows[0].id) { return; @@ -172,7 +172,7 @@ export async function findSessionId( } } `, - { flowId, email: context.user?.email } + { flowId, email: context.user?.email }, ); if (response.lowcal_sessions.length && response.lowcal_sessions[0].id) { return response.lowcal_sessions[0].id; @@ -188,7 +188,7 @@ async function deleteSession(adminGQLClient: GraphQLClient, context) { id } }`, - { sessionId } + { sessionId }, ); } } @@ -201,14 +201,14 @@ async function deleteSession(adminGQLClient: GraphQLClient, context) { id } }`, - { sessionId } + { sessionId }, ); } } async function deletePublishedFlow( adminGQLClient: GraphQLClient, - context: Context + context: Context, ) { if (context.flow?.publishedId) { log(`deleting published flow ${context.flow?.publishedId}`); @@ -218,7 +218,7 @@ async function deletePublishedFlow( id } }`, - { publishedFlowId: context.flow?.publishedId } + { publishedFlowId: context.flow?.publishedId }, ); } } @@ -232,7 +232,7 @@ async function deleteFlow(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { flowId: context.flow?.id } + { flowId: context.flow?.id }, ); } else if (context.flow?.slug) { // try deleting via slug (when cleaning up from a previously failed test) @@ -242,11 +242,11 @@ async function deleteFlow(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { slug: context.flow?.slug } + { slug: context.flow?.slug }, ); if (response.flows.length && response.flows[0].id) { log( - `deleting flow ${context.flow?.slug} flowId: ${response.flows[0].id}` + `deleting flow ${context.flow?.slug} flowId: ${response.flows[0].id}`, ); await adminGQLClient.request( `mutation DeleteTestFlow( $flowId: uuid!) { @@ -254,7 +254,7 @@ async function deleteFlow(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { flowId: response.flows[0].id } + { flowId: response.flows[0].id }, ); } } @@ -269,7 +269,7 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { userId: context.user?.id } + { userId: context.user?.id }, ); } else if (context.user?.email) { // try deleting via email (when cleaning up from a previously failed test) @@ -279,11 +279,11 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { email: context.user?.email } + { email: context.user?.email }, ); if (response.users.length && response.users[0].id) { log( - `deleting user ${context.user?.email} userId: ${response.users[0].id}` + `deleting user ${context.user?.email} userId: ${response.users[0].id}`, ); await adminGQLClient.request( `mutation DeleteTestUser($userId: Int!) { @@ -291,7 +291,7 @@ async function deleteUser(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { userId: response.users[0].id } + { userId: response.users[0].id }, ); } } @@ -306,7 +306,7 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { teamId: context.team?.id } + { teamId: context.team?.id }, ); } else if (context.team?.slug) { // try deleting via slug (when cleaning up from a previously failed test) @@ -316,11 +316,11 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { slug: context.team?.slug } + { slug: context.team?.slug }, ); if (response.teams.length && response.teams[0].id) { log( - `deleting team ${context.team?.slug} teamId: ${response.teams[0].id}` + `deleting team ${context.team?.slug} teamId: ${response.teams[0].id}`, ); await adminGQLClient.request( `mutation DeleteTestTeam( $teamId: Int!) { @@ -328,7 +328,7 @@ async function deleteTeam(adminGQLClient: GraphQLClient, context: Context) { id } }`, - { teamId: response.teams[0].id } + { teamId: response.teams[0].id }, ); } } @@ -353,7 +353,7 @@ async function setupGovPaySecret($admin: CoreDomainClient, context: Context) { { team_id: context.team.id, staging_govpay_secret: process.env.GOV_UK_PAY_SECRET_E2E, - } + }, ); } catch (error) { throw Error("Failed to setup GovPay secret for E2E team");