Skip to content

Commit

Permalink
Add null environment variables to map
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante committed Dec 18, 2024
1 parent 26b1015 commit 593491c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ internal class RuleVariableValueMapBuilder {
listOf(eventDate),
currentDate.toString(),
)
} else {
valueMap[RuleEngineUtils.ENV_VAR_EVENT_DATE] =
RuleVariableValue(
RuleValueType.TEXT,
null,
listOf(),
currentDate.toString(),
);
}
if (ruleEvent.dueDate != null) {
val dueDate = ruleEvent.dueDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,72 @@ class RuleEngineFunctionTest {
assertEquals(ruleAction, ruleEffects[0].ruleAction)
}

@Test
fun evaluateHasValueFunctionMustReturnFalseIfValueNotSpecified() {
val ruleAction =
RuleAction(
"d2:hasValue(V{event_date})",
"DISPLAYTEXT",
mapOf(Pair("content", "test_action_content"), Pair("location", "feedback")),
)
val rule = Rule("d2:hasValue(V{event_date})", listOf(ruleAction), "", "")
val ruleEngineContext = RuleEngineTestUtils.getRuleEngineContext(rule, listOf())
val ruleEvent =
RuleEvent(
"test_event",
"test_program_stage",
"",
RuleEventStatus.ACTIVE,
Instant.DISTANT_FUTURE,
Clock.System.now(),
LocalDate.currentDate(),
null,
"",
null,
listOf(
RuleDataValue(
"test_data_element_one",
"test_value",
),
),
)
val ruleEffects = RuleEngine.getInstance().evaluate(ruleEvent, null, emptyList(), ruleEngineContext)
assertEquals(0, ruleEffects.size)
}

@Test
fun evaluateNotHasValueFunctionMustReturnTrueIfValueNotSpecified() {
val ruleAction =
RuleAction(
"true",
"DISPLAYTEXT",
mapOf(Pair("content", "test_action_content"), Pair("location", "feedback")),
)
val rule = Rule("!d2:hasValue(V{event_date})", listOf(ruleAction), "", "")
val ruleEngineContext = RuleEngineTestUtils.getRuleEngineContext(rule, listOf())
val ruleEvent =
RuleEvent(
"test_event",
"test_program_stage",
"",
RuleEventStatus.ACTIVE,
Instant.DISTANT_FUTURE,
Clock.System.now(),
LocalDate.currentDate(),
null,
"",
null,
listOf(
RuleDataValue(
"test_data_element_one",
"test_value",
),
),
)
val ruleEffects = RuleEngine.getInstance().evaluate(ruleEvent, null, emptyList(), ruleEngineContext)
assertEquals(1, ruleEffects.size)
}

@Test
fun optionSetNameShouldBeUsed() {
val option1 = Option("name1", "code1")
Expand Down

0 comments on commit 593491c

Please sign in to comment.