Skip to content

Commit 3d26dc5

Browse files
authored
feat: Add EQUAL, NOT_EQUAL, GREATER_THAN, GREATER_THAN_INCLUSIVE, LESS_THAN, LESS_THAN_INCLUSIVE (#26)
* feat: Add EQUAL, NOT_EQUAL, GREATER_THAN, GREATER_THAN_INCLUSIVE, LESS_THAN, LESS_THAN_INCLUSIVE * important test change * renames * consistent schema refs * naming improvements
1 parent c69e2eb commit 3d26dc5

File tree

33 files changed

+1458
-4
lines changed

33 files changed

+1458
-4
lines changed

test_cases/test_context_value_jsonpath_pointing_to_object__is_not_set__should_match.jsonc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// Then: The context should be considered part of the segment because paths that lead to non-primitive values are treated as not set
55
//
66
// NOTE: This is a regression test for a bug where paths that lead to non-primitive values were evaluated against comparison operators
7-
// (EQUAL, NOT_EQUAL, etc) instead of being treated as not set, causing undefined behavior.
8-
// There's a potential use case for the `IS_SET`/`IS_NOT_SET` operators to check for the existence of an object, but it's not currently implemented.
9-
// If such a use case arises, we can consider adding support for it.
10-
// For now, the engine implementations are expected to treat paths that lead to non-primitive values as not set.
7+
// (EQUAL, NOT_EQUAL, etc) instead of being treated as not set, causing undefined behavior.
8+
// There's a potential use case for the `IS_SET`/`IS_NOT_SET` operators to check for the existence of an object, but it's not currently implemented.
9+
// If such a use case arises, we can consider adding support for it.
10+
// For now, the engine implementations are expected to treat paths that lead to non-primitive values as not set.
1111
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
1212
"context": {
1313
"environment": {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
// Given: A segment for active users with an EQUAL condition checking if is_active equals "0"
3+
// When: An evaluation context with an identity that has is_active false (boolean)
4+
// Then: The context should not be considered part of the segment
5+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
6+
"context": {
7+
"environment": {
8+
"key": "key",
9+
"name": "Environment"
10+
},
11+
"identity": {
12+
"identifier": "active_user",
13+
"key": "key_active_user",
14+
"traits": {
15+
"is_active": false
16+
}
17+
},
18+
"segments": {
19+
"1": {
20+
"key": "1",
21+
"name": "active_users_segment",
22+
"rules": [
23+
{
24+
"type": "ALL",
25+
"conditions": [
26+
{
27+
"operator": "EQUAL",
28+
"property": "is_active",
29+
"value": "0"
30+
}
31+
]
32+
}
33+
]
34+
}
35+
}
36+
},
37+
"result": {
38+
"flags": {},
39+
"segments": []
40+
}
41+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
// Given: A segment with an EQUAL condition checking if is_active equals "False" and "false"
3+
// When: An evaluation context with an identity that has is_active = false (boolean)
4+
// Then: The context should be considered part of the segment due to type conversion
5+
//
6+
// NOTE: For boolean traits/context values, we expect the engine to perform type conversion
7+
// when comparing against string values "False" and "false".
8+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
9+
"context": {
10+
"environment": {
11+
"key": "key",
12+
"name": "Environment"
13+
},
14+
"identity": {
15+
"identifier": "test_user",
16+
"key": "key_test_user",
17+
"traits": {
18+
"is_active": false
19+
}
20+
},
21+
"segments": {
22+
"1": {
23+
"key": "1",
24+
"name": "test_segment",
25+
"rules": [
26+
{
27+
"type": "ALL",
28+
"conditions": [
29+
{
30+
"operator": "EQUAL",
31+
"property": "is_active",
32+
"value": "False"
33+
},
34+
{
35+
"operator": "EQUAL",
36+
"property": "is_active",
37+
"value": "false"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
}
44+
},
45+
"result": {
46+
"flags": {},
47+
"segments": [
48+
{
49+
"key": "1",
50+
"name": "test_segment"
51+
}
52+
]
53+
}
54+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
// Given: A segment with an EQUAL condition checking if is_active equals "True" and "true"
3+
// When: An evaluation context with an identity that has is_active false (boolean)
4+
// Then: The context should not be considered part of the segment due to value mismatch
5+
//
6+
// NOTE: For boolean traits/context values, we expect the engine to perform type conversion
7+
// when comparing against string values "True" and "true".
8+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
9+
"context": {
10+
"environment": {
11+
"key": "key",
12+
"name": "Environment"
13+
},
14+
"identity": {
15+
"identifier": "test_user",
16+
"key": "key_test_user",
17+
"traits": {
18+
"is_active": false
19+
}
20+
},
21+
"segments": {
22+
"1": {
23+
"key": "1",
24+
"name": "test_segment",
25+
"rules": [
26+
{
27+
"type": "ALL",
28+
"conditions": [
29+
{
30+
"operator": "EQUAL",
31+
"property": "is_active",
32+
"value": "True"
33+
},
34+
{
35+
"operator": "EQUAL",
36+
"property": "is_active",
37+
"value": "true"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
}
44+
},
45+
"result": {
46+
"flags": {},
47+
"segments": []
48+
}
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
// Given: A segment for active users with an EQUAL condition checking if is_active equals "True" and "true"
3+
// When: An evaluation context with an identity that has is_active true (boolean)
4+
// Then: The context should be considered part of the segment due to type conversion
5+
//
6+
// NOTE: For boolean traits/context values, we expect the engine to perform type conversion
7+
// when comparing against string values "True" and "true".
8+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
9+
"context": {
10+
"environment": {
11+
"key": "key",
12+
"name": "Environment"
13+
},
14+
"identity": {
15+
"identifier": "active_user",
16+
"key": "key_active_user",
17+
"traits": {
18+
"is_active": true
19+
}
20+
},
21+
"segments": {
22+
"1": {
23+
"key": "1",
24+
"name": "active_users_segment",
25+
"rules": [
26+
{
27+
"type": "ALL",
28+
"conditions": [
29+
{
30+
"operator": "EQUAL",
31+
"property": "is_active",
32+
"value": "True"
33+
},
34+
{
35+
"operator": "EQUAL",
36+
"property": "is_active",
37+
"value": "true"
38+
}
39+
]
40+
}
41+
]
42+
}
43+
}
44+
},
45+
"result": {
46+
"flags": {},
47+
"segments": [
48+
{
49+
"key": "1",
50+
"name": "active_users_segment"
51+
}
52+
]
53+
}
54+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
// Given: A segment for active users with an EQUAL condition checking if is_active equals "1"
3+
// When: An evaluation context with an identity that has is_active true (boolean)
4+
// Then: The context should be considered part of the segment
5+
//
6+
// NOTE: We're maintaining historical engine behaviour which coerces segment condition value
7+
// to match the type of the identity trait value.
8+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
9+
"context": {
10+
"environment": {
11+
"key": "key",
12+
"name": "Environment"
13+
},
14+
"identity": {
15+
"identifier": "active_user",
16+
"key": "key_active_user",
17+
"traits": {
18+
"is_active": true
19+
}
20+
},
21+
"segments": {
22+
"1": {
23+
"key": "1",
24+
"name": "active_users_segment",
25+
"rules": [
26+
{
27+
"type": "ALL",
28+
"conditions": [
29+
{
30+
"operator": "EQUAL",
31+
"property": "is_active",
32+
"value": "1"
33+
}
34+
]
35+
}
36+
]
37+
}
38+
}
39+
},
40+
"result": {
41+
"flags": {},
42+
"segments": [
43+
{
44+
"key": "1",
45+
"name": "active_users_segment"
46+
}
47+
]
48+
}
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
// Given: A segment for specific version users with an EQUAL condition checking if ratio equals "1.23"
3+
// When: An evaluation context with an identity that has version 1.23 (float)
4+
// Then: The context should be considered part of the segment due to type conversion
5+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
6+
"context": {
7+
"environment": {
8+
"key": "key",
9+
"name": "Environment"
10+
},
11+
"identity": {
12+
"identifier": "ratio_user",
13+
"key": "key_ratio_user",
14+
"traits": {
15+
"ratio": 1.23
16+
}
17+
},
18+
"segments": {
19+
"1": {
20+
"key": "1",
21+
"name": "specific_ratio_users_segment",
22+
"rules": [
23+
{
24+
"type": "ALL",
25+
"conditions": [
26+
{
27+
"operator": "EQUAL",
28+
"property": "ratio",
29+
"value": "1.23"
30+
}
31+
]
32+
}
33+
]
34+
}
35+
}
36+
},
37+
"result": {
38+
"flags": {},
39+
"segments": [
40+
{
41+
"key": "1",
42+
"name": "specific_ratio_users_segment"
43+
}
44+
]
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
// Given: A segment for active users with an EQUAL condition checking if is_active equals "False" and "false"
3+
// When: An evaluation context with an identity that has is_active 0 (integer)
4+
// Then: The context should not be considered part of the segment
5+
"$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json",
6+
"context": {
7+
"environment": {
8+
"key": "key",
9+
"name": "Environment"
10+
},
11+
"identity": {
12+
"identifier": "active_user",
13+
"key": "key_active_user",
14+
"traits": {
15+
"is_active": 0
16+
}
17+
},
18+
"segments": {
19+
"1": {
20+
"key": "1",
21+
"name": "active_users_segment",
22+
"rules": [
23+
{
24+
"type": "ANY",
25+
"conditions": [
26+
{
27+
"operator": "EQUAL",
28+
"property": "is_active",
29+
"value": "False"
30+
},
31+
{
32+
"operator": "EQUAL",
33+
"property": "is_active",
34+
"value": "false"
35+
}
36+
]
37+
}
38+
]
39+
}
40+
}
41+
},
42+
"result": {
43+
"flags": {},
44+
"segments": []
45+
}
46+
}

0 commit comments

Comments
 (0)