diff --git a/api.planx.uk/modules/flows/publish/helpers.test.ts b/api.planx.uk/modules/flows/publish/helpers.test.ts index 8c1c30926d..d254e8f830 100644 --- a/api.planx.uk/modules/flows/publish/helpers.test.ts +++ b/api.planx.uk/modules/flows/publish/helpers.test.ts @@ -5,6 +5,14 @@ import { import { hasStatutoryApplicationType } from "./helpers.js"; describe("hasStatutoryApplicationPath", () => { + beforeAll(() => { + vi.mock("@opensystemslab/planx-core", () => { + return { + getValidSchemaValues: vi.fn().mockImplementation(() => ["ldc"]), + }; + }); + }); + test("returns false for a flow that doesn't have a Send", () => { expect(hasStatutoryApplicationType(mockStatutoryFlowWithoutSend)).toEqual( false, diff --git a/api.planx.uk/modules/flows/publish/publish.test.ts b/api.planx.uk/modules/flows/publish/publish.test.ts index b9a0571013..c0c7f837c4 100644 --- a/api.planx.uk/modules/flows/publish/publish.test.ts +++ b/api.planx.uk/modules/flows/publish/publish.test.ts @@ -82,10 +82,8 @@ describe("publish", () => { }, }, }); - await supertest(app) - .post("/flows/1/publish") - .set(authHeader({ role: "platformAdmin" })) - .expect(200); + + await supertest(app).post("/flows/1/publish").set(auth).expect(200); }); it("does not update if there are no new changes", async () => { diff --git a/api.planx.uk/modules/flows/publish/service.ts b/api.planx.uk/modules/flows/publish/service.ts index adf1d4e12a..cb60fdea60 100644 --- a/api.planx.uk/modules/flows/publish/service.ts +++ b/api.planx.uk/modules/flows/publish/service.ts @@ -9,6 +9,7 @@ import { import { userContext } from "../../auth/middleware.js"; import { getClient } from "../../../client/index.js"; import { hasComponentType } from "../validate/helpers.js"; +import { hasStatutoryApplicationType } from "./helpers.js"; interface PublishFlow { publishedFlow: { @@ -26,11 +27,14 @@ export const publishFlow = async (flowId: string, summary?: string) => { const flattenedFlow = await dataMerged(flowId); const mostRecent = await getMostRecentPublishedFlow(flowId); - const hasSendComponent = hasComponentType(flattenedFlow, ComponentType.Send); const delta = jsondiffpatch.diff(mostRecent, flattenedFlow); if (!delta) return null; + const hasSendComponent = hasComponentType(flattenedFlow, ComponentType.Send); + const isStatutoryApplication = + hasSendComponent && hasStatutoryApplicationType(flattenedFlow); + const { client: $client } = getClient(); const response = await $client.request( gql` @@ -67,7 +71,7 @@ export const publishFlow = async (flowId: string, summary?: string) => { publisher_id: parseInt(userId), summary: summary ?? null, has_send_component: hasSendComponent, - is_statutory_application_type: false, + is_statutory_application_type: isStatutoryApplication, }, ); diff --git a/api.planx.uk/tests/mocks/applicationTypeCheckMocks.ts b/api.planx.uk/tests/mocks/applicationTypeCheckMocks.ts deleted file mode 100644 index ebb2726e2a..0000000000 --- a/api.planx.uk/tests/mocks/applicationTypeCheckMocks.ts +++ /dev/null @@ -1,106 +0,0 @@ -const setValueApplicationTypeBase = { - SetValueAppType: { - data: { - fn: "application.type", - val: "", - operation: "replace", - }, - type: 380, - }, -}; - -const questionApplicationTypeBase = { - ApplicationType: { - data: { - fn: "application.type", - tags: [], - text: "What kind of is application this?", - neverAutoAnswer: false, - }, - type: 100, - edges: ["LDC", "PP"], - }, - LDC: { - data: { - text: "Lawful development certificate", - val: "", - }, - type: 200, - }, - PP: { - data: { - text: "Planning permission", - val: "", - }, - type: 200, - }, -}; - -const checklistApplicationTypeBase = { - ChecklistAppType: { - data: { - fn: "application.type", - text: "App Type", - allRequired: false, - neverAutoAnswer: false, - }, - type: 105, - edges: ["Outline"], - }, - Outline: { - data: { - val: "", - text: "Planning permission outline", - }, - type: 200, - }, -}; - -export const setValueApplicationTypePass = { - SetValueAppType: { - ...setValueApplicationTypeBase.SetValueAppType, - data: { - ...setValueApplicationTypeBase.SetValueAppType.data, - val: "pp.full.major", - }, - }, -}; - -export const questionApplicationTypePass = { - ApplicationType: { ...questionApplicationTypeBase.ApplicationType }, - LDC: { - data: { - ...questionApplicationTypeBase.LDC.data, - val: "ldc.listedBuildingWorks", - }, - }, - PP: { data: { ...questionApplicationTypeBase.PP.data, val: "pp.full" } }, -}; - -export const checklistApplicationTypePass = { - ApplicationType: { ...checklistApplicationTypeBase.ChecklistAppType }, - Outline: { - data: { ...checklistApplicationTypeBase.Outline.data, val: "pp.outline" }, - }, -}; -export const applicationTypeFail = { - SetValueAppType: { - ...setValueApplicationTypeBase.SetValueAppType, - data: { - ...setValueApplicationTypeBase.SetValueAppType.data, - val: "pj.jam.major", - }, - }, - ApplicationType: { ...checklistApplicationTypeBase.ChecklistAppType }, - Outline: { - data: { ...checklistApplicationTypeBase.Outline.data, val: "pj.bagels" }, - }, - QuestionType: { ...questionApplicationTypeBase.ApplicationType }, - LDC: { - data: { - ...questionApplicationTypeBase.LDC.data, - val: "pda.toomuch", - }, - }, - PP: { data: { ...questionApplicationTypeBase.PP.data, val: "pj.bagels" } }, -};