Skip to content

Commit

Permalink
chore: Remove redundant convertSlugToName util (#3405)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Jul 11, 2024
1 parent 17cdbd6 commit b8da414
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 39 deletions.
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
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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 +124,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 +184,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 +217,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 +252,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
10 changes: 2 additions & 8 deletions api.planx.uk/modules/saveAndReturn/service/resumeApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ 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 { 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 Down Expand Up @@ -111,7 +106,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 +120,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
14 changes: 0 additions & 14 deletions api.planx.uk/modules/saveAndReturn/service/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { queryMock } from "../../../tests/graphqlQueryMock";
import { LowCalSession, LowCalSessionData, Team } 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
8 changes: 0 additions & 8 deletions api.planx.uk/modules/saveAndReturn/service/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ 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 @@ -276,7 +269,6 @@ export const setupEmailEventTriggers = async (sessionId: string) => {

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

0 comments on commit b8da414

Please sign in to comment.