From 1f230d7b043084ac28f648a2df5641f07fba7024 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Fri, 23 Feb 2024 17:46:05 +0000 Subject: [PATCH] fix: don't include ODP Schema in submission zip by default (#2812) --- api.planx.uk/modules/admin/session/zip.ts | 11 +- .../send/downloadApplicationFiles/index.ts | 5 +- api.planx.uk/modules/send/email/index.test.ts | 1 + .../modules/send/utils/exportZip.test.ts | 147 ++++++++++-------- api.planx.uk/modules/send/utils/exportZip.ts | 3 + api.planx.uk/package.json | 2 +- api.planx.uk/pnpm-lock.yaml | 8 +- e2e/tests/api-driven/package.json | 2 +- e2e/tests/api-driven/pnpm-lock.yaml | 8 +- e2e/tests/ui-driven/package.json | 2 +- e2e/tests/ui-driven/pnpm-lock.yaml | 8 +- editor.planx.uk/package.json | 2 +- editor.planx.uk/pnpm-lock.yaml | 10 +- 13 files changed, 121 insertions(+), 88 deletions(-) diff --git a/api.planx.uk/modules/admin/session/zip.ts b/api.planx.uk/modules/admin/session/zip.ts index 5a9c5d38e2..a9ef0711eb 100644 --- a/api.planx.uk/modules/admin/session/zip.ts +++ b/api.planx.uk/modules/admin/session/zip.ts @@ -12,10 +12,15 @@ import { buildSubmissionExportZip } from "../../send/utils/exportZip"; * parameters: * - $ref: '#/components/parameters/sessionId' * - in: query - * name: includeXML + * name: includeOneAppXML * type: boolean * required: false * description: If the OneApp XML file should be included in the zip + * - in: query + * name: includeDigitalPlanningJSON + * type: boolean + * required: false + * description: If the Digital Planning JSON file should be included in the zip (only generated for supported application types) * security: * - bearerAuth: [] */ @@ -27,7 +32,9 @@ export async function generateZip( try { const zip = await buildSubmissionExportZip({ sessionId: req.params.sessionId, - includeOneAppXML: req.query.includeXML === "true", + includeOneAppXML: req.query.includeOneAppXML === "true", + includeDigitalPlanningJSON: + req.query.includeDigitalPlanningJSON === "false", }); res.download(zip.filename, () => { zip.remove(); diff --git a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts index ce5781483a..a7d85a7132 100644 --- a/api.planx.uk/modules/send/downloadApplicationFiles/index.ts +++ b/api.planx.uk/modules/send/downloadApplicationFiles/index.ts @@ -38,7 +38,10 @@ export async function downloadApplicationFiles( } // create the submission zip - const zip = await buildSubmissionExportZip({ sessionId }); + const zip = await buildSubmissionExportZip({ + sessionId, + includeDigitalPlanningJSON: true, + }); // Send it to the client const zipData = zip.toBuffer(); diff --git a/api.planx.uk/modules/send/email/index.test.ts b/api.planx.uk/modules/send/email/index.test.ts index 692cbbd98b..4481c258c1 100644 --- a/api.planx.uk/modules/send/email/index.test.ts +++ b/api.planx.uk/modules/send/email/index.test.ts @@ -268,6 +268,7 @@ describe(`downloading application data received by email`, () => { .then((_res) => { expect(mockBuildSubmissionExportZip).toHaveBeenCalledWith({ sessionId: "123", + includeDigitalPlanningJSON: true, }); }); }); diff --git a/api.planx.uk/modules/send/utils/exportZip.test.ts b/api.planx.uk/modules/send/utils/exportZip.test.ts index 9c5703016d..f0bde23113 100644 --- a/api.planx.uk/modules/send/utils/exportZip.test.ts +++ b/api.planx.uk/modules/send/utils/exportZip.test.ts @@ -100,17 +100,6 @@ describe("buildSubmissionExportZip", () => { expect(mockAddFile).toHaveBeenCalledWith("Overview.htm", expect.anything()); }); - test("ODP schema json is added to the zip", async () => { - const schema = expectedPlanningPermissionPayload; - const expectedBuffer = Buffer.from(JSON.stringify(schema, null, 2)); - - await buildSubmissionExportZip({ sessionId: "1234" }); - expect(mockAddFile).toHaveBeenCalledWith( - "application.json", - expectedBuffer, - ); - }); - test("boundary GeoJSON is added to zip", async () => { const geojson = { type: "Feature", @@ -176,58 +165,6 @@ describe("buildSubmissionExportZip", () => { ); }); - test("ODP schema json is excluded if unsupported application type", async () => { - // set-up mock session passport overwriting "application.type" - const lowcalSessionUnsupportedAppType: Partial = { - ...mockLowcalSession, - id: "1234", - data: { - ...mockLowcalSession.data, - id: "1234", - passport: { - data: { - ...mockLowcalSession.data!.passport.data, - "application.type": ["listedBuildingConsent"], - }, - }, - }, - }; - mockGetSessionById.mockResolvedValueOnce(lowcalSessionUnsupportedAppType); - - await buildSubmissionExportZip({ sessionId: "1234" }); - - expect(mockAddFile).not.toHaveBeenCalledWith( - "application.json", - expect.anything(), - ); - }); - - test("ODP schema json is excluded if no application type", async () => { - // set-up mock session passport overwriting "application.type" - const lowcalSessionUnsupportedAppType: Partial = { - ...mockLowcalSession, - id: "1234", - data: { - ...mockLowcalSession.data, - id: "1234", - passport: { - data: { - ...mockLowcalSession.data!.passport.data, - "application.type": undefined, - }, - }, - }, - }; - mockGetSessionById.mockResolvedValueOnce(lowcalSessionUnsupportedAppType); - - await buildSubmissionExportZip({ sessionId: "1234" }); - - expect(mockAddFile).not.toHaveBeenCalledWith( - "application.json", - expect.anything(), - ); - }); - test("a document template is added when the template is supported", async () => { await buildSubmissionExportZip({ sessionId: "1234" }); expect(mockAddLocalFile).toHaveBeenCalledWith( @@ -273,13 +210,95 @@ describe("buildSubmissionExportZip", () => { }), ).rejects.toThrow(/Failed to generate OneApp XML/); }); + }); + + describe("includeDigitalPlanningJSON", () => { + test("ODP schema json is added to the zip", async () => { + await buildSubmissionExportZip({ + sessionId: "1234", + includeDigitalPlanningJSON: true, + }); + expect(mockAddFile).toHaveBeenCalledWith( + "application.json", + expect.anything(), + ); + }); + + test("ODP schema json is excluded if no query param", async () => { + await buildSubmissionExportZip({ sessionId: "1234" }); + expect(mockAddFile).not.toHaveBeenCalledWith( + "application.json", + expect.anything(), + ); + }); + + test("ODP schema json is excluded if unsupported application type", async () => { + // set-up mock session passport overwriting "application.type" + const lowcalSessionUnsupportedAppType: Partial = { + ...mockLowcalSession, + id: "1234", + data: { + ...mockLowcalSession.data, + id: "1234", + passport: { + data: { + ...mockLowcalSession.data!.passport.data, + "application.type": ["listedBuildingConsent"], + }, + }, + }, + }; + mockGetSessionById.mockResolvedValueOnce(lowcalSessionUnsupportedAppType); + + await buildSubmissionExportZip({ + sessionId: "1234", + includeDigitalPlanningJSON: true, + }); + + expect(mockAddFile).not.toHaveBeenCalledWith( + "application.json", + expect.anything(), + ); + }); + + test("ODP schema json is excluded if no application type", async () => { + // set-up mock session passport overwriting "application.type" + const lowcalSessionUnsupportedAppType: Partial = { + ...mockLowcalSession, + id: "1234", + data: { + ...mockLowcalSession.data, + id: "1234", + passport: { + data: { + ...mockLowcalSession.data!.passport.data, + "application.type": undefined, + }, + }, + }, + }; + mockGetSessionById.mockResolvedValueOnce(lowcalSessionUnsupportedAppType); + + await buildSubmissionExportZip({ + sessionId: "1234", + includeDigitalPlanningJSON: true, + }); + + expect(mockAddFile).not.toHaveBeenCalledWith( + "application.json", + expect.anything(), + ); + }); it("throws an error when ODP schema generation fails", async () => { mockGenerateDigitalPlanningDataPayload.mockRejectedValueOnce( new Error("validation test error"), ); await expect( - buildSubmissionExportZip({ sessionId: "1234" }), + buildSubmissionExportZip({ + sessionId: "1234", + includeDigitalPlanningJSON: true, + }), ).rejects.toThrow(/Failed to generate ODP Schema JSON/); }); }); diff --git a/api.planx.uk/modules/send/utils/exportZip.ts b/api.planx.uk/modules/send/utils/exportZip.ts index 4527b44ee9..e81fa1d404 100644 --- a/api.planx.uk/modules/send/utils/exportZip.ts +++ b/api.planx.uk/modules/send/utils/exportZip.ts @@ -20,9 +20,11 @@ import type { PlanXExportData } from "@opensystemslab/planx-core/types"; export async function buildSubmissionExportZip({ sessionId, includeOneAppXML = false, + includeDigitalPlanningJSON = false, }: { sessionId: string; includeOneAppXML?: boolean; + includeDigitalPlanningJSON?: boolean; }): Promise { // create zip const zip = new ExportZip(sessionId); @@ -56,6 +58,7 @@ export async function buildSubmissionExportZip({ const supportedApplicationPrefixes = ["ldc", "pa", "pp"]; const applicationType = passport.data?.["application.type"]?.[0]; if ( + includeDigitalPlanningJSON && applicationType && supportedApplicationPrefixes.includes(applicationType.split(".")?.[0]) ) { diff --git a/api.planx.uk/package.json b/api.planx.uk/package.json index f747e0118b..b250a6670a 100644 --- a/api.planx.uk/package.json +++ b/api.planx.uk/package.json @@ -4,7 +4,7 @@ "private": true, "dependencies": { "@airbrake/node": "^2.1.8", - "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a68d840", + "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#f8f2155", "@types/isomorphic-fetch": "^0.0.36", "adm-zip": "^0.5.10", "aws-sdk": "^2.1467.0", diff --git a/api.planx.uk/pnpm-lock.yaml b/api.planx.uk/pnpm-lock.yaml index 3802fc6305..2ee3efebff 100644 --- a/api.planx.uk/pnpm-lock.yaml +++ b/api.planx.uk/pnpm-lock.yaml @@ -12,8 +12,8 @@ dependencies: specifier: ^2.1.8 version: 2.1.8 '@opensystemslab/planx-core': - specifier: git+https://github.com/theopensystemslab/planx-core#a68d840 - version: github.com/theopensystemslab/planx-core/a68d840 + specifier: git+https://github.com/theopensystemslab/planx-core#f8f2155 + version: github.com/theopensystemslab/planx-core/f8f2155 '@types/isomorphic-fetch': specifier: ^0.0.36 version: 0.0.36 @@ -8292,8 +8292,8 @@ packages: resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} dev: false - github.com/theopensystemslab/planx-core/a68d840: - resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/a68d840} + github.com/theopensystemslab/planx-core/f8f2155: + resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/f8f2155} name: '@opensystemslab/planx-core' version: 1.0.0 prepare: true diff --git a/e2e/tests/api-driven/package.json b/e2e/tests/api-driven/package.json index 24f944db44..5071fda4f4 100644 --- a/e2e/tests/api-driven/package.json +++ b/e2e/tests/api-driven/package.json @@ -6,7 +6,7 @@ }, "dependencies": { "@cucumber/cucumber": "^9.3.0", - "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a68d840", + "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#f8f2155", "axios": "^1.6.0", "dotenv": "^16.3.1", "dotenv-expand": "^10.0.0", diff --git a/e2e/tests/api-driven/pnpm-lock.yaml b/e2e/tests/api-driven/pnpm-lock.yaml index 96c9d7f6aa..ea7d97fccd 100644 --- a/e2e/tests/api-driven/pnpm-lock.yaml +++ b/e2e/tests/api-driven/pnpm-lock.yaml @@ -9,8 +9,8 @@ dependencies: specifier: ^9.3.0 version: 9.3.0 '@opensystemslab/planx-core': - specifier: git+https://github.com/theopensystemslab/planx-core#a68d840 - version: github.com/theopensystemslab/planx-core/a68d840 + specifier: git+https://github.com/theopensystemslab/planx-core#f8f2155 + version: github.com/theopensystemslab/planx-core/f8f2155 axios: specifier: ^1.6.0 version: 1.6.5 @@ -2781,8 +2781,8 @@ packages: resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} dev: false - github.com/theopensystemslab/planx-core/a68d840: - resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/a68d840} + github.com/theopensystemslab/planx-core/f8f2155: + resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/f8f2155} name: '@opensystemslab/planx-core' version: 1.0.0 prepare: true diff --git a/e2e/tests/ui-driven/package.json b/e2e/tests/ui-driven/package.json index 43748b5130..99e40b88e9 100644 --- a/e2e/tests/ui-driven/package.json +++ b/e2e/tests/ui-driven/package.json @@ -8,7 +8,7 @@ "postinstall": "./install-dependencies.sh" }, "dependencies": { - "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a68d840", + "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#f8f2155", "axios": "^1.6.2", "dotenv": "^16.3.1", "eslint": "^8.56.0", diff --git a/e2e/tests/ui-driven/pnpm-lock.yaml b/e2e/tests/ui-driven/pnpm-lock.yaml index 16b8f0c2f4..6ae7ccd38a 100644 --- a/e2e/tests/ui-driven/pnpm-lock.yaml +++ b/e2e/tests/ui-driven/pnpm-lock.yaml @@ -6,8 +6,8 @@ settings: dependencies: '@opensystemslab/planx-core': - specifier: git+https://github.com/theopensystemslab/planx-core#a68d840 - version: github.com/theopensystemslab/planx-core/a68d840 + specifier: git+https://github.com/theopensystemslab/planx-core#f8f2155 + version: github.com/theopensystemslab/planx-core/f8f2155 axios: specifier: ^1.6.2 version: 1.6.5 @@ -2528,8 +2528,8 @@ packages: resolution: {integrity: sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==} dev: false - github.com/theopensystemslab/planx-core/a68d840: - resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/a68d840} + github.com/theopensystemslab/planx-core/f8f2155: + resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/f8f2155} name: '@opensystemslab/planx-core' version: 1.0.0 prepare: true diff --git a/editor.planx.uk/package.json b/editor.planx.uk/package.json index dd3eed38bb..320f0b9ee8 100644 --- a/editor.planx.uk/package.json +++ b/editor.planx.uk/package.json @@ -13,7 +13,7 @@ "@mui/styles": "^5.15.2", "@mui/utils": "^5.15.2", "@opensystemslab/map": "^0.8.0", - "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#a68d840", + "@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#f8f2155", "@tiptap/core": "^2.0.3", "@tiptap/extension-bold": "^2.0.3", "@tiptap/extension-bubble-menu": "^2.1.13", diff --git a/editor.planx.uk/pnpm-lock.yaml b/editor.planx.uk/pnpm-lock.yaml index 894052edc4..5d04de4dd8 100644 --- a/editor.planx.uk/pnpm-lock.yaml +++ b/editor.planx.uk/pnpm-lock.yaml @@ -43,8 +43,8 @@ dependencies: specifier: ^0.8.0 version: 0.8.0 '@opensystemslab/planx-core': - specifier: git+https://github.com/theopensystemslab/planx-core#a68d840 - version: github.com/theopensystemslab/planx-core/a68d840(@types/react@18.2.45) + specifier: git+https://github.com/theopensystemslab/planx-core#f8f2155 + version: github.com/theopensystemslab/planx-core/f8f2155(@types/react@18.2.45) '@tiptap/core': specifier: ^2.0.3 version: 2.0.3(@tiptap/pm@2.0.3) @@ -21067,9 +21067,9 @@ packages: use-sync-external-store: 1.2.0(react@18.2.0) dev: false - github.com/theopensystemslab/planx-core/a68d840(@types/react@18.2.45): - resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/a68d840} - id: github.com/theopensystemslab/planx-core/a68d840 + github.com/theopensystemslab/planx-core/f8f2155(@types/react@18.2.45): + resolution: {tarball: https://codeload.github.com/theopensystemslab/planx-core/tar.gz/f8f2155} + id: github.com/theopensystemslab/planx-core/f8f2155 name: '@opensystemslab/planx-core' version: 1.0.0 prepare: true