Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: retire BOPS v1 submission endpoints and events #2857

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api.planx.uk/lib/hasura/metadata/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface ScheduledEvent {

export interface CombinedResponse {
bops?: ScheduledEventResponse;
bops_v2?: ScheduledEventResponse;
uniform?: ScheduledEventResponse;
email?: ScheduledEventResponse;
}
Expand Down
2 changes: 0 additions & 2 deletions api.planx.uk/modules/admin/routes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Router } from "express";
import { usePlatformAdminAuth } from "../auth/middleware";
import { getOneAppXML } from "./session/oneAppXML";
import { getBOPSPayload } from "./session/bops";
import { getCSVData, getRedactedCSVData } from "./session/csv";
import { getHTMLExport, getRedactedHTMLExport } from "./session/html";
import { generateZip } from "./session/zip";
Expand All @@ -14,7 +13,6 @@ router.use("/admin/", usePlatformAdminAuth);

// TODO: Split the routes below into controller and service components
router.get("/admin/session/:sessionId/xml", getOneAppXML);
router.get("/admin/session/:sessionId/bops", getBOPSPayload);
router.get("/admin/session/:sessionId/csv", getCSVData);
router.get("/admin/session/:sessionId/csv-redacted", getRedactedCSVData);
router.get("/admin/session/:sessionId/html", getHTMLExport);
Expand Down
60 changes: 0 additions & 60 deletions api.planx.uk/modules/admin/session/bops.test.ts

This file was deleted.

31 changes: 0 additions & 31 deletions api.planx.uk/modules/admin/session/bops.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,6 @@ const createPaymentSendEvents = async (
comment: `bops_submission_${payload.sessionId}`,
});
combinedResponse[Destination.BOPS] = bopsEvent;

const isProduction = process.env.APP_ENVIRONMENT === "production";
if (!isProduction) {
const bopsV2Event = await createScheduledEvent({
webhook: `{{HASURA_PLANX_API_URL}}/bops-v2/${teamSlug}`,
schedule_at: new Date(now.getTime() + 30 * 1000),
payload: eventPayload,
comment: `bops_v2_submission_${payload.sessionId}`,
});
combinedResponse["bops_v2"] = bopsV2Event;
}
}

if (destinations.includes(Destination.Email)) {
Expand Down
146 changes: 6 additions & 140 deletions api.planx.uk/modules/send/bops/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import nock from "nock";
import supertest from "supertest";
import { queryMock } from "../../../tests/graphqlQueryMock";
import app from "../../../server";
import { expectedPayload } from "../../../tests/mocks/bopsMocks";
import { expectedPlanningPermissionPayload } from "../../../tests/mocks/digitalPlanningDataMocks";

jest.mock("../../saveAndReturn/service/utils", () => ({
Expand All @@ -18,11 +17,6 @@ jest.mock("@opensystemslab/planx-core", () => {
CoreDomainClient: class extends actualCoreDomainClient {
constructor() {
super();
this.export.bopsPayload = () =>
jest.fn().mockResolvedValue({
exportData: expectedPayload,
redactedExportData: expectedPayload,
});
this.export.digitalPlanningDataPayload = () =>
jest.fn().mockResolvedValue({
exportData: expectedPlanningPermissionPayload,
Expand All @@ -32,135 +26,7 @@ jest.mock("@opensystemslab/planx-core", () => {
};
});

describe(`sending an application to BOPS`, () => {
const submissionURL = "https://test.bops-test.com";

beforeEach(() => {
queryMock.mockQuery({
name: "FindApplication",
data: {
bopsApplications: [],
},
variables: {
session_id: "123",
search_string: "%/api/v1/planning_applications",
},
});

queryMock.mockQuery({
name: "CreateBopsApplication",
matchOnVariables: false,
data: {
insertBopsApplication: { id: 22 },
},
});

queryMock.mockQuery({
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
bopsSecret: null,
},
},
],
},
variables: {
slug: "southwark",
},
});

queryMock.mockQuery({
name: "GetStagingIntegrations",
data: {
teams: [],
},
variables: {
slug: "unsupported-team",
},
});
});

it("proxies request and returns hasura id", async () => {
nock(`${submissionURL}/api/v1/planning_applications`).post("").reply(200, {
application: "0000123",
});

await supertest(app)
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(200)
.then((res) => {
expect(res.body).toEqual({
application: { id: 22, bopsResponse: { application: "0000123" } },
});
});
});

it("requires auth", async () => {
await supertest(app)
.post("/bops/southwark")
.send({ payload: { sessionId: "123" } })
.expect(401);
});

it("throws an error if payload is missing", async () => {
await supertest(app)
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: null })
.expect(400)
.then((res) => {
expect(res.body.error).toMatch(/Missing application/);
});
});

it("throws an error if team is unsupported", async () => {
await supertest(app)
.post("/bops/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(500)
.then((res) => {
expect(res.body.error).toMatch(
/No team matching "unsupported-team" found/,
);
});
});

it("does not re-send an application which has already been submitted", async () => {
queryMock.mockQuery({
name: "FindApplication",
data: {
bopsApplications: [
{ response: { message: "Application created", id: "bops_app_id" } },
],
},
variables: {
session_id: "previously_submitted_app",
search_string: "%/api/v1/planning_applications",
},
});

await supertest(app)
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "previously_submitted_app" } })
.expect(200)
.then((res) => {
expect(res.body).toEqual({
sessionId: "previously_submitted_app",
bopsId: "bops_app_id",
message: "Skipping send, already successfully submitted",
});
});
});
});

describe(`sending an application to BOPS v2`, () => {
describe(`sending an application to BOPS (v2)`, () => {
const submissionURL = "https://test.bops-test.com";

beforeEach(() => {
Expand Down Expand Up @@ -224,7 +90,7 @@ describe(`sending an application to BOPS v2`, () => {
});

await supertest(app)
.post("/bops-v2/southwark")
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(200)
Expand All @@ -240,14 +106,14 @@ describe(`sending an application to BOPS v2`, () => {

it("requires auth", async () => {
await supertest(app)
.post("/bops-v2/southwark")
.post("/bops/southwark")
.send({ payload: { sessionId: "123" } })
.expect(401);
});

it("throws an error if payload is missing", async () => {
await supertest(app)
.post("/bops-v2/southwark")
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: null })
.expect(400)
Expand All @@ -258,7 +124,7 @@ describe(`sending an application to BOPS v2`, () => {

it("throws an error if team is unsupported", async () => {
await supertest(app)
.post("/bops-v2/unsupported-team")
.post("/bops/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(500)
Expand All @@ -284,7 +150,7 @@ describe(`sending an application to BOPS v2`, () => {
});

await supertest(app)
.post("/bops-v2/southwark")
.post("/bops/southwark")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "previously_submitted_app" } })
.expect(200)
Expand Down
Loading
Loading