Skip to content

Commit

Permalink
chore: Tidy up - linting and dropping custom DeepPartial type
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 1, 2023
1 parent bda3ed1 commit 5c545c0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 30 deletions.
4 changes: 2 additions & 2 deletions api.planx.uk/inviteToPay/createPaymentSendEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ interface GetTeamSlugByFlowId {
flows: {
team: {
slug: string;
}
}
};
};
}

const getTeamSlugByFlowId = async (id: Flow["id"]): Promise<Team["slug"]> => {
Expand Down
4 changes: 1 addition & 3 deletions api.planx.uk/notify/routeSendEmailRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ describe("Send Email endpoint", () => {
const softDeleteSessionMock = queryMock
.getCalls()
.find((mock) => mock.id === "SoftDeleteLowcalSession");
expect(
softDeleteSessionMock?.response.data.session.id,
).toEqual("123");
expect(softDeleteSessionMock?.response.data.session.id).toEqual("123");
});
});
});
Expand Down
21 changes: 9 additions & 12 deletions api.planx.uk/saveAndReturn/resumeApplication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,33 @@ import app from "../server";
import { queryMock } from "../tests/graphqlQueryMock";
import { mockLowcalSession, mockTeam } from "../tests/mocks/saveAndReturnMocks";
import { buildContentFromSessions } from "./resumeApplication";
import { PartialDeep } from "type-fest";

const ENDPOINT = "/resume-application";
const TEST_EMAIL = "[email protected]";

type DeepPartial<T> = T extends object
? {
[P in keyof T]?: DeepPartial<T[P]>;
}
: T;

const mockFormatRawProjectTypes = jest
.fn()
.mockResolvedValue(["New office premises"]);

jest.mock("@opensystemslab/planx-core", () => {
const actualCoreDomainClient = jest.requireActual("@opensystemslab/planx-core").CoreDomainClient;
const actualCoreDomainClient = jest.requireActual(
"@opensystemslab/planx-core",
).CoreDomainClient;

return {
CoreDomainClient: class extends actualCoreDomainClient {
constructor() {
super();
this.formatRawProjectTypes = () => mockFormatRawProjectTypes();
}
}
},
};
});

describe("buildContentFromSessions function", () => {
it("should return correctly formatted content for a single session", async () => {
const sessions: DeepPartial<LowCalSession>[] = [
const sessions: PartialDeep<LowCalSession>[] = [
{
data: {
passport: {
Expand Down Expand Up @@ -67,7 +64,7 @@ describe("buildContentFromSessions function", () => {
});

it("should return correctly formatted content for multiple session", async () => {
const sessions: DeepPartial<LowCalSession>[] = [
const sessions: PartialDeep<LowCalSession>[] = [
{
data: {
passport: {
Expand Down Expand Up @@ -142,7 +139,7 @@ describe("buildContentFromSessions function", () => {
});

it("should handle an empty address field", async () => {
const sessions: DeepPartial<LowCalSession>[] = [
const sessions: PartialDeep<LowCalSession>[] = [
{
data: {
passport: {
Expand Down Expand Up @@ -175,7 +172,7 @@ describe("buildContentFromSessions function", () => {

it("should handle an empty project type field", async () => {
mockFormatRawProjectTypes.mockResolvedValueOnce("");
const sessions: DeepPartial<LowCalSession>[] = [
const sessions: PartialDeep<LowCalSession>[] = [
{
data: {
passport: {
Expand Down
11 changes: 7 additions & 4 deletions api.planx.uk/saveAndReturn/resumeApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ const validateRequest = async (
}
}
`;
const { sessions, teams } = await $api.client.request<ValidateRequest>(query, {
teamSlug,
email: email.toLowerCase(),
});
const { sessions, teams } = await $api.client.request<ValidateRequest>(
query,
{
teamSlug,
email: email.toLowerCase(),
},
);

if (!teams?.length) throw Error;

Expand Down
8 changes: 5 additions & 3 deletions api.planx.uk/saveAndReturn/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ const getSaveAndReturnPublicHeaders = (sessionId: string, email: string) => ({
"x-hasura-lowcal-email": email.toLowerCase(),
});

interface SetupEmailNotifications {
session: { hasUserSaved: boolean }
interface SetupEmailNotifications {
session: { hasUserSaved: boolean };
}

// Update lowcal_sessions.has_user_saved column to kick-off the setup_lowcal_expiry_events &
Expand All @@ -259,7 +259,9 @@ const setupEmailEventTriggers = async (sessionId: string) => {
`;
const {
session: { hasUserSaved },
} = await $api.client.request<SetupEmailNotifications>(mutation, { sessionId });
} = await $api.client.request<SetupEmailNotifications>(mutation, {
sessionId,
});
return hasUserSaved;
} catch (error) {
throw new Error(
Expand Down
6 changes: 4 additions & 2 deletions api.planx.uk/send/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jest.mock("../saveAndReturn/utils", () => ({
}));

jest.mock("@opensystemslab/planx-core", () => {
const actualCoreDomainClient = jest.requireActual("@opensystemslab/planx-core").CoreDomainClient;
const actualCoreDomainClient = jest.requireActual(
"@opensystemslab/planx-core",
).CoreDomainClient;

return {
CoreDomainClient: class extends actualCoreDomainClient {
Expand All @@ -21,7 +23,7 @@ jest.mock("@opensystemslab/planx-core", () => {
redactedExportData: expectedPayload,
});
}
}
},
};
});

Expand Down
6 changes: 3 additions & 3 deletions api.planx.uk/send/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface CreateBopsApplication {
insertBopsApplication: {
id: string;
bopsId: string;
}
};
}

/**
Expand Down Expand Up @@ -167,8 +167,8 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {

interface FindApplication {
bopsApplications: {
response: Record<string, string>
}[]
response: Record<string, string>;
}[];
}

/**
Expand Down
4 changes: 3 additions & 1 deletion api.planx.uk/send/email.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const mockGenerateCSVData = jest.fn().mockResolvedValue([
]);

jest.mock("@opensystemslab/planx-core", () => {
const actualCoreDomainClient = jest.requireActual("@opensystemslab/planx-core").CoreDomainClient;
const actualCoreDomainClient = jest.requireActual(
"@opensystemslab/planx-core",
).CoreDomainClient;

return {
Passport: jest.fn().mockImplementation(() => ({
Expand Down

0 comments on commit 5c545c0

Please sign in to comment.