...
1 package growthbook
2
3 import "testing"
4
5 func TestConditionValueNullOrNotPresent(t *testing.T) {
6 condition := ParseCondition([]byte(`{"userId": null}`))
7 result := condition.Eval(Attributes{"userId": nil})
8 if result != true {
9 t.Error("1: expected condition evaluation to be true")
10 }
11
12 condition = ParseCondition([]byte(`{}`))
13 result = condition.Eval(Attributes{"userId": nil})
14 if result != true {
15 t.Error("2: expected condition evaluation to be true")
16 }
17 }
18
19 func TestConditionValueIsPresent(t *testing.T) {
20 condition := ParseCondition([]byte(`{"userId": null}`))
21 result := condition.Eval(Attributes{"userId": "123"})
22 if result != false {
23 t.Error("1: expected condition evaluation to be false")
24 }
25 }
26
27 func TestConditionValueIsPresentButFalsy(t *testing.T) {
28 condition := ParseCondition([]byte(`{"userId": null}`))
29 result := condition.Eval(Attributes{"userId": 0})
30 if result != false {
31 t.Error("1: expected condition evaluation to be false")
32 }
33 result = condition.Eval(Attributes{"userId": ""})
34 if result != false {
35 t.Error("2: expected condition evaluation to be false")
36 }
37 }
38
View as plain text