diff --git a/api.planx.uk/modules/flows/validate/helpers.ts b/api.planx.uk/modules/flows/validate/helpers.ts index 577949bbb2..cbc4c3770e 100644 --- a/api.planx.uk/modules/flows/validate/helpers.ts +++ b/api.planx.uk/modules/flows/validate/helpers.ts @@ -22,14 +22,12 @@ export const hasComponentType = ( const nodeIds = Object.entries(flowGraph).filter( (entry): entry is [string, Node] => isComponentType(entry, type), ); + if (fn) { - nodeIds - ?.filter(([_nodeId, nodeData]) => nodeData?.data?.fn === fn) - ?.map(([nodeId, _nodeData]) => nodeId); - } else { - nodeIds?.map(([nodeId, _nodeData]) => nodeId); + return nodeIds.some(([, nodeData]) => nodeData?.data?.fn === fn); } - return Boolean(nodeIds?.length); + + return Boolean(nodeIds.length); }; export const numberOfComponentType = ( diff --git a/api.planx.uk/modules/flows/validate/validate.test.ts b/api.planx.uk/modules/flows/validate/validate.test.ts index 302b50fd14..46aa4a0833 100644 --- a/api.planx.uk/modules/flows/validate/validate.test.ts +++ b/api.planx.uk/modules/flows/validate/validate.test.ts @@ -419,15 +419,9 @@ describe("invite to pay validation on diff", () => { }); it("does not update if invite to pay is enabled, but there is not a Checklist that sets `proposal.projectType`", async () => { - const { - Checklist: _Checklist, - ChecklistOptionOne: _ChecklistOptionOne, - ChecklistOptionTwo: _ChecklistOptionTwo, - ...invalidatedFlow - } = flowWithInviteToPay; - invalidatedFlow["_root"].edges?.splice( - invalidatedFlow["_root"].edges?.indexOf("Checklist"), - ); + const invalidatedFlow = flowWithInviteToPay; + // Remove proposal.projectType, set incorrect variable + invalidatedFlow!.Checklist!.data!.fn = "some.other.variable"; queryMock.mockQuery({ name: "GetFlowData",