diff --git a/api.planx.uk/publish.js b/api.planx.uk/publish.js index 99f40f3266..3929aeed48 100644 --- a/api.planx.uk/publish.js +++ b/api.planx.uk/publish.js @@ -108,6 +108,7 @@ 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], @@ -115,7 +116,6 @@ const publishFlow = async (req, res) => { res.json({ alteredNodes, - publishedFlow, }); } else { res.json({ diff --git a/api.planx.uk/publish.test.js b/api.planx.uk/publish.test.js index 7adf3c3e0e..1760ea5e4d 100644 --- a/api.planx.uk/publish.test.js +++ b/api.planx.uk/publish.test.js @@ -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(() => { @@ -11,7 +10,7 @@ beforeEach(() => { matchOnVariables: false, data: { flows_by_pk: { - data: currentFlowData, + data: mockFlowData, }, }, }); @@ -23,7 +22,7 @@ beforeEach(() => { flows_by_pk: { published_flows: [ { - data: currentFlowDataFlattened, + data: mockFlowData, }, ], }, @@ -35,7 +34,7 @@ beforeEach(() => { matchOnVariables: false, data: { insert_published_flows_one: { - data: currentFlowDataFlattened, + data: mockFlowData, }, }, }); @@ -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: - '

The planning fee covers the cost of processing your application. Find out more about how planning fees are calculated here.

', - }, - type: 400, - }, - ScjaYmpbVK: { - data: { - text: "?", - }, - type: 200, - }, - b7j9tq22dj: { - data: { - text: "*", - }, - type: 200, - }, - dnVqd6zt4N: { - data: { - heading: "Application sent", - moreInfo: - "

You will be contacted

\n\n", - contactInfo: - '

You can contact us at planning@lambeth.gov.uk

\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", @@ -191,7 +133,7 @@ const currentFlowDataFlattened = { flagSet: "Planning permission", overrides: { NO_APP_REQUIRED: { - heading: "wooo", + heading: "Congratulations!", }, }, },