Skip to content
Open
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
32 changes: 32 additions & 0 deletions field-logic/src/lib/engine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,36 @@ describe('SurveyEngine', () => {
expect(session.visitedNodes).toContain('q1');
expect(session.visitedNodes).toContain('q2_yes');
});

it('should fallback to default route for unknown operators', () => {
const surveyWithUnknownOperator: SurveyDefinition = {
...mockSurvey,
nodes: [
{
id: "start",
type: "info",
content: { text: "Welcome" },
routing: { default: "q_unknown" }
},
{
id: "q_unknown",
type: "text",
content: { question: "Unknown?" },
routing: {
rules: [
{ operator: "non_existent_op", value: "some_value", target: "q2_yes" }
],
default: "end"
}
},
...mockSurvey.nodes.filter(n => n.id !== "start" && n.id !== "q1")
]
};
const engineWithUnknown = new SurveyEngine(surveyWithUnknownOperator, 'test_session');
engineWithUnknown.start();
engineWithUnknown.submitAnswer(null); // move to q_unknown

const node = engineWithUnknown.submitAnswer("any answer");
expect(node?.id).toBe('end');
});
});