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 (open-feature#282)

## This PR

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

### Related Issues

Fixes [open-feature#281](open-feature#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 <[email protected]>
Co-authored-by: André Silva <[email protected]>
Signed-off-by: Artyom Tonoyan <[email protected]>
  • Loading branch information
2 people authored and arttonoyan committed Nov 17, 2024
1 parent c2548d3 commit 242d03e
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 242d03e

Please sign in to comment.