use growthbook_rust::client::{GrowthBookClientBuilder, GrowthBookClientTrait};
use growthbook_rust::model_public::GrowthBookAttribute;
use serde_json::json;
#[tokio::test]
async fn empty_object_condition_matches_only_empty_object() {
let features_json = json!({
"eq-empty-object": {
"defaultValue": false,
"rules": [{ "condition": { "x": {} }, "force": true }]
}
});
let client = GrowthBookClientBuilder::new().features_json(features_json).unwrap().build().await.expect("Failed to build client");
let attrs = |value: serde_json::Value| GrowthBookAttribute::from(json!({ "x": value })).unwrap();
assert!(client.is_on("eq-empty-object", Some(attrs(json!({})))), "condition {{x: {{}}}} must match user x = {{}}");
assert!(
!client.is_on("eq-empty-object", Some(attrs(json!({ "a": 1 })))),
"condition {{x: {{}}}} must not match a non-empty object"
);
assert!(!client.is_on("eq-empty-object", Some(attrs(json!(null)))), "condition {{x: {{}}}} must not match null");
let missing = GrowthBookAttribute::from(json!({ "y": 1 })).unwrap();
assert!(!client.is_on("eq-empty-object", Some(missing)), "condition {{x: {{}}}} must not match a missing attribute");
}