From 6c381ccadf6da73dedf6aff35e96d24546359a1e Mon Sep 17 00:00:00 2001 From: wadii Date: Mon, 4 May 2026 10:35:24 +0200 Subject: [PATCH 1/2] feat: added tests supporting sub nested rules in segment --- ...__no_group_matches__should_not_match.jsonc | 94 ++++++++++++++++++ ...ups__one_group_matches__should_match.jsonc | 98 +++++++++++++++++++ ...ed_all_groups__match__should_exclude.jsonc | 80 +++++++++++++++ 3 files changed, 272 insertions(+) create mode 100644 test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc create mode 100644 test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc create mode 100644 test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc diff --git a/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc b/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc new file mode 100644 index 0000000..4df897b --- /dev/null +++ b/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc @@ -0,0 +1,94 @@ +{ + // Given: A segment with an ANY rule containing two ALL sub-rule groups + // When: Identity traits match neither group (wrong user_id for Production) + // Then: The segment should not match + "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", + "context": { + "environment": { + "key": "key", + "name": "Production" + }, + "identity": { + "identifier": "user_2", + "key": "key_user_2", + "traits": { + "user_id": "999" + } + }, + "segments": { + "100": { + "key": "100", + "name": "user_per_env", + "rules": [ + { + "type": "ALL", + "rules": [ + { + "type": "ANY", + "rules": [ + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "$.environment.name", + "value": "Production" + }, + { + "operator": "EQUAL", + "property": "user_id", + "value": "123" + } + ] + }, + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "$.environment.name", + "value": "QA" + }, + { + "operator": "EQUAL", + "property": "user_id", + "value": "456" + } + ] + } + ] + } + ] + } + ], + "overrides": [ + { + "enabled": true, + "key": "1", + "name": "test_feature", + "value": "overridden" + } + ] + } + }, + "features": { + "test_feature": { + "enabled": false, + "key": "1", + "name": "test_feature", + "value": "default" + } + } + }, + "result": { + "flags": { + "test_feature": { + "enabled": false, + "name": "test_feature", + "value": "default", + "reason": "DEFAULT" + } + }, + "segments": [] + } +} diff --git a/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc b/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc new file mode 100644 index 0000000..46cf7db --- /dev/null +++ b/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc @@ -0,0 +1,98 @@ +{ + // Given: A segment with an ANY rule containing two ALL sub-rule groups + // When: Identity traits match one group (Production + user 123) but not the other + // Then: The segment should match (ANY = OR between groups) + "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", + "context": { + "environment": { + "key": "key", + "name": "Production" + }, + "identity": { + "identifier": "user_1", + "key": "key_user_1", + "traits": { + "user_id": "123" + } + }, + "segments": { + "100": { + "key": "100", + "name": "user_per_env", + "rules": [ + { + "type": "ALL", + "rules": [ + { + "type": "ANY", + "rules": [ + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "$.environment.name", + "value": "Production" + }, + { + "operator": "EQUAL", + "property": "user_id", + "value": "123" + } + ] + }, + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "$.environment.name", + "value": "QA" + }, + { + "operator": "EQUAL", + "property": "user_id", + "value": "456" + } + ] + } + ] + } + ] + } + ], + "overrides": [ + { + "enabled": true, + "key": "1", + "name": "test_feature", + "value": "overridden" + } + ] + } + }, + "features": { + "test_feature": { + "enabled": false, + "key": "1", + "name": "test_feature", + "value": "default" + } + } + }, + "result": { + "flags": { + "test_feature": { + "enabled": true, + "name": "test_feature", + "value": "overridden", + "reason": "TARGETING_MATCH; segment=user_per_env" + } + }, + "segments": [ + { + "name": "user_per_env" + } + ] + } +} diff --git a/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc b/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc new file mode 100644 index 0000000..f6eca1a --- /dev/null +++ b/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc @@ -0,0 +1,80 @@ +{ + // Given: A segment with a NONE rule containing an ALL sub-rule group + // When: Identity traits match the ALL group (is_bot = true) + // Then: The segment should not match (NONE excludes matching groups) + "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", + "context": { + "environment": { + "key": "key", + "name": "Production" + }, + "identity": { + "identifier": "bot_user", + "key": "key_bot_user", + "traits": { + "is_bot": "true", + "tier": "free" + } + }, + "segments": { + "200": { + "key": "200", + "name": "exclude_bots", + "rules": [ + { + "type": "ALL", + "rules": [ + { + "type": "NONE", + "rules": [ + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "is_bot", + "value": "true" + }, + { + "operator": "EQUAL", + "property": "tier", + "value": "free" + } + ] + } + ] + } + ] + } + ], + "overrides": [ + { + "enabled": true, + "key": "1", + "name": "test_feature", + "value": "overridden" + } + ] + } + }, + "features": { + "test_feature": { + "enabled": false, + "key": "1", + "name": "test_feature", + "value": "default" + } + } + }, + "result": { + "flags": { + "test_feature": { + "enabled": false, + "name": "test_feature", + "value": "default", + "reason": "DEFAULT" + } + }, + "segments": [] + } +} From c5f51e31274ab05058109b087d4acbf41bd0bf27 Mon Sep 17 00:00:00 2001 From: wadii Date: Mon, 4 May 2026 17:28:52 +0200 Subject: [PATCH 2/2] feat: added tests supporting any top level rule --- ...__no_group_matches__should_not_match.jsonc | 55 +++++++++---------- ...ups__one_group_matches__should_match.jsonc | 55 +++++++++---------- ...ed_all_groups__match__should_exclude.jsonc | 31 +++++------ 3 files changed, 63 insertions(+), 78 deletions(-) diff --git a/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc b/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc index 4df897b..7700182 100644 --- a/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc +++ b/test_cases/test_any_rule_with_nested_all_groups__no_group_matches__should_not_match.jsonc @@ -1,5 +1,5 @@ { - // Given: A segment with an ANY rule containing two ALL sub-rule groups + // Given: A segment with a top-level ANY rule containing ALL sub-rule groups // When: Identity traits match neither group (wrong user_id for Production) // Then: The segment should not match "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", @@ -21,40 +21,35 @@ "name": "user_per_env", "rules": [ { - "type": "ALL", + "type": "ANY", "rules": [ { - "type": "ANY", - "rules": [ + "type": "ALL", + "conditions": [ { - "type": "ALL", - "conditions": [ - { - "operator": "EQUAL", - "property": "$.environment.name", - "value": "Production" - }, - { - "operator": "EQUAL", - "property": "user_id", - "value": "123" - } - ] + "operator": "EQUAL", + "property": "$.environment.name", + "value": "Production" }, { - "type": "ALL", - "conditions": [ - { - "operator": "EQUAL", - "property": "$.environment.name", - "value": "QA" - }, - { - "operator": "EQUAL", - "property": "user_id", - "value": "456" - } - ] + "operator": "EQUAL", + "property": "user_id", + "value": "123" + } + ] + }, + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "$.environment.name", + "value": "QA" + }, + { + "operator": "EQUAL", + "property": "user_id", + "value": "456" } ] } diff --git a/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc b/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc index 46cf7db..e067598 100644 --- a/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc +++ b/test_cases/test_any_rule_with_nested_all_groups__one_group_matches__should_match.jsonc @@ -1,5 +1,5 @@ { - // Given: A segment with an ANY rule containing two ALL sub-rule groups + // Given: A segment with a top-level ANY rule containing ALL sub-rule groups // When: Identity traits match one group (Production + user 123) but not the other // Then: The segment should match (ANY = OR between groups) "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", @@ -21,40 +21,35 @@ "name": "user_per_env", "rules": [ { - "type": "ALL", + "type": "ANY", "rules": [ { - "type": "ANY", - "rules": [ + "type": "ALL", + "conditions": [ { - "type": "ALL", - "conditions": [ - { - "operator": "EQUAL", - "property": "$.environment.name", - "value": "Production" - }, - { - "operator": "EQUAL", - "property": "user_id", - "value": "123" - } - ] + "operator": "EQUAL", + "property": "$.environment.name", + "value": "Production" }, { - "type": "ALL", - "conditions": [ - { - "operator": "EQUAL", - "property": "$.environment.name", - "value": "QA" - }, - { - "operator": "EQUAL", - "property": "user_id", - "value": "456" - } - ] + "operator": "EQUAL", + "property": "user_id", + "value": "123" + } + ] + }, + { + "type": "ALL", + "conditions": [ + { + "operator": "EQUAL", + "property": "$.environment.name", + "value": "QA" + }, + { + "operator": "EQUAL", + "property": "user_id", + "value": "456" } ] } diff --git a/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc b/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc index f6eca1a..39860bd 100644 --- a/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc +++ b/test_cases/test_none_rule_with_nested_all_groups__match__should_exclude.jsonc @@ -1,6 +1,6 @@ { - // Given: A segment with a NONE rule containing an ALL sub-rule group - // When: Identity traits match the ALL group (is_bot = true) + // Given: A segment with a top-level NONE rule containing an ALL sub-rule group + // When: Identity traits match the ALL group (is_bot = true AND tier = free) // Then: The segment should not match (NONE excludes matching groups) "$schema": "https://raw.githubusercontent.com/Flagsmith/engine-test-data/refs/tags/v2.0.0/schema.json", "context": { @@ -22,25 +22,20 @@ "name": "exclude_bots", "rules": [ { - "type": "ALL", + "type": "NONE", "rules": [ { - "type": "NONE", - "rules": [ + "type": "ALL", + "conditions": [ { - "type": "ALL", - "conditions": [ - { - "operator": "EQUAL", - "property": "is_bot", - "value": "true" - }, - { - "operator": "EQUAL", - "property": "tier", - "value": "free" - } - ] + "operator": "EQUAL", + "property": "is_bot", + "value": "true" + }, + { + "operator": "EQUAL", + "property": "tier", + "value": "free" } ] }