diff --git a/api.planx.uk/modules/send/bops/bops.test.ts b/api.planx.uk/modules/send/bops/bops.test.ts index d173ed2f65..4a6d5051c2 100644 --- a/api.planx.uk/modules/send/bops/bops.test.ts +++ b/api.planx.uk/modules/send/bops/bops.test.ts @@ -164,6 +164,8 @@ describe(`sending an application to BOPS`, () => { }); describe(`sending an application to BOPS v2`, () => { + const submissionURL = "https://test.bops-test.com"; + beforeEach(() => { queryMock.mockQuery({ name: "FindApplication", @@ -183,6 +185,38 @@ describe(`sending an application to BOPS v2`, () => { insertBopsApplication: { id: 22 }, }, }); + + queryMock.mockQuery({ + name: "GetStagingBopsSubmissionURL", + data: { + teams: [ + { + integrations: { + bopsSubmissionURL: submissionURL, + }, + }, + ], + }, + variables: { + slug: "southwark", + }, + }); + + queryMock.mockQuery({ + name: "GetStagingBopsSubmissionURL", + data: { + teams: [ + { + integrations: { + bopsSubmissionURL: null, + }, + }, + ], + }, + variables: { + slug: "unsupported-team", + }, + }); }); it("successfully proxies request and returns hasura id", async () => { diff --git a/api.planx.uk/modules/send/bops/bops.ts b/api.planx.uk/modules/send/bops/bops.ts index bf4b7ad447..22e4568a11 100644 --- a/api.planx.uk/modules/send/bops/bops.ts +++ b/api.planx.uk/modules/send/bops/bops.ts @@ -178,9 +178,21 @@ const sendToBOPSV2 = async ( // a local or staging API instance should send to the BOPS staging endpoint // production should send to the BOPS production endpoint const localAuthority = req.params.localAuthority; - const bopsSubmissionURLEnvName = `BOPS_SUBMISSION_URL_${localAuthority.toUpperCase()}`; - const bopsSubmissionURL = process.env[bopsSubmissionURLEnvName]; + const env = process.env.NODE_ENV === "production" ? "production" : "staging"; + const bopsSubmissionURL = await $api.team.getBopsSubmissionURL( + localAuthority, + 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})`, + }), + ); + } + if (!isSupported) { return next( new ServerError({