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

Production deploy #3404

Merged
merged 13 commits into from
Jul 12, 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
8 changes: 6 additions & 2 deletions .github/workflows/pizza-teardown-manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
inputs:
pull_request_id:
required: true
type: integer
type: number
description: Pull Request number which should have its pizza destroyed

env:
Expand All @@ -20,4 +20,8 @@ jobs:
action: destroy
api_key: ${{ secrets.VULTR_API_KEY }}
domain: ${{ env.DOMAIN }}
pullrequest_id: ${{ github.event.inputs.pull_request_id }}
os_type: alpine
plan: vc2-1c-1gb
pull_request_id: ${{ github.event.inputs.pull_request_id }}
region: lhr
tag: manual-teardown
9 changes: 2 additions & 7 deletions api.planx.uk/modules/admin/session/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@ import {
GovUKPayment,
PaymentRequest,
Session,
Team,
} from "@opensystemslab/planx-core/types";
import { NextFunction, Request, Response } from "express";
import { gql } from "graphql-request";

import {
Breadcrumb,
Flow,
LowCalSession,
Passport,
Team,
} from "../../../types";
import { Breadcrumb, Flow, LowCalSession, Passport } from "../../../types";
import { $api } from "../../../client";

/**
Expand Down
3 changes: 2 additions & 1 deletion api.planx.uk/modules/flows/moveFlow/service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { gql } from "graphql-request";
import { Flow, Team } from "../../../types";
import { Flow } from "../../../types";
import { $public, getClient } from "../../../client";
import { Team } from "@opensystemslab/planx-core/types";

export const moveFlow = async (flowId: string, teamSlug: string) => {
const team = await $public.team.getBySlug(teamSlug);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentType } from "@opensystemslab/planx-core/types";
import { ComponentType, Team } from "@opensystemslab/planx-core/types";
import { NextFunction, Request, Response } from "express";
import { gql } from "graphql-request";
import {
Expand All @@ -7,7 +7,7 @@ import {
} from "../../../../lib/hasura/metadata";
import { $api, $public } from "../../../../client";
import { getMostRecentPublishedFlow } from "../../../../helpers";
import { Flow, Node, Team } from "../../../../types";
import { Flow, Node } from "../../../../types";

enum Destination {
BOPS = "bops",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { $public, $api } from "../../../../client";
import { sendEmail } from "../../../../lib/notify";
import { gql } from "graphql-request";
import { convertSlugToName } from "../../../saveAndReturn/service/utils";
import type { AgentAndPayeeSubmissionNotifyConfig } from "../../../../types";

export async function sendAgentAndPayeeConfirmationEmail(sessionId: string) {
Expand Down Expand Up @@ -47,7 +46,12 @@ async function getDataForPayeeAndAgentEmails(
flow {
slug
team {
notifyPersonalisation: notify_personalisation
notifyPersonalisation: team_settings {
helpEmail: help_email
helpPhone: help_phone
emailReplyToId: email_reply_to_id
helpOpeningHours: help_opening_hours
}
}
}
paymentRequests: payment_requests(
Expand Down
60 changes: 34 additions & 26 deletions api.planx.uk/modules/pay/service/inviteToPay/sendPaymentEmail.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { gql } from "graphql-request";
import {
calculateExpiryDate,
convertSlugToName,
getServiceLink,
} from "../../../saveAndReturn/service/utils";
import {
Expand All @@ -10,8 +9,7 @@ import {
sendEmail,
} from "../../../../lib/notify";
import { InviteToPayNotifyConfig } from "../../../../types";
import { Team } from "../../../../types";
import type { PaymentRequest } from "@opensystemslab/planx-core/types";
import type { PaymentRequest, Team } from "@opensystemslab/planx-core/types";
import { $public } from "../../../../client";

interface SessionDetails {
Expand Down Expand Up @@ -76,7 +74,7 @@ const validatePaymentRequest = async (
name
slug
domain
notifyPersonalisation: notify_personalisation
settings: team_settings
}
}
}
Expand Down Expand Up @@ -109,28 +107,38 @@ const validatePaymentRequest = async (
const getInviteToPayNotifyConfig = async (
session: SessionDetails,
paymentRequest: PaymentRequest,
): Promise<InviteToPayNotifyConfig> => ({
personalisation: {
...session.flow.team.notifyPersonalisation,
sessionId: paymentRequest.sessionId,
paymentRequestId: paymentRequest.id,
payeeEmail: paymentRequest.payeeEmail,
payeeName: paymentRequest.payeeName,
agentName: paymentRequest.applicantName,
address: (
paymentRequest.sessionPreviewData?._address as Record<"title", string>
).title,
fee: getFee(paymentRequest),
projectType:
(await $public.formatRawProjectTypes(
paymentRequest.sessionPreviewData?.["proposal.projectType"] as string[],
)) || "Project type not submitted",
serviceName: session.flow.name,
serviceLink: getServiceLink(session.flow.team, session.flow.slug),
expiryDate: calculateExpiryDate(paymentRequest.createdAt),
paymentLink: getPaymentLink(session, paymentRequest),
},
});
): Promise<InviteToPayNotifyConfig> => {
const flow = session.flow;
const { settings } = session.flow.team;

return {
personalisation: {
helpEmail: settings.helpEmail,
helpPhone: settings.helpPhone,
emailReplyToId: settings.emailReplyToId,
helpOpeningHours: settings.helpOpeningHours,
sessionId: paymentRequest.sessionId,
paymentRequestId: paymentRequest.id,
payeeEmail: paymentRequest.payeeEmail,
payeeName: paymentRequest.payeeName,
agentName: paymentRequest.applicantName,
address: (
paymentRequest.sessionPreviewData?._address as Record<"title", string>
).title,
fee: getFee(paymentRequest),
projectType:
(await $public.formatRawProjectTypes(
paymentRequest.sessionPreviewData?.[
"proposal.projectType"
] as string[],
)) || "Project type not submitted",
serviceName: session.flow.name,
serviceLink: getServiceLink(flow.team, flow.slug),
expiryDate: calculateExpiryDate(paymentRequest.createdAt),
paymentLink: getPaymentLink(session, paymentRequest),
},
};
};

const getFee = (paymentRequest: PaymentRequest) => {
const toPounds = (pence: number) => pence / 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LowCalSession, Team } from "../../../types";
import { LowCalSession } from "../../../types";
import supertest from "supertest";
import app from "../../../server";
import { queryMock } from "../../../tests/graphqlQueryMock";
Expand All @@ -8,6 +8,7 @@ import {
} from "../../../tests/mocks/saveAndReturnMocks";
import { buildContentFromSessions } from "./resumeApplication";
import { PartialDeep } from "type-fest";
import { Team } from "@opensystemslab/planx-core/types";

const ENDPOINT = "/resume-application";
const TEST_EMAIL = "[email protected]";
Expand Down Expand Up @@ -54,7 +55,7 @@ describe("buildContentFromSessions function", () => {
},
];

const result = `Service: Apply for a lawful development certificate
const result = `Service: Apply for a Lawful Development Certificate
Address: 1 High Street
Project type: New office premises
Expiry Date: 29 May 2026
Expand Down Expand Up @@ -124,15 +125,15 @@ describe("buildContentFromSessions function", () => {
},
},
];
const result = `Service: Apply for a lawful development certificate
const result = `Service: Apply for a Lawful Development Certificate
Address: 1 High Street
Project type: New office premises
Expiry Date: 29 May 2026
Link: example.com/team/apply-for-a-lawful-development-certificate/published?sessionId=123\n\nService: Apply for a lawful development certificate
Link: example.com/team/apply-for-a-lawful-development-certificate/published?sessionId=123\n\nService: Apply for a Lawful Development Certificate
Address: 2 High Street
Project type: New office premises
Expiry Date: 29 May 2026
Link: example.com/team/apply-for-a-lawful-development-certificate/published?sessionId=456\n\nService: Apply for a lawful development certificate
Link: example.com/team/apply-for-a-lawful-development-certificate/published?sessionId=456\n\nService: Apply for a Lawful Development Certificate
Address: 3 High Street
Project type: New office premises
Expiry Date: 29 May 2026
Expand Down Expand Up @@ -184,7 +185,7 @@ describe("buildContentFromSessions function", () => {
},
},
];
const result = `Service: Apply for a lawful development certificate
const result = `Service: Apply for a Lawful Development Certificate
Address: 1 High Street
Project type: New office premises
Expiry Date: 29 May 2026
Expand Down Expand Up @@ -217,7 +218,7 @@ describe("buildContentFromSessions function", () => {
},
];

const result = `Service: Apply for a lawful development certificate
const result = `Service: Apply for a Lawful Development Certificate
Address: Address not submitted
Project type: New office premises
Expiry Date: 29 May 2026
Expand Down Expand Up @@ -252,7 +253,7 @@ describe("buildContentFromSessions function", () => {
},
];

const result = `Service: Apply for a lawful development certificate
const result = `Service: Apply for a Lawful Development Certificate
Address: 1 High Street
Project type: Project type not submitted
Expiry Date: 29 May 2026
Expand Down
23 changes: 10 additions & 13 deletions api.planx.uk/modules/saveAndReturn/service/resumeApplication.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import type { SiteAddress } from "@opensystemslab/planx-core/types";
import type { SiteAddress, Team } from "@opensystemslab/planx-core/types";
import { differenceInDays } from "date-fns";
import { gql } from "graphql-request";
import { $api, $public } from "../../../client";
import { sendEmail } from "../../../lib/notify";
import { LowCalSession, Team } from "../../../types";
import {
DAYS_UNTIL_EXPIRY,
calculateExpiryDate,
convertSlugToName,
getResumeLink,
} from "./utils";
import { LowCalSession } from "../../../types";
import { DAYS_UNTIL_EXPIRY, calculateExpiryDate, getResumeLink } from "./utils";

/**
* Send a "Resume" email to an applicant which list all open applications for a given council (team)
Expand All @@ -22,7 +17,7 @@ const resumeApplication = async (teamSlug: string, email: string) => {
const config = {
personalisation: await getPersonalisation(sessions, team),
reference: null,
emailReplyToId: team.notifyPersonalisation.emailReplyToId,
emailReplyToId: team.settings.emailReplyToId,
};
const response = await sendEmail("resume", email, config);
return response;
Expand Down Expand Up @@ -69,7 +64,7 @@ const validateRequest = async (
teams(where: { slug: { _eq: $teamSlug } }) {
slug
name
notifyPersonalisation: notify_personalisation
settings: team_settings
domain
}
}
Expand Down Expand Up @@ -98,7 +93,10 @@ const getPersonalisation = async (sessions: LowCalSession[], team: Team) => {
return {
teamName: team.name,
content: await buildContentFromSessions(sessions, team),
...team.notifyPersonalisation,
helpEmail: team.settings.helpEmail,
helpPhone: team.settings.helpPhone,
helpOpeningHours: team.settings.helpOpeningHours,
emailReplyToId: team.settings.emailReplyToId,
};
};

Expand All @@ -111,7 +109,6 @@ const buildContentFromSessions = async (
team: Team,
): Promise<string> => {
const contentBuilder = async (session: LowCalSession) => {
const service = convertSlugToName(session.flow.slug);
const address: SiteAddress | undefined =
session.data?.passport?.data?._address;
const addressLine = address?.single_line_address || address?.title;
Expand All @@ -126,7 +123,7 @@ const buildContentFromSessions = async (
const sessionAge = differenceInDays(today, new Date(session.created_at));

if (sessionAge < DAYS_UNTIL_EXPIRY)
return `Service: ${service}
return `Service: ${session.flow.name}
Address: ${addressLine || "Address not submitted"}
Project type: ${projectType || "Project type not submitted"}
Expiry Date: ${expiryDate}
Expand Down
17 changes: 2 additions & 15 deletions api.planx.uk/modules/saveAndReturn/service/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { Team } from "@opensystemslab/planx-core/types";
import { queryMock } from "../../../tests/graphqlQueryMock";
import { LowCalSession, LowCalSessionData, Team } from "../../../types";
import { LowCalSession, LowCalSessionData } from "../../../types";
import {
convertSlugToName,
getResumeLink,
getSessionDetails,
setupEmailEventTriggers,
} from "./utils";

describe("convertSlugToName util function", () => {
it("should return the correct value", () => {
const testData = [
["open-systems-lab", "Open systems lab"],
["lambeth", "Lambeth"],
];

testData.forEach(([slug, name]) => {
expect(convertSlugToName(slug)).toEqual(name);
});
});
});

describe("getResumeLink util function", () => {
it("should return the correct value for a custom domain", () => {
const session = {
Expand Down
21 changes: 8 additions & 13 deletions api.planx.uk/modules/saveAndReturn/service/utils.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { SiteAddress } from "@opensystemslab/planx-core/types";
import { SiteAddress, Team } from "@opensystemslab/planx-core/types";
import { format, addDays } from "date-fns";
import { gql } from "graphql-request";
import { LowCalSession, Team } from "../../../types";
import { LowCalSession } from "../../../types";
import { Template, getClientForTemplate, sendEmail } from "../../../lib/notify";
import { $api, $public } from "../../../client";

const DAYS_UNTIL_EXPIRY = 28;
const REMINDER_DAYS_FROM_EXPIRY = [7, 1];

/**
* Converts a flow's slug to a pretty name
* XXX: This relies on pretty names not having dashes in them, which may not always be true (e.g. Na h-Eileanan Siar, Stoke-on-Trent)
*/
const convertSlugToName = (slug: string): string =>
slug[0].toUpperCase() + slug.substring(1).replaceAll("-", " ");

