Skip to content

Commit

Permalink
unit test case fixes for ConditionsTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan108 committed Mar 7, 2024
1 parent 595d07b commit 2086939
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/test/kotlin/com/featurevisor/sdk/ConditionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ import com.featurevisor.types.Operator.SEMVER_LESS_THAN_OR_EQUALS
import com.featurevisor.types.Operator.SEMVER_NOT_EQUALS
import com.featurevisor.types.Operator.STARTS_WITH
import io.kotest.matchers.shouldBe
import java.sql.Date
import java.time.LocalDate
import java.util.*
import kotlin.test.BeforeTest
import kotlin.test.Test

class ConditionsTest {

val calendar = Calendar.getInstance()

@Test
fun `EQUALS operator works for strings`() {
val condition =
Expand Down Expand Up @@ -372,22 +378,22 @@ class ConditionsTest {
val condition = Condition.Plain(
attributeKey = "date",
operator = BEFORE,
value = ConditionValue.DateTimeValue(LocalDate.of(2023, 10, 5)),
value = ConditionValue.DateTimeValue(Date.valueOf("2023-10-4")),
)

Conditions.conditionIsMatched(
condition = condition,
context = mapOf("date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 4)))
context = mapOf("date" to AttributeValue.DateValue(Date.valueOf("2022-11-4")))
) shouldBe true

Conditions.conditionIsMatched(
condition = condition,
context = mapOf("date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 5)))
context = mapOf("date" to AttributeValue.DateValue(Date.valueOf("2024-10-4")))
) shouldBe false

Conditions.conditionIsMatched(
condition = condition,
context = mapOf("date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 6)))
context = mapOf("date" to AttributeValue.DateValue(Date.valueOf("2024-10-4")))
) shouldBe false
}

Expand All @@ -396,22 +402,22 @@ class ConditionsTest {
val condition = Condition.Plain(
attributeKey = "date",
operator = AFTER,
value = ConditionValue.DateTimeValue(LocalDate.of(2023, 10, 5)),
value = ConditionValue.DateTimeValue(Date.valueOf("2023-10-4")),
)

Conditions.conditionIsMatched(
condition = condition,
context = mapOf("date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 4)))
context = mapOf("date" to AttributeValue.DateValue(Date.valueOf("2022-10-4")))
) shouldBe false

Conditions.conditionIsMatched(
condition = condition,
context = mapOf("date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 5)))
context = mapOf("date" to AttributeValue.DateValue(Date.valueOf("2022-10-4")))
) shouldBe false

Conditions.conditionIsMatched(
condition = condition,
context = mapOf("date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 6)))
context = mapOf("date" to AttributeValue.DateValue(Date.valueOf("2024-10-4")))
) shouldBe true
}

Expand Down Expand Up @@ -477,7 +483,7 @@ class ConditionsTest {
val beforeCondition = Condition.Plain(
attributeKey = "date",
operator = BEFORE,
value = ConditionValue.DateTimeValue(LocalDate.of(2023, 10, 5)),
value = ConditionValue.DateTimeValue(Date(1632307200000)),
)

val inArrayCondition = Condition.Plain(
Expand Down Expand Up @@ -511,7 +517,7 @@ class ConditionsTest {
val context = mapOf(
"browser_type" to AttributeValue.StringValue("chrome"), // true
"version" to AttributeValue.StringValue("1.2.4"), // true
"date" to AttributeValue.DateValue(LocalDate.of(2023, 10, 6)), // false
"date" to AttributeValue.DateValue(Date.valueOf("2023-10-4")), // false
"letter" to AttributeValue.StringValue("x"), // false
"age" to AttributeValue.IntValue(19), // true
)
Expand Down

0 comments on commit 2086939

Please sign in to comment.