diff --git a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt index cc3f3908..928c65f5 100644 --- a/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt @@ -123,6 +123,44 @@ class RuleEngineFunctionTest { return null } + @Test + fun actionConditionShouldEvaluateToTrueUsingVariableDefaultValueIfVariableValueIsNull() { + val ruleAction = + RuleAction( + "#{test_variable} > -1", + "DISPLAYTEXT", + mapOf(Pair("content", "test_action_content"), Pair("location", "feedback")), + ) + val ruleVariable: RuleVariable = + RuleVariableCurrentEvent( + "test_variable", + true, + emptyList(), + "test_data_element_one", + RuleValueType.NUMERIC, + ) + val rule = Rule("true", listOf(ruleAction), "", "") + val ruleEngineContext = RuleEngineTestUtils.getRuleEngineContext(rule, listOf(ruleVariable)) + val ruleEvent = + RuleEvent( + "test_event", + "test_program_stage", + "", + RuleEventStatus.ACTIVE, + Clock.System.now(), + Clock.System.now(), + LocalDate.currentDate(), + null, + "", + null, + listOf(), + ) + val ruleEffects = RuleEngine.getInstance().evaluate(ruleEvent, null, emptyList(), ruleEngineContext) + assertEquals(1, ruleEffects.size) + assertEquals("true", ruleEffects[0].data) + assertEquals(ruleAction, ruleEffects[0].ruleAction) + } + @Test fun evaluateHasValueFunctionMustReturnTrueIfValueSpecified() { val ruleAction = @@ -153,12 +191,7 @@ class RuleEngineFunctionTest { null, "", null, - listOf( - RuleDataValue( - "test_data_element_one", - "test_value", - ), - ), + listOf(), ) val ruleEffects = RuleEngine.getInstance().evaluate(ruleEvent, null, emptyList(), ruleEngineContext) assertEquals(1, ruleEffects.size)