/**
* Build the magic link which will be sent to users via email to continue their application
*/
Expand Down Expand Up @@ -66,7 +59,7 @@ const sendSingleApplicationEmail = async ({
const config = {
personalisation: getPersonalisation(session, flowSlug, flowName, team),
reference: null,
emailReplyToId: team.notifyPersonalisation.emailReplyToId,
emailReplyToId: team.settings.emailReplyToId,
};
const firstSave = !session.hasUserSaved;
if (firstSave && !session.submittedAt)
Expand Down Expand Up @@ -104,7 +97,7 @@ const validateSingleSessionRequest = async (
team {
name
slug
notifyPersonalisation: notify_personalisation
settings: team_settings
domain
}
}
Expand Down Expand Up @@ -183,7 +176,10 @@ const getPersonalisation = (
serviceName: flowName,
teamName: team.name,
sessionId: session.id,
...team.notifyPersonalisation,
helpEmail: team.settings.helpEmail,
helpPhone: team.settings.helpPhone,
helpOpeningHours: team.settings.helpOpeningHours,
emailReplyToId: team.settings.emailReplyToId,
...session,
};
};
Expand Down Expand Up @@ -276,7 +272,6 @@ export const setupEmailEventTriggers = async (sessionId: string) => {

export {
getSaveAndReturnPublicHeaders,
convertSlugToName,
getResumeLink,
sendSingleApplicationEmail,
markSessionAsSubmitted,
Expand Down
Loading