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: Handle bug on first publish #2391

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions api.planx.uk/editor/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ it("requires a user to have the 'teamEditor' role", async () => {
});

describe("publish", () => {
it("publishes for the first time", async () => {
queryMock.mockQuery({
name: "GetMostRecentPublishedFlow",
matchOnVariables: false,
data: {
flow: {
publishedFlows: [],
},
},
});

await supertest(app).post("/flows/1/publish").set(auth).expect(200);
});

it("does not update if there are no new changes", async () => {
await supertest(app)
.post("/flows/1/publish")
Expand Down
4 changes: 1 addition & 3 deletions api.planx.uk/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ interface PublishedFlows {
// Get the most recent version of a published flow's data (flattened, with external portal nodes)
const getMostRecentPublishedFlow = async (
id: string,
): Promise<Flow["data"]> => {
): Promise<Flow["data"] | undefined> => {
const { flow } = await $public.client.request<PublishedFlows>(
gql`
query GetMostRecentPublishedFlow($id: uuid!) {
Expand All @@ -119,8 +119,6 @@ const getMostRecentPublishedFlow = async (
);

const mostRecent = flow?.publishedFlows?.[0]?.data;
if (!mostRecent) throw Error(`Published flow not found for flow ${id}`);

return mostRecent;
};

Expand Down
2 changes: 2 additions & 0 deletions api.planx.uk/saveAndReturn/validateSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ async function reconcileSessionData({
const alteredSectionIds = new Set<string>();

const currentFlow = await getMostRecentPublishedFlow(sessionData.id);
if (!currentFlow)
throw Error(`Unable to find published flow for flow ${sessionData.id}`);

// create ordered breadcrumbs to be able to look up section IDs later
const orderedBreadcrumbs: OrderedBreadcrumbs = sortBreadcrumbs(
Expand Down
Loading