Skip to content

Commit

Permalink
Change test project setting; Cleaned FLiptConverter code
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei de la Cruz <andrei.delacruz@gmail.com>
  • Loading branch information
jeandreidc committed Oct 3, 2024
1 parent e11bdaa commit cd1b5a9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
using Flipt.Rest;
Expand Down Expand Up @@ -109,20 +108,6 @@ public async Task<ResolutionDetails<bool>> EvaluateBooleanAsync(string flagKey,
}
}

private static ResolutionDetails<T> ResolutionDetailFromHttpException<T>(HttpRequestException e, string flagKey,
T defaultValue)
{
var error = e.StatusCode switch
{
HttpStatusCode.NotFound => ErrorType.FlagNotFound,
HttpStatusCode.BadRequest => ErrorType.TypeMismatch,
HttpStatusCode.Forbidden => ErrorType.ProviderNotReady,
HttpStatusCode.InternalServerError => ErrorType.ProviderNotReady,
_ => ErrorType.General
};
return new ResolutionDetails<T>(flagKey, defaultValue, error, errorMessage: e.Message);
}

private static ResolutionDetails<T> ResolutionDetailFromFliptException<T>(FliptException e, string flagKey,
T defaultValue)
{
Expand All @@ -146,19 +131,19 @@ public interface IFliptToOpenFeatureConverter
/// <summary>
/// Used for evaluating non-boolean flags. Flipt handles datatypes which is not boolean as variants
/// </summary>
/// <param name="flagKey"></param>
/// <param name="defaultValue"></param>
/// <param name="context"></param>
/// <typeparam name="T"></typeparam>
/// <param name="flagKey">Key of the flag to evaluate</param>
/// <param name="defaultValue">Fallback value in case of error, or flag not present or disabled, or no match</param>
/// <param name="context">Additional data to use to filter and segment requests</param>
/// <typeparam name="T">Type to evaluate. For boolean use EvaluateBoolean</typeparam>
/// <returns>OpenFeature ResolutionDetails object</returns>
Task<ResolutionDetails<T>> EvaluateAsync<T>(string flagKey, T defaultValue, EvaluationContext context = null);

/// <summary>
/// Used for evaluating boolean flags
/// </summary>
/// <param name="flagKey"></param>
/// <param name="defaultValue"></param>
/// <param name="context"></param>
/// <param name="flagKey">Key of the flag to evaluate</param>
/// <param name="defaultValue">Fallback value in case of error, or flag not present, or no match</param>
/// <param name="context">Additional data to use to filter and segment requests</param>
/// <returns>OpenFeature ResolutionDetails object</returns>
Task<ResolutionDetails<bool>> EvaluateBooleanAsync(string flagKey, bool defaultValue,
EvaluationContext context = null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions;
using OpenFeature.Contrib.Providers.Flipt.Converters;
using OpenFeature.Model;
using Xunit;

namespace OpenFeature.Contrib.Providers.Flipt.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using OpenFeature.Constant;
using OpenFeature.Contrib.Providers.Flipt.ClientWrapper;
using OpenFeature.Model;
using Xunit;

namespace OpenFeature.Contrib.Providers.Flipt.Test;

Expand Down Expand Up @@ -63,4 +64,6 @@ public async Task
valueResolution.Value.Should().BeEquivalentTo(new Value());
valueResolution.ErrorType.Should().Be(ErrorType.TypeMismatch);
}

// Todo Andrei: Add tests to make sure that the wrapper was called
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using OpenFeature.Constant;
using OpenFeature.Contrib.Providers.Flipt.ClientWrapper;
using OpenFeature.Model;
using Xunit;

namespace OpenFeature.Contrib.Providers.Flipt.Test;

Expand Down Expand Up @@ -53,7 +54,6 @@ public async Task EvaluateBooleanAsync_GivenExistingFlag_ShouldReturnFlagValue(s
resolution.FlagKey.Should().Be(flagKey);
resolution.Value.Should().Be(valueFromSrc);
resolution.Reason.Should().Be(Reason.TargetingMatch);

}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Update="FluentAssertions" Version="6.12.1"/>
<PackageReference Remove="NSubstitute"/>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OpenFeature.Contrib.Providers.Flipt\OpenFeature.Contrib.Providers.Flipt.csproj"/>
</ItemGroup>

Expand Down

0 comments on commit cd1b5a9

Please sign in to comment.