Skip to content

Commit

Permalink
fix: Should map metadata when converting from ResolutionDetails to Fl…
Browse files Browse the repository at this point in the history
…agEvaluationDetails (#282)

## This PR

When converting the ResolutionDetails to FlagEvalutionDetails we aren't
passing the ImmutableMetadata to the new object.

### Related Issues

Fixes [#281](#281)

### Notes
This PR is done on a common merge base so we can merge it into v1 as
well

### Follow-up Tasks
N/A

### How to test
Unit test added to covert the missing test case

---------

Signed-off-by: Benjamin Evenson <2031163+benjiro@users.noreply.github.com>
Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
  • Loading branch information
benjiro and askpt authored Jul 26, 2024
1 parent 2dbe1f4 commit 2f8bd21
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OpenFeature/Extension/ResolutionDetailsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal static class ResolutionDetailsExtensions
public static FlagEvaluationDetails<T> ToFlagEvaluationDetails<T>(this ResolutionDetails<T> details)
{
return new FlagEvaluationDetails<T>(details.FlagKey, details.Value, details.ErrorType, details.Reason,
details.Variant, details.ErrorMessage);
details.Variant, details.ErrorMessage, details.FlagMetadata);
}
}
}
24 changes: 24 additions & 0 deletions test/OpenFeature.Tests/OpenFeatureClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
Expand All @@ -11,6 +12,7 @@
using NSubstitute.ExceptionExtensions;
using OpenFeature.Constant;
using OpenFeature.Error;
using OpenFeature.Extension;
using OpenFeature.Model;
using OpenFeature.Tests.Internal;
using Xunit;
Expand Down Expand Up @@ -480,5 +482,27 @@ public void Should_Get_And_Set_Context()
client.SetContext(new EvaluationContextBuilder().Set(KEY, VAL).Build());
Assert.Equal(VAL, client.GetContext().GetValue(KEY).AsInteger);
}


[Fact]
public void ToFlagEvaluationDetails_Should_Convert_All_Properties()
{
var fixture = new Fixture();
var flagName = fixture.Create<string>();
var boolValue = fixture.Create<bool>();
var errorType = fixture.Create<ErrorType>();
var reason = fixture.Create<string>();
var variant = fixture.Create<string>();
var errorMessage = fixture.Create<string>();
var flagData = fixture
.CreateMany<KeyValuePair<string, object>>(10)
.ToDictionary(x => x.Key, x => x.Value);
var flagMetadata = new ImmutableMetadata(flagData);

var expected = new ResolutionDetails<bool>(flagName, boolValue, errorType, reason, variant, errorMessage, flagMetadata);
var result = expected.ToFlagEvaluationDetails();

result.Should().BeEquivalentTo(expected);
}
}
}

0 comments on commit 2f8bd21

Please sign in to comment.