Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicamcinchak committed Mar 15, 2024
2 parents f4d2500 + a5ac624 commit 26c6e82
Show file tree
Hide file tree
Showing 85 changed files with 2,835 additions and 725 deletions.
15 changes: 1 addition & 14 deletions .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 Expand Up @@ -87,28 +87,15 @@ SUPPRESS_LOGS=true

# Local authority specific integrations
## Lambeth
GOV_UK_PAY_TOKEN_LAMBETH=👻
UNIFORM_CLIENT_LAMBETH=👻

## Southwark
GOV_UK_PAY_TOKEN_SOUTHWARK=👻
UNIFORM_CLIENT_SOUTHWARK=👻

## Buckinghamshire
GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE=👻
UNIFORM_CLIENT_AYLESBURY_VALE=👻
UNIFORM_CLIENT_CHILTERN=👻
UNIFORM_CLIENT_WYCOMBE=👻

## Camden
GOV_UK_PAY_TOKEN_CAMDEN=👻

## Gloucester
GOV_UK_PAY_TOKEN_GLOUCESTER=👻

## Medway
GOV_UK_PAY_TOKEN_MEDWAY=👻

## End-to-end test team (borrows Lambeth's details)
GOV_UK_PAY_SECRET_E2E=👻
GOV_UK_PAY_TOKEN_E2E=👻
21 changes: 1 addition & 20 deletions api.planx.uk/.env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,4 @@ UNIFORM_SUBMISSION_URL=👻

SLACK_WEBHOOK_URL=👻

ORDNANCE_SURVEY_API_KEY=👻

# Local authority specific integrations
## Lambeth
GOV_UK_PAY_TOKEN_LAMBETH=👻

## Southwark
GOV_UK_PAY_TOKEN_SOUTHWARK=👻

## Buckinghamshire
GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE=👻

## Camden
GOV_UK_PAY_TOKEN_CAMDEN=👻

## Gloucester
GOV_UK_PAY_TOKEN_GLOUCESTER=👻

## Medway
GOV_UK_PAY_TOKEN_MEDWAY=👻
ORDNANCE_SURVEY_API_KEY=👻
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

0 comments on commit 26c6e82

Please sign in to comment.