Skip to content

Commit

Permalink
Added FliptToOpenFeatureConverter tests for non-existent flags for Va…
Browse files Browse the repository at this point in the history
…riant types

Signed-off-by: Andrei de la Cruz <[email protected]>
  • Loading branch information
jeandreidc committed Oct 2, 2024
1 parent d4b3e42 commit 10b1d86
Showing 1 changed file with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OpenFeature.Contrib.Providers.Flipt.Test;

public class FlipToOpenFeatureConverterTest
public class FliptToOpenFeatureConverterTest
{
// EvaluateBooleanAsync Tests
[Theory]
Expand Down Expand Up @@ -157,6 +157,48 @@ public async Task EvaluateAsync_GivenExistingVariantFlagAndWithAnObject_ShouldRe
resolution.Variant.Should().Be(variantKey);
resolution.Value.Should().BeEquivalentTo(expectedValue);
}


[Fact]
public async Task
EvaluateVariantAsync_GivenNonExistentFlagWithNonNestedFallback_ShouldReturnDefaultValueWithFlagNotFoundError()
{
var fallbackValue = new Value(new Structure(new Dictionary<string, Value>
{
{ "name", new Value("Mr. Robinson") }, { "age", new Value(12) }
}));
var mockFliptClientWrapper = new Mock<IFliptClientWrapper>();
mockFliptClientWrapper.Setup(fcw => fcw.EvaluateVariantAsync(It.IsAny<EvaluationRequest>()))
.ThrowsAsync(new HttpRequestException("", null, HttpStatusCode.NotFound));

var fliptToOpenFeature = new FliptToOpenFeatureConverter(mockFliptClientWrapper.Object);
var resolution = await fliptToOpenFeature.EvaluateAsync("non-existent-flag", fallbackValue);

resolution.FlagKey.Should().Be("non-existent-flag");
resolution.Variant.Should().BeNull();
resolution.Value.Should().BeEquivalentTo(fallbackValue);
resolution.ErrorType.Should().Be(ErrorType.FlagNotFound);
}


[Fact]
public async Task
EvaluateVariantAsync_GivenNonExistentFlagWithNestedFallback_ShouldReturnDefaultValueWithFlagNotFoundError()
{
var fallbackValue = new Value("");
var mockFliptClientWrapper = new Mock<IFliptClientWrapper>();
mockFliptClientWrapper.Setup(fcw => fcw.EvaluateVariantAsync(It.IsAny<EvaluationRequest>()))
.ThrowsAsync(new HttpRequestException("", null, HttpStatusCode.NotFound));

var fliptToOpenFeature = new FliptToOpenFeatureConverter(mockFliptClientWrapper.Object);
var resolution = await fliptToOpenFeature.EvaluateAsync("non-existent-flag", fallbackValue);

resolution.FlagKey.Should().Be("non-existent-flag");
resolution.Variant.Should().BeNull();
resolution.Value.Should().BeEquivalentTo(fallbackValue);
resolution.ErrorType.Should().Be(ErrorType.FlagNotFound);
}

/* Todo Andrei: Mga kulang pa na unit test
- Successful na flag
- Boolean
Expand Down

0 comments on commit 10b1d86

Please sign in to comment.