diff --git a/src/models/session/logic.test.ts b/src/models/session/logic.test.ts index 13c229de..09a182ff 100644 --- a/src/models/session/logic.test.ts +++ b/src/models/session/logic.test.ts @@ -80,8 +80,8 @@ describe("getPathForNode", () => { it("returns a path for a complex flow", () => { const path = getPathForNode({ nodeId: "kTEuqpqCh2", flow }); - expect(path).toHaveLength(57); - expect(path[56].id).toBe("_root"); + expect(path).toHaveLength(58); + expect(path[57].id).toBe("_root"); expect(path[0].id).toBe("kTEuqpqCh2"); const pathIds = path.map(({ id }) => id); diff --git a/src/models/session/logic.ts b/src/models/session/logic.ts index 3606d8ad..beb6b121 100644 --- a/src/models/session/logic.ts +++ b/src/models/session/logic.ts @@ -123,10 +123,9 @@ const buildAnswerData = (crumb: Crumb, flow: FlowGraph) => } }, {}); -type GetPathForNode = (params: { - nodeId: string; - flow: OrderedFlow; -}) => { id: string; type: ComponentType | "_root" }[]; +type Path = { id: string; type: ComponentType | "_root" }[]; + +type GetPathForNode = (params: { nodeId: string; flow: OrderedFlow }) => Path; /** * Return a "path" for a given node which represents it's placement relative to the root node @@ -138,17 +137,17 @@ export const getPathForNode: GetPathForNode = ({ nodeId, flow }) => { return acc; }, {} as IndexedFlowGraph); - const path: ReturnType = []; + const path: Path = []; const traverseGraph = (currentNodeId: string) => { const { id, type, parentId } = indexedFlow[currentNodeId]; + path.push({ id, type }); if (parentId === "_root") { path.push({ id: "_root", type: "_root" }); return; } - path.push({ id, type }); traverseGraph(parentId); };