Skip to content

Commit

Permalink
finish basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahscott committed Aug 6, 2021
1 parent 03856bc commit 64ba031
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 115 deletions.
2 changes: 1 addition & 1 deletion api.planx.uk/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ const publishFlow = async (req, res) => {
const publishedFlow =
response.insert_published_flows_one &&
response.insert_published_flows_one.data;

const alteredNodes = Object.keys(delta).map((key) => ({
id: key,
...publishedFlow[key],
}));

res.json({
alteredNodes,
publishedFlow,
});
} else {
res.json({
Expand Down
170 changes: 56 additions & 114 deletions api.planx.uk/publish.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
const supertest = require("supertest");

const { authHeader } = require("./tests/mockJWT");

const { queryMock } = require("./tests/graphqlQueryMock");
const { authHeader } = require("./tests/mockJWT");
const app = require("./server");

beforeEach(() => {
Expand All @@ -11,7 +10,7 @@ beforeEach(() => {
matchOnVariables: false,
data: {
flows_by_pk: {
data: currentFlowData,
data: mockFlowData,
},
},
});
Expand All @@ -23,7 +22,7 @@ beforeEach(() => {
flows_by_pk: {
published_flows: [
{
data: currentFlowDataFlattened,
data: mockFlowData,
},
],
},
Expand All @@ -35,7 +34,7 @@ beforeEach(() => {
matchOnVariables: false,
data: {
insert_published_flows_one: {
data: currentFlowDataFlattened,
data: mockFlowData,
},
},
});
Expand All @@ -54,124 +53,67 @@ it("does not update if there are no new changes", async () => {
});
});

it("updates if there have been changes", async () => {
it("updates published flow and returns altered nodes if there have been changes", async () => {
const alteredFlow = {
...mockFlowData,
"4CJgXe8Ttl": {
data: {
flagSet: "Planning permission",
overrides: {
NO_APP_REQUIRED: {
heading: "Some Other Heading",
},
},
},
type: 3,
},
};

queryMock.mockQuery({
name: "GetFlowData",
matchOnVariables: false,
data: {
flows_by_pk: {
data: alteredFlow,
},
},
});

queryMock.mockQuery({
name: "PublishFlow",
matchOnVariables: false,
data: {
insert_published_flows_one: {
data: alteredFlow,
},
},
});

await supertest(app)
.post("/flows/1/publish")
.set(authHeader())
.expect(200)
.then((res) => {
expect(res.body).toEqual({
alteredNodes: null,
message: "No new changes",
alteredNodes: [
{
id: "4CJgXe8Ttl",
type: 3,
data: {
flagSet: "Planning permission",
overrides: {
NO_APP_REQUIRED: {
heading: "Some Other Heading",
},
},
},
},
],
});
});
});

// MOCK DATA: currentFlowData, currentFlowDataFlattened, stalePublishedFlow
const currentFlowData = {
_root: {
edges: [
"RYYckLE2cH",
"R99ncwKifm",
"3qssvGXmMO",
"SEp0QeNsTS",
"q8Foul9hRN",
"4CJgXe8Ttl",
"dnVqd6zt4N",
],
},
"3qssvGXmMO": {
type: 9,
},
"4CJgXe8Ttl": {
data: {
flagSet: "Planning permission",
overrides: {
NO_APP_REQUIRED: {
heading: "wooo",
},
},
},
type: 3,
},
"5sWfsvXphd": {
data: {
text: "?",
},
type: 200,
},
BV2VJhOC0I: {
data: {
text: "internal question",
},
type: 100,
edges: ["ScjaYmpbVK", "b7j9tq22dj"],
},
OL9JENldcI: {
data: {
text: "!!",
},
type: 200,
},
R99ncwKifm: {
data: {
text: "portal",
},
type: 300,
edges: ["BV2VJhOC0I"],
},
RYYckLE2cH: {
data: {
text: "Question",
},
type: 100,
edges: ["5sWfsvXphd", "OL9JENldcI"],
},
SEp0QeNsTS: {
data: {
fn: "application.fee.payable",
url: "http://localhost:7002/pay",
color: "#EFEFEF",
title: "Pay for your application",
description:
'<p>The planning fee covers the cost of processing your application. Find out more about how planning fees are calculated <a href="https://www.gov.uk/guidance/fees-for-planning-applications" target="_self">here</a>.</p>',
},
type: 400,
},
ScjaYmpbVK: {
data: {
text: "?",
},
type: 200,
},
b7j9tq22dj: {
data: {
text: "*",
},
type: 200,
},
dnVqd6zt4N: {
data: {
heading: "Application sent",
moreInfo:
"<h2>You will be contacted</h2>\n<ul>\n<li>if there is anything missing from the information you have provided so far</li>\n<li>if any additional information is required</li>\n<li>to arrange a site visit, if required</li>\n<li>to inform you whether a certificate has been granted or not</li>\n</ul>\n",
contactInfo:
'<p>You can contact us at <a href="mailto:planning@lambeth.gov.uk" target="_self"><strong>planning@lambeth.gov.uk</strong></a></p>\n',
description:
"A payment receipt has been emailed to you. You will also receive an email to confirm when your application has been received.",
feedbackCTA: "What did you think of this service? (takes 30 seconds)",
},
type: 725,
},
q8Foul9hRN: {
data: {
url: "http://localhost:7002/bops/southwark",
},
type: 650,
},
};

const currentFlowDataFlattened = {
const mockFlowData = {
_root: {
edges: [
"RYYckLE2cH",
Expand All @@ -191,7 +133,7 @@ const currentFlowDataFlattened = {
flagSet: "Planning permission",
overrides: {
NO_APP_REQUIRED: {
heading: "wooo",
heading: "Congratulations!",
},
},
},
Expand Down

0 comments on commit 64ba031

Please sign in to comment.