Skip to content

Commit

Permalink
chore: Bump planx-core, update types and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jan 29, 2024
1 parent 31bdf4e commit 708ebb2
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 86 deletions.
41 changes: 18 additions & 23 deletions api.planx.uk/modules/send/bops/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ describe(`sending an application to BOPS`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
bopsSecret: null,
},
},
],
Expand All @@ -72,15 +73,9 @@ describe(`sending an application to BOPS`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: null,
},
},
],
teams: [],
},
variables: {
slug: "unsupported-team",
Expand Down Expand Up @@ -128,9 +123,9 @@ describe(`sending an application to BOPS`, () => {
.post("/bops/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(400)
.expect(500)
.then((res) => {
expect(res.body.error).toMatch(/not enabled for this local authority/);
expect(res.body.error).toMatch(/No team matching "unsupported-team" found/);
});
});

Expand Down Expand Up @@ -187,12 +182,14 @@ describe(`sending an application to BOPS v2`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
// Decodes to "abc123"
bopsSecret: "ccd96ddbcf94af4899a1fe9c88752547:e913b3b604f0610ee57abb822e6cc6fd",
},
},
],
Expand All @@ -203,15 +200,9 @@ describe(`sending an application to BOPS v2`, () => {
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
name: "GetStagingIntegrations",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: null,
},
},
],
teams: [],
},
variables: {
slug: "unsupported-team",
Expand All @@ -220,7 +211,8 @@ describe(`sending an application to BOPS v2`, () => {
});

it("successfully proxies request and returns hasura id", async () => {
nock(`${submissionURL}/api/v2/planning_applications`).post("").reply(200, {
const expectedHeaders = { authorization: "Bearer abc123" };

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "Bearer abc123" is used as
authorization header
.
const nockScope = nock(`${submissionURL}/api/v2/planning_applications`, { reqheaders: expectedHeaders }).post("").reply(200, {
application: "0000123",
});

Expand All @@ -233,6 +225,9 @@ describe(`sending an application to BOPS v2`, () => {
expect(res.body).toEqual({
application: { id: 22, bopsResponse: { application: "0000123" } },
});

// Check nock was called with expected headers
expect(nockScope.isDone()).toBe(true);
});
});

Expand All @@ -259,9 +254,9 @@ describe(`sending an application to BOPS v2`, () => {
.post("/bops-v2/unsupported-team")
.set({ Authorization: process.env.HASURA_PLANX_API_KEY! })
.send({ payload: { sessionId: "123" } })
.expect(400)
.expect(500)
.then((res) => {
expect(res.body.error).toMatch(/not enabled for this local authority/);
expect(res.body.error).toMatch(/No team matching "unsupported-team" found/);
});
});

Expand Down
37 changes: 11 additions & 26 deletions api.planx.uk/modules/send/bops/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,12 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
const localAuthority = req.params.localAuthority;
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";
const bopsSubmissionURL = await $api.team.getBopsSubmissionURL(
localAuthority,

const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
);
const isSupported = Boolean(bopsSubmissionURL);
if (!isSupported) {
return next(
new ServerError({
status: 400,
message: `Back-office Planning System (BOPS) is not enabled for this local authority (${localAuthority})`,
}),
);
}
});
const target = `${bopsSubmissionURL}/api/v1/planning_applications`;
const exportData = await $api.export.bopsPayload(payload?.sessionId);

Expand All @@ -69,7 +62,7 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
adapter: "http",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.BOPS_API_TOKEN}`,
Authorization: `Bearer ${bopsToken || process.env.BOPS_API_TOKEN}`,
},
data: exportData,
})
Expand Down Expand Up @@ -181,19 +174,11 @@ const sendToBOPSV2 = async (
const localAuthority = req.params.localAuthority;
const env =
process.env.APP_ENVIRONMENT === "production" ? "production" : "staging";
const bopsSubmissionURL = await $api.team.getBopsSubmissionURL(
localAuthority,
const { bopsSubmissionURL, bopsToken } = await $api.team.getIntegrations({
slug: localAuthority,
encryptionKey: process.env.ENCRYPTION_KEY!,
env,
);
const isSupported = Boolean(bopsSubmissionURL);
if (!isSupported) {
return next(
new ServerError({
status: 400,
message: `Back-office Planning System (BOPS) is not enabled for this local authority (${localAuthority})`,
}),
);
}
});
const target = `${bopsSubmissionURL}/api/v2/planning_applications`;
const exportData = await $api.export.digitalPlanningDataPayload(
payload?.sessionId,
Expand All @@ -206,7 +191,7 @@ const sendToBOPSV2 = async (
adapter: "http",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.BOPS_API_TOKEN}`,
Authorization: `Bearer ${bopsToken || process.env.BOPS_API_TOKEN}`,
},
data: exportData,
})
Expand Down
3 changes: 2 additions & 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#d1a224c",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ce539b0",
"@types/isomorphic-fetch": "^0.0.36",
"adm-zip": "^0.5.10",
"aws-sdk": "^2.1467.0",
Expand All @@ -18,6 +18,7 @@
"date-fns": "^2.29.3",
"dompurify": "^3.0.6",
"express": "^4.18.2",
"express-async-errors": "^3.1.1",
"express-jwt": "^8.4.1",
"express-pino-logger": "^7.0.0",
"express-rate-limit": "^7.1.5",
Expand Down
29 changes: 18 additions & 11 deletions api.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api.planx.uk/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "isomorphic-fetch";
import "express-async-errors";
import { json, urlencoded } from "body-parser";
import assert from "assert";
import cookieParser from "cookie-parser";
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/api-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"dependencies": {
"@cucumber/cucumber": "^9.3.0",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#d1a224c",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ce539b0",
"axios": "^1.6.0",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests/api-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion e2e/tests/ui-driven/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"postinstall": "./install-dependencies.sh"
},
"dependencies": {
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#d1a224c",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ce539b0",
"axios": "^1.6.2",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
Expand Down
14 changes: 7 additions & 7 deletions e2e/tests/ui-driven/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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#d1a224c",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#ce539b0",
"@tiptap/core": "^2.0.3",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
Loading

0 comments on commit 708ebb2

Please sign in to comment.