Skip to content

Commit

Permalink
Add default value test
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante committed Dec 19, 2024
1 parent c611da6 commit 328ad9a
Showing 1 changed file with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 328ad9a

Please sign in to comment.