Skip to content

Commit

Permalink
better flattenFlow test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Feb 20, 2024
1 parent 3d46fdb commit 42df2c6
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 6 deletions.
118 changes: 112 additions & 6 deletions api.planx.uk/modules/flows/flattenFlow/flattenFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import supertest from "supertest";

import app from "../../../server";
import { queryMock } from "../../../tests/graphqlQueryMock";
import { mockFlowData } from "../../../tests/mocks/validateAndPublishMocks";
import {
childFlow,
draftParentFlow,
flattenedParentFlow,
mockFlowData,
} from "../../../tests/mocks/validateAndPublishMocks";

beforeEach(() => {
queryMock.mockQuery({
Expand All @@ -14,7 +19,7 @@ beforeEach(() => {
data: {
flow: {
data: mockFlowData,
slug: "mock-flow-name",
slug: "mock-flow",
team_id: 1,
team: {
slug: "testing",
Expand All @@ -23,6 +28,25 @@ beforeEach(() => {
},
},
});

queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "parent-flow-with-external-portal",
},
data: {
flow: {
data: draftParentFlow,
slug: "parent-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [{ data: flattenedParentFlow }],
},
},
});
});

it("is publicly accessible and does not require a user to be signed in", async () => {
Expand All @@ -40,11 +64,93 @@ it("returns the expected result for a simple flow without external portals", asy
});
});

it.todo("throws an error for a flow with unpublished external portals");
it("returns the expected result for a simple flow without external portals when the ?unpublished=true query param is set", async () => {
await supertest(app)
.get("/flows/basic-flow-no-external-portals/flatten-data?unpublished=true")
.expect(200)
.then((res) => {
expect(res.body).toEqual(mockFlowData);
});
});

it("returns the expected result for a flow with published external portals", async () => {
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "child-flow-id",
},
data: {
flow: {
data: childFlow,
slug: "child-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [{ data: childFlow }],
},
},
});

await supertest(app)
.get("/flows/parent-flow-with-external-portal/flatten-data")
.expect(200)
.then((res) => expect(res.body).toEqual(flattenedParentFlow));
});

it("throws an error for a flow with unpublished external portals", async () => {
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "child-flow-id",
},
data: {
flow: {
data: childFlow,
slug: "child-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [],
},
},
});

await supertest(app)
.get("/flows/parent-flow-with-external-portal/flatten-data")
.expect(500);
});

it("returns the expected draft result for a flow with unpublished external portals when ?unpublished=true query param is set", async () => {
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "child-flow-id",
},
data: {
flow: {
data: childFlow,
slug: "child-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [],
},
},
});

it.todo(
"returns the expected draft result for a flow with unpublished external portals if ?unpublished=true query param is set",
);
await supertest(app)
.get(
"/flows/parent-flow-with-external-portal/flatten-data?unpublished=true",
)
.expect(200)
.then((res) => expect(res.body).toEqual(flattenedParentFlow));
});

it("throws an error if no flow is found", async () => {
await supertest(app).get("/flows/invalid-id/flatten-data").expect(500);
Expand Down
113 changes: 113 additions & 0 deletions api.planx.uk/tests/mocks/validateAndPublishMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,116 @@ export const mockFlowData: FlowGraph = {
type: 650,
},
};

export const draftParentFlow: FlowGraph = {
_root: {
edges: ["ContentNode", "ExternalPortalNode", "NoticeNode"],
},
ContentNode: {
type: 250,
data: {
content: "<p>This is a test flow with external portal content</p>",
},
},
NoticeNode: {
type: 8,
data: {
title: "End of test",
color: "#EFEFEF",
resetButton: true,
},
},
ExternalPortalNode: {
type: 310,
data: {
flowId: "child-flow-id",
},
},
};

export const flattenedParentFlow: FlowGraph = {
_root: {
edges: ["ContentNode", "ExternalPortalNode", "NoticeNode"],
},
ContentNode: {
data: {
content: "<p>This is a test flow with external portal content</p>",
},
type: 250,
},
NoticeNode: {
data: {
color: "#EFEFEF",
title: "End of test",
resetButton: true,
},
type: 8,
},
ExternalPortalNode: {
type: 300,
edges: ["child-flow-id"],
},
"child-flow-id": {
edges: ["QuestionInsidePortal"],
type: 300,
data: {
text: "child-flow",
},
},
OptionB: {
data: {
text: "B",
},
type: 200,
},
OptionC: {
data: {
text: "C",
},
type: 200,
},
QuestionInsidePortal: {
data: {
text: "This is a question in a flow referenced as an external portal",
},
type: 100,
edges: ["OptionA", "OptionB", "OptionC"],
},
OptionA: {
data: {
text: "A",
},
type: 200,
},
};

export const childFlow: FlowGraph = {
_root: {
edges: ["QuestionInsidePortal"],
},
OptionB: {
data: {
text: "B",
},
type: 200,
},
OptionC: {
data: {
text: "C",
},
type: 200,
},
QuestionInsidePortal: {
data: {
text: "This is a question in a flow referenced as an external portal",
},
type: 100,
edges: ["OptionA", "OptionB", "OptionC"],
},
OptionA: {
data: {
text: "A",
},
type: 200,
},
};

0 comments on commit 42df2c6

Please sign in to comment.