Skip to content

Commit

Permalink
feat: Explicitly handle redaction (#2313)
Browse files Browse the repository at this point in the history
* chore: Handle redactions more explicitly

* test: Update tests

* chore: Bump planx-core
  • Loading branch information
DafyddLlyr authored Oct 17, 2023
1 parent 102393e commit bf52435
Show file tree
Hide file tree
Showing 20 changed files with 370 additions and 320 deletions.
4 changes: 1 addition & 3 deletions api.planx.uk/admin/session/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { expectedPayload } from "../../tests/mocks/bopsMocks";
const endpoint = (strings: TemplateStringsArray) =>
`/admin/session/${strings[0]}/bops`;

const mockGenerateBOPSPayload = jest.fn().mockResolvedValue({
exportData: expectedPayload,
});
const mockGenerateBOPSPayload = jest.fn().mockResolvedValue(expectedPayload);

jest.mock("@opensystemslab/planx-core", () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/admin/session/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getBOPSPayload = async (
next: NextFunction,
) => {
try {
const { exportData } = await $api.export.bopsPayload(req.params.sessionId);
const exportData = await $api.export.bopsPayload(req.params.sessionId);
res.set("content-type", "application/json");
return res.send(exportData);
} catch (error) {
Expand Down
17 changes: 7 additions & 10 deletions api.planx.uk/admin/session/csv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ import { authHeader } from "../../tests/mockJWT";
const endpoint = (strings: TemplateStringsArray) =>
`/admin/session/${strings[0]}/csv`;

const mockGenerateCSVData = jest.fn().mockResolvedValue({
responses: [
{
question: "Is this a test?",
responses: [{ value: "Yes" }],
metadata: {},
},
],
redactedResponses: [],
});
const mockGenerateCSVData = jest.fn().mockResolvedValue([
{
question: "Is this a test?",
responses: [{ value: "Yes" }],
metadata: {},
},
]);
jest.mock("@opensystemslab/planx-core", () => {
return {
CoreDomainClient: jest.fn().mockImplementation(() => ({
Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/admin/session/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function getCSVData(
) {
try {
const $client = getClient();
const { responses } = await $client.export.csvData(req.params.sessionId);
const responses = await $client.export.csvData(req.params.sessionId);

if (req.query?.download) {
stringify(responses, {
Expand Down Expand Up @@ -71,7 +71,7 @@ export async function getRedactedCSVData(
) {
try {
const $client = getClient();
const { redactedResponses } = await $client.export.csvData(
const redactedResponses = await $client.export.csvDataRedacted(
req.params.sessionId,
);

Expand Down
4 changes: 2 additions & 2 deletions api.planx.uk/admin/session/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getHTMLExport: HTMLExportHandler = async (req, res, next) => {
const session = await $client.session.find(req.params.sessionId);
if (!session) throw Error(`Unable to find session ${req.params.sessionId}`);

const { responses } = await $client.export.csvData(req.params.sessionId);
const responses = await $client.export.csvData(req.params.sessionId);
const boundingBox =
session.data.passport.data["property.boundary.site.buffered"];

Expand Down Expand Up @@ -65,7 +65,7 @@ export const getRedactedHTMLExport: HTMLExportHandler = async (
const session = await $client.session.find(req.params.sessionId);
if (!session) throw Error(`Unable to find session ${req.params.sessionId}`);

const { redactedResponses } = await $client.export.csvData(
const redactedResponses = await $client.export.csvDataRedacted(
req.params.sessionId,
);
const boundingBox =
Expand Down
4 changes: 3 additions & 1 deletion api.planx.uk/admin/session/oneAppXML.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const mockGenerateOneAppXML = jest
jest.mock("../../client", () => {
return {
$api: {
generateOneAppXML: () => mockGenerateOneAppXML(),
export: {
oneAppPayload: () => mockGenerateOneAppXML(),
},
},
};
});
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/admin/session/oneAppXML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const getOneAppXML = async (
next: NextFunction,
) => {
try {
const xml = await $api.generateOneAppXML(req.params.sessionId);
const xml = await $api.export.oneAppPayload(req.params.sessionId);
res.set("content-type", "text/xml");
return res.send(xml);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@airbrake/node": "^2.1.8",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#d92224b",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#3a85966",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand Down
Loading

0 comments on commit bf52435

Please sign in to comment.