-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from growthbook/fixing-eval-isin-failure
Fixed differing null/empty evaluation during non-array IsIn condition
- Loading branch information
Showing
5 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace GrowthBook.Tests.CustomTests; | ||
|
||
public class RegressionTests : UnitTest | ||
{ | ||
[Fact] | ||
public void EvalIsInConditionShouldNotDifferWhenAttributeIsEmptyInsteadOfNull() | ||
{ | ||
var featureJson = """ | ||
{ | ||
"defaultValue": false, | ||
"rules": [ | ||
{ | ||
"condition": { | ||
"userId": { | ||
"$in": [ | ||
"ac1", | ||
"ac2", | ||
"ac3" | ||
] | ||
} | ||
}, | ||
"force": true | ||
} | ||
] | ||
} | ||
"""; | ||
|
||
var feature = JsonConvert.DeserializeObject<Feature>(featureJson); | ||
|
||
var staticFeatures = new Dictionary<string, Feature> | ||
{ | ||
["test-in-op"] = feature | ||
}; | ||
|
||
var context = new Context | ||
{ | ||
Features = staticFeatures | ||
}; | ||
|
||
var growthBook = new GrowthBook(context); | ||
|
||
// The initial evaluation will use a null userId value. | ||
|
||
var flag = growthBook.IsOn("test-in-op"); | ||
flag.Should().BeFalse("because the userId property in the attributes JSON is null"); | ||
|
||
// Try again with a userId that is an empty string instead. | ||
|
||
context.Attributes.Add("userId", string.Empty); | ||
|
||
var errorFlag = growthBook.IsOn("test-in-op"); | ||
errorFlag.Should().BeFalse("because an empty string is considered falsy and should not differ from the null case"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters