-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update fn for checking stat app and adjust files
- Loading branch information
Showing
5 changed files
with
145 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { | ||
ComponentType as TYPES, | ||
type FlowGraph, | ||
} from "@opensystemslab/planx-core/types"; | ||
import { hasStatutoryApplicationType } from "./helpers.js"; | ||
|
||
const mockStatutoryFlow: FlowGraph = { | ||
_root: { | ||
edges: ["QuestionOne", "Send"], | ||
}, | ||
QuestionTwo: { | ||
data: { | ||
fn: "application.type", | ||
text: "What type of application is it?", | ||
neverAutoAnswer: false, | ||
}, | ||
type: TYPES.Question, | ||
edges: [ | ||
"AnswerWithDiscretionaryApplicationValue", | ||
"AnswerWithStatutoryApplicationValue", | ||
"VeeQdrkcef", | ||
], | ||
}, | ||
AnswerWithDiscretionaryApplicationValue: { | ||
data: { | ||
val: "findOut", | ||
text: "Find out if", | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
VeeQdrkcef: { | ||
data: { | ||
text: "Something else", | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
AnswerWithStatutoryApplicationValue: { | ||
data: { | ||
val: "ldc", | ||
text: "LDC", | ||
}, | ||
type: TYPES.Answer, | ||
}, | ||
QuestionOne: { | ||
type: TYPES.Question, | ||
data: { | ||
text: "Branching question", | ||
neverAutoAnswer: false, | ||
}, | ||
edges: ["7lDopQVOjk", "V5ZV8milBj"], | ||
}, | ||
"7lDopQVOjk": { | ||
type: TYPES.Answer, | ||
data: { | ||
text: "Left", | ||
}, | ||
edges: ["QuestionTwo"], | ||
}, | ||
V5ZV8milBj: { | ||
type: TYPES.Answer, | ||
data: { | ||
text: "Right", | ||
}, | ||
}, | ||
Send: { | ||
type: TYPES.Send, | ||
data: { | ||
title: "Send to email", | ||
destinations: ["email"], | ||
}, | ||
}, | ||
}; | ||
|
||
const mockStatutoryFlowWithoutSend = { ...mockStatutoryFlow }; | ||
delete mockStatutoryFlowWithoutSend["Send"]; | ||
|
||
describe("hasStatutoryApplicationPath", () => { | ||
test("returns false for a flow that doesn't have a Send", () => { | ||
expect(hasStatutoryApplicationType(mockStatutoryFlowWithoutSend)).toEqual( | ||
false, | ||
); | ||
}); | ||
|
||
test.todo("returns false for a flow with Send but not any application.type"); | ||
|
||
test.todo( | ||
"returns false for a flow with Send but only discretionary application.type values", | ||
); | ||
|
||
test("returns true for a flow with Send and at least one statutory application.type value", () => { | ||
expect(hasStatutoryApplicationType(mockStatutoryFlow)).toEqual(true); | ||
}); | ||
}); | ||
|
||
// TODO also add mocks which use SetValue, etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
ComponentType, | ||
type FlowGraph, | ||
} from "@opensystemslab/planx-core/types"; | ||
import { hasComponentType } from "../validate/helpers.js"; | ||
import { getValidSchemaValues } from "@opensystemslab/planx-core"; | ||
|
||
export const hasStatutoryApplicationType = (flattenedFlow: FlowGraph) => { | ||
const hasSendComponent = hasComponentType(flattenedFlow, ComponentType.Send); | ||
if (!hasSendComponent) return false; | ||
|
||
const statutoryApplicationTypes = getValidSchemaValues("ApplicationType"); | ||
if (!statutoryApplicationTypes) return false; | ||
|
||
let isStatutoryApplication = false; | ||
Object.entries(flattenedFlow).some(([nodeId, _nodeData]) => { | ||
const nodeToCheck = flattenedFlow[nodeId]; | ||
|
||
// Only continue if application.type exists in a Node | ||
if (nodeToCheck?.data?.fn === "application.type") { | ||
// Check SetValue as data.val will be in node, not edge | ||
if (typeof nodeToCheck.data?.val === "string") { | ||
isStatutoryApplication = statutoryApplicationTypes.includes( | ||
nodeToCheck.data?.val, | ||
); | ||
return isStatutoryApplication; | ||
} | ||
|
||
// Check other Nodes which have Edges | ||
if (nodeToCheck.edges) { | ||
// Loop through each edge and check the value | ||
nodeToCheck.edges.some((edge) => { | ||
const edgeData = flattenedFlow[edge].data; | ||
if (typeof edgeData?.val === "string") { | ||
isStatutoryApplication = statutoryApplicationTypes.includes( | ||
edgeData.val, | ||
); | ||
return isStatutoryApplication; | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
return isStatutoryApplication; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.