Skip to content

Commit

Permalink
don't include by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Feb 23, 2024
1 parent 733054a commit e9bd7e4
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 66 deletions.
8 changes: 7 additions & 1 deletion api.planx.uk/modules/admin/session/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
*/
Expand All @@ -28,6 +33,7 @@ export async function generateZip(
const zip = await buildSubmissionExportZip({
sessionId: req.params.sessionId,
includeOneAppXML: req.query.includeXML === "true",
includeDigitalPlanningJSON: req.query.includeJSON === "false",
});
res.download(zip.filename, () => {
zip.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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();
Expand Down
147 changes: 83 additions & 64 deletions api.planx.uk/modules/send/utils/exportZip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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<LowCalSession> = {
...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<LowCalSession> = {
...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(
Expand Down Expand Up @@ -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<LowCalSession> = {
...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<LowCalSession> = {
...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/);
});
});
Expand Down
3 changes: 3 additions & 0 deletions api.planx.uk/modules/send/utils/exportZip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExportZip> {
// create zip
const zip = new ExportZip(sessionId);
Expand Down Expand Up @@ -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])
) {
Expand Down

0 comments on commit e9bd7e4

Please sign in to comment.