Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fetch & flatten the latest published version of external portal data when publishing the parent flow #2783

Merged
merged 30 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a410c6a
update dataMerged in api
jessicamcinchak Feb 13, 2024
9308820
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 15, 2024
791089c
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 16, 2024
20697e3
add public get endpoints for flattened flow data that we can call on …
jessicamcinchak Feb 16, 2024
8db2924
delete dataMergedHotfix in editor, call api
jessicamcinchak Feb 16, 2024
a186785
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 19, 2024
80cebdc
add new /publish-preview route and bubble upaxios error msgs to publi…
jessicamcinchak Feb 19, 2024
7811c03
getFlowData should still return team_id
jessicamcinchak Feb 19, 2024
d547c6d
better error formatting on /publish-preview
jessicamcinchak Feb 20, 2024
10890ec
update dataMerged() tests
jessicamcinchak Feb 20, 2024
3d46fdb
add and update API tests, run prettier
jessicamcinchak Feb 20, 2024
42df2c6
better flattenFlow test coverage
jessicamcinchak Feb 20, 2024
26e779d
dataMerged() tests should share same mock data as flattenFlows()
jessicamcinchak Feb 20, 2024
2c04da8
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 23, 2024
616e6b2
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 26, 2024
9a3decb
pr feedback
jessicamcinchak Feb 26, 2024
5d7a3bd
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 27, 2024
9567f70
don't wrap publishedPreview route in SaveAndReturnLayout
jessicamcinchak Feb 27, 2024
25629bd
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 28, 2024
5c3b104
feat: simplified changelogs on publish (#2811)
jessicamcinchak Feb 28, 2024
76e1e9b
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
jessicamcinchak Feb 28, 2024
84d589a
Merge branch 'jess/fetch-published-portals-on-publish' of github.com:…
jessicamcinchak Feb 28, 2024
51bf520
rename frontend routes and views, not /preview yet
jessicamcinchak Feb 28, 2024
8d05bf7
rename API query param too
jessicamcinchak Feb 28, 2024
cf4143c
run prettier
jessicamcinchak Feb 28, 2024
7409749
minor doc updtae
jessicamcinchak Feb 28, 2024
67dda60
redirect /unpublished to /amber
jessicamcinchak Feb 29, 2024
e3cab8f
fix: if same portal is nested many times at different levels, ensure …
jessicamcinchak Mar 1, 2024
61a8f64
chore: map user ids to names on publish change dialog for nested flow…
jessicamcinchak Mar 4, 2024
e964a15
feat: update and redirect `/preview` to `/published` (#2854)
jessicamcinchak Mar 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AWS_SECRET_KEY=👻
FILE_API_KEY=👻
FILE_API_KEY_NEXUS=👻

# Editor/Preview
# Editor
EDITOR_URL_EXT=http://localhost:3000

# Hasura
Expand Down
163 changes: 76 additions & 87 deletions api.planx.uk/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import {
isLiveEnv,
} from "./helpers";
import { queryMock } from "./tests/graphqlQueryMock";
import { userContext } from "./modules/auth/middleware";
import { getJWT } from "./tests/mockJWT";
import {
childFlow,
draftParentFlow,
flattenedParentFlow,
} from "./tests/mocks/validateAndPublishMocks";

describe("getEnvironment function", () => {
describe("getFormattedEnvironment() function", () => {
const OLD_ENV = process.env;

beforeEach(() => {
Expand Down Expand Up @@ -69,121 +72,107 @@ describe("isLiveEnv() function", () => {
});

describe("dataMerged() function", () => {
const getStoreMock = jest.spyOn(userContext, "getStore");
getStoreMock.mockReturnValue({
user: {
sub: "123",
jwt: getJWT({ role: "teamEditor" }),
},
});

beforeEach(() => {
const unflattenedParent = {
_root: {
edges: ["Zj0ZKa0PwT", "Rur8iS88x3"],
},
"5yElH96W7I": {
data: {
text: "Option 2",
},
type: 200,
edges: ["aMlxwR7ONH"],
},
Rur8iS88x3: {
data: {
color: "#EFEFEF",
title: "End of the line",
resetButton: false,
},
type: 8,
},
SShTHaRo2k: {
data: {
flowId: "child-id",
},
type: 310,
},
Zj0ZKa0PwT: {
data: {
text: "This is a question with many options",
},
type: 100,
edges: ["c8hZwm0a9c", "5yElH96W7I", "UMsI68BuAy"],
},
c8hZwm0a9c: {
data: {
text: "Option 1",
},
type: 200,
edges: ["SShTHaRo2k"],
},
aMlxwR7ONH: {
type: 310,
data: {
flowId: "child-id",
},
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "parent-flow-with-external-portal",
},
UMsI68BuAy: {
type: 200,
data: {
text: "Option 3",
data: {
flow: {
data: draftParentFlow,
slug: "parent-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [{ data: flattenedParentFlow }],
},
},
};
});
});

const unflattenedChild = {
_root: {
edges: ["sbDyJVsyXg"],
it("flattens published external portal nodes by overwriting their type", async () => {
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "child-flow-id",
},
sbDyJVsyXg: {
type: 100,
data: {
description: "<p>Hello there 👋</p>",
text: "This is within the portal",
data: {
flow: {
data: childFlow,
slug: "child-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [{ data: childFlow }],
},
},
};
});

const result = await dataMerged("parent-flow-with-external-portal");
const nodeTypes = Object.values(result).map((node) =>
"type" in node ? node.type : undefined,
);

expect(nodeTypes.includes(ComponentType.ExternalPortal)).toBe(false);
});

it("throws an error when an external portal is not published", async () => {
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "child-id",
id: "child-flow-id",
},
data: {
flow: {
data: childFlow,
slug: "child-flow",
data: unflattenedChild,
team_id: 123,
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [],
},
},
});

await expect(
dataMerged("parent-flow-with-external-portal"),
).rejects.toThrow();
});

it("flattens any published or draft external portal nodes when isDraftData only is set to true", async () => {
queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: true,
variables: {
id: "parent-id",
id: "child-flow-id",
},
data: {
flow: {
slug: "parent-flow",
data: unflattenedParent,
team_id: 123,
data: childFlow,
slug: "child-flow",
team_id: 1,
team: {
slug: "testing",
},
publishedFlows: [],
},
},
});
});

it("handles multiple external portal nodes", async () => {
const result = await dataMerged("parent-id");
const nodeTypes = Object.values(result).map((node) =>
"type" in node ? node.type : undefined,
const result = await dataMerged(
"parent-flow-with-external-portal",
{},
false,
true,
);
const areAllPortalsFlattened = !nodeTypes.includes(
ComponentType.ExternalPortal,
);

// All external portals have been flattened / replaced
expect(areAllPortalsFlattened).toBe(true);
expect(result).toEqual(flattenedParentFlow);
});
});

Expand Down
Loading
Loading