From 2238915ab53df52e2da96633ef053fffd41185de Mon Sep 17 00:00:00 2001 From: Chris Hannon Date: Fri, 2 Feb 2024 17:29:04 -0700 Subject: [PATCH] Added tests --- .../CustomTests/RegressionTests.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/GrowthBook.Tests/CustomTests/RegressionTests.cs b/GrowthBook.Tests/CustomTests/RegressionTests.cs index d6b6580..79f62e9 100644 --- a/GrowthBook.Tests/CustomTests/RegressionTests.cs +++ b/GrowthBook.Tests/CustomTests/RegressionTests.cs @@ -11,6 +11,39 @@ namespace GrowthBook.Tests.CustomTests; public class RegressionTests : UnitTest { + [Fact] + public void GetFeatureValueShouldOnlyReturnFallbackValueWhenTheFeatureResultValueIsNull() + { + const string FeatureName = "test-false-default-value"; + + var feature = new Feature { DefaultValue = false }; + + var staticFeatures = new Dictionary + { + [FeatureName] = feature + }; + + var context = new Context + { + Features = staticFeatures + }; + + var growthBook = new GrowthBook(context); + + growthBook.IsOn(FeatureName).Should().BeFalse("because the value of the feature is considered falsy"); + growthBook.GetFeatureValue(FeatureName, true).Should().BeFalse("because the default value can be served from the feature"); + + growthBook.Features[FeatureName] = new Feature { DefaultValue = null }; + + growthBook.IsOn(FeatureName).Should().BeFalse("because the value of the feature is considered falsy"); + growthBook.GetFeatureValue(FeatureName, false).Should().BeFalse("because the fallback value should be returned when the result value is null"); + + growthBook.Features[FeatureName] = new Feature { DefaultValue = true }; + + growthBook.IsOn(FeatureName).Should().BeTrue("because the value of the feature is considered truthy"); + growthBook.GetFeatureValue(FeatureName, false).Should().BeTrue("because the default value can be served from the feature"); + } + [Fact] public void EvalIsInConditionShouldNotDifferWhenAttributeIsEmptyInsteadOfNull() {