Skip to content

Commit

Permalink
fix: Ensure hasComponentType checks fn value (#4014)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Nov 28, 2024
1 parent bce9028 commit 7a523e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
10 changes: 4 additions & 6 deletions api.planx.uk/modules/flows/validate/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
12 changes: 3 additions & 9 deletions api.planx.uk/modules/flows/validate/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7a523e9

Please sign in to comment.