Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not send targeting key as separate trait in flagsmith #120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ private Task<IFlags> GetFlags(EvaluationContext ctx)

return string.IsNullOrEmpty(key)
? _flagsmithClient.GetEnvironmentFlags()
: _flagsmithClient.GetIdentityFlags(key, ctx.AsDictionary().Select(x => new Trait(x.Key, x.Value.AsObject) as ITrait).ToList());
: _flagsmithClient.GetIdentityFlags(key, ctx
.AsDictionary()
.Where(x => x.Key != Configuration.TargetingKey)
.Select(x => new Trait(x.Key, x.Value.AsObject) as ITrait)
.ToList());
}

private async Task<ResolutionDetails<T>> ResolveValue<T>(string flagKey, T defaultValue, TryParseDelegate<T> tryParse, EvaluationContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
/// </summary>
public class FlagsmithProviderConfiguration : IFlagsmithProviderConfiguration
{
/// <summary>
/// Default value for targeting key
/// </summary>
public const string DefaultTargetingKey = "targetingKey";

/// <summary>
/// Key that will be used as identity for Flagsmith requests. Default: "targetingKey"
/// </summary>
public string TargetingKey { get; set; } = "targetingKey";
public string TargetingKey { get; set; } = DefaultTargetingKey;

/// <inheritdoc/>
public bool UsingBooleanConfigValue { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task GetValue_ForEnabledFeatureWithEvaluationContext_ReturnCorrectV
var date = DateTime.Now;
flags.GetFeatureValue("example-feature").Returns("true");
flags.IsFeatureEnabled("example-feature").Returns(true);
flagsmithClient.GetIdentityFlags("233", Arg.Is<List<ITrait>>(x => x.Count == 7 && x.Any(c => c.GetTraitKey() == "key1"))).Returns(flags);
flagsmithClient.GetIdentityFlags("233", Arg.Is<List<ITrait>>(x => x.Count == 6 && x.Any(c => c.GetTraitKey() == "key1"))).Returns(flags);

var providerConfig = GetDefaultFlagsmithProviderConfigurationConfiguration();
var flagsmithProvider = new FlagsmithProvider(providerConfig, flagsmithClient);
Expand All @@ -77,7 +77,7 @@ public async Task GetValue_ForEnabledFeatureWithEvaluationContext_ReturnCorrectV
.Set("key4", date)
.Set("key5", Structure.Empty)
.Set("key6", 1.0)
.Set("targetingKey", "233");
.Set(FlagsmithProviderConfiguration.DefaultTargetingKey, "233");
// Act
var result = await flagsmithProvider.ResolveBooleanValue("example-feature", false, contextBuilder.Build());

Expand Down
Loading