Skip to content

Commit

Permalink
add test for SetValue and mock for getValidSchemaValues
Browse files Browse the repository at this point in the history
remove appTypeCheckMocks

shift order of service.ts in publish

set user role for publish.test first publish test

add formatting back to publish.test

refine test return of schema values
  • Loading branch information
RODO94 committed Jan 30, 2025
1 parent 8e11ab6 commit 30e3f50
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 112 deletions.
8 changes: 8 additions & 0 deletions api.planx.uk/modules/flows/publish/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions api.planx.uk/modules/flows/publish/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
8 changes: 6 additions & 2 deletions api.planx.uk/modules/flows/publish/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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<PublishFlow>(
gql`
Expand Down Expand Up @@ -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,
},
);

Expand Down
106 changes: 0 additions & 106 deletions api.planx.uk/tests/mocks/applicationTypeCheckMocks.ts

This file was deleted.

0 comments on commit 30e3f50

Please sign in to comment.