diff --git a/api.planx.uk/inviteToPay/createPaymentSendEvents.test.ts b/api.planx.uk/inviteToPay/createPaymentSendEvents.test.ts index 2f7cf22b28..4855cb0b36 100644 --- a/api.planx.uk/inviteToPay/createPaymentSendEvents.test.ts +++ b/api.planx.uk/inviteToPay/createPaymentSendEvents.test.ts @@ -1,10 +1,10 @@ import supertest from "supertest"; import app from "../server"; -import { createScheduledEvent } from "../hasura/metadata"; +import { createScheduledEvent } from "../lib/hasura/metadata"; import { queryMock } from "../tests/graphqlQueryMock"; import { flowWithInviteToPay } from "../tests/mocks/inviteToPayData"; -jest.mock("../hasura/metadata"); +jest.mock("../lib/hasura/metadata"); const mockedCreateScheduledEvent = createScheduledEvent as jest.MockedFunction< typeof createScheduledEvent >; diff --git a/api.planx.uk/inviteToPay/createPaymentSendEvents.ts b/api.planx.uk/inviteToPay/createPaymentSendEvents.ts index 799ab3bbba..35ac8e3787 100644 --- a/api.planx.uk/inviteToPay/createPaymentSendEvents.ts +++ b/api.planx.uk/inviteToPay/createPaymentSendEvents.ts @@ -5,7 +5,7 @@ import { $api, $public } from "../client"; import { ScheduledEventResponse, createScheduledEvent, -} from "../hasura/metadata"; +} from "../lib/hasura/metadata"; import { getMostRecentPublishedFlow } from "../helpers"; import { Flow, Node, Team } from "../types"; diff --git a/api.planx.uk/hasura/metadata/index.test.ts b/api.planx.uk/lib/hasura/metadata/index.test.ts similarity index 100% rename from api.planx.uk/hasura/metadata/index.test.ts rename to api.planx.uk/lib/hasura/metadata/index.test.ts diff --git a/api.planx.uk/hasura/metadata/index.ts b/api.planx.uk/lib/hasura/metadata/index.ts similarity index 100% rename from api.planx.uk/hasura/metadata/index.ts rename to api.planx.uk/lib/hasura/metadata/index.ts diff --git a/api.planx.uk/hasura/schema/index.test.ts b/api.planx.uk/lib/hasura/schema/index.test.ts similarity index 100% rename from api.planx.uk/hasura/schema/index.test.ts rename to api.planx.uk/lib/hasura/schema/index.test.ts diff --git a/api.planx.uk/hasura/schema/index.ts b/api.planx.uk/lib/hasura/schema/index.ts similarity index 100% rename from api.planx.uk/hasura/schema/index.ts rename to api.planx.uk/lib/hasura/schema/index.ts diff --git a/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.test.ts b/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.test.ts index 303310aa3b..ac5e7cb5b2 100644 --- a/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.test.ts +++ b/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.test.ts @@ -1,10 +1,10 @@ import supertest from "supertest"; import app from "../../../../server"; -import { createScheduledEvent } from "../../../../hasura/metadata"; +import { createScheduledEvent } from "../../../../lib/hasura/metadata"; const { post } = supertest(app); -jest.mock("../../../../hasura/metadata"); +jest.mock("../../../../lib/hasura/metadata"); const mockedCreateScheduledEvent = createScheduledEvent as jest.MockedFunction< typeof createScheduledEvent >; diff --git a/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.ts b/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.ts index b8ec4cf072..58064a5e6a 100644 --- a/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.ts +++ b/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/index.ts @@ -1,6 +1,6 @@ import { addDays } from "date-fns"; -import { createScheduledEvent } from "../../../../hasura/metadata"; +import { createScheduledEvent } from "../../../../lib/hasura/metadata"; import { DAYS_UNTIL_EXPIRY, REMINDER_DAYS_FROM_EXPIRY, diff --git a/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/schema.ts b/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/schema.ts index f8b17aa24f..2bafddb4b5 100644 --- a/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/schema.ts +++ b/api.planx.uk/modules/webhooks/service/lowcalSessionEvents/schema.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import { ValidatedRequestHandler } from "../../../../shared/middleware/validate"; -import { ScheduledEventResponse } from "../../../../hasura/metadata"; +import { ScheduledEventResponse } from "../../../../lib/hasura/metadata"; export const createSessionEventSchema = z.object({ body: z.object({ diff --git a/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.test.ts b/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.test.ts index 20beeefd98..70fd705cdc 100644 --- a/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.test.ts +++ b/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.test.ts @@ -1,11 +1,11 @@ import supertest from "supertest"; import app from "../../../../server"; -import { createScheduledEvent } from "../../../../hasura/metadata"; +import { createScheduledEvent } from "../../../../lib/hasura/metadata"; import { CreatePaymentEvent } from "./schema"; const { post } = supertest(app); -jest.mock("../../../../hasura/metadata"); +jest.mock("../../../../lib/hasura/metadata"); const mockedCreateScheduledEvent = createScheduledEvent as jest.MockedFunction< typeof createScheduledEvent >; diff --git a/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.ts b/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.ts index 9679c7931e..b438ce5236 100644 --- a/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.ts +++ b/api.planx.uk/modules/webhooks/service/paymentRequestEvents/index.ts @@ -1,6 +1,6 @@ import { addDays } from "date-fns"; -import { createScheduledEvent } from "../../../../hasura/metadata"; +import { createScheduledEvent } from "../../../../lib/hasura/metadata"; import { DAYS_UNTIL_EXPIRY, REMINDER_DAYS_FROM_EXPIRY, diff --git a/api.planx.uk/modules/webhooks/service/paymentRequestEvents/schema.ts b/api.planx.uk/modules/webhooks/service/paymentRequestEvents/schema.ts index 042ea05f71..20fe20abd7 100644 --- a/api.planx.uk/modules/webhooks/service/paymentRequestEvents/schema.ts +++ b/api.planx.uk/modules/webhooks/service/paymentRequestEvents/schema.ts @@ -1,6 +1,6 @@ import { z } from "zod"; import { ValidatedRequestHandler } from "../../../../shared/middleware/validate"; -import { ScheduledEventResponse } from "../../../../hasura/metadata"; +import { ScheduledEventResponse } from "../../../../lib/hasura/metadata"; export const createPaymentEventSchema = z.object({ body: z.object({ diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts index c6d77a547b..50a863c391 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.test.ts @@ -1,4 +1,4 @@ -import { runSQL } from "../../../../hasura/schema"; +import { runSQL } from "../../../../lib/hasura/schema"; import { queryMock } from "../../../../tests/graphqlQueryMock"; import { mockIds, @@ -25,7 +25,7 @@ import { deleteHasuraScheduledEventsForSubmittedSessions, } from "./operations"; -jest.mock("../../../../hasura/schema"); +jest.mock("../../../../lib/hasura/schema"); const mockRunSQL = runSQL as jest.MockedFunction; const mockFindSession = jest.fn(); diff --git a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts index b3c19658fd..c5d3a0697c 100644 --- a/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts +++ b/api.planx.uk/modules/webhooks/service/sanitiseApplicationData/operations.ts @@ -2,10 +2,10 @@ import { gql } from "graphql-request"; import { subMonths } from "date-fns"; import { Operation, OperationResult, QueryResult } from "./types"; -import { runSQL } from "../../../../hasura/schema"; -import { getFilesForSession } from "../../../../session/files"; +import { runSQL } from "../../../../lib/hasura/schema"; import { deleteFilesByURL } from "../../../../s3/deleteFile"; import { $api } from "../../../../client"; +import { Passport } from "@opensystemslab/planx-core"; const RETENTION_PERIOD_MONTHS = 6; export const getRetentionPeriod = () => @@ -97,7 +97,11 @@ export const deleteApplicationFiles: Operation = async () => { const sessionIds = await getExpiredSessionIds(); for (const sessionId of sessionIds) { - const files = await getFilesForSession(sessionId); + const session = await $api.session.find(sessionId); + if (!session) { + throw Error(`Unable to find session matching id ${sessionId}`); + } + const files = new Passport(session.data.passport).files(); if (files.length) { const deleted = await deleteFilesByURL(files); deletedFiles.push(...deleted); diff --git a/api.planx.uk/send/createSendEvents.ts b/api.planx.uk/send/createSendEvents.ts index 8f5c12af4e..67c86db3a8 100644 --- a/api.planx.uk/send/createSendEvents.ts +++ b/api.planx.uk/send/createSendEvents.ts @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from "express"; import { ScheduledEventResponse, createScheduledEvent, -} from "../hasura/metadata"; +} from "../lib/hasura/metadata"; interface CombinedResponse { bops?: ScheduledEventResponse; diff --git a/api.planx.uk/session/files.test.ts b/api.planx.uk/session/files.test.ts deleted file mode 100644 index 824df21f6e..0000000000 --- a/api.planx.uk/session/files.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { getFilesForSession } from "./files"; - -const mockFindSession = jest.fn(); - -jest.mock("../client", () => { - return { - $api: { - session: { - find: jest.fn().mockImplementation(() => mockFindSession()), - }, - }, - }; -}); - -describe("getFilesForSession()", () => { - it("handles sessions without files", async () => { - mockFindSession.mockResolvedValue({ - data: { passport: {} }, - }); - expect(await getFilesForSession("sessionId")).toEqual([]); - }); - - it("handles sessions with files", async () => { - mockFindSession.mockResolvedValue({ - data: { - passport: { - data: { - "file.key": [ - { - url: "https://my.test.file", - }, - ], - }, - }, - }, - }); - expect(await getFilesForSession("sessionId")).toEqual([ - "https://my.test.file", - ]); - }); -}); diff --git a/api.planx.uk/session/files.ts b/api.planx.uk/session/files.ts deleted file mode 100644 index 7f5550afc5..0000000000 --- a/api.planx.uk/session/files.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Passport } from "@opensystemslab/planx-core"; -import { $api } from "../client"; - -export const getFilesForSession = async ( - sessionId: string, -): Promise => { - const session = await $api.session.find(sessionId); - if (!session?.data.passport?.data) return []; - - const files = new Passport(session.data.passport).files(); - return files; -};