Skip to content

Commit

Permalink
fix: empty user Id return false from IsEnabled #215 (#216)
Browse files Browse the repository at this point in the history
Co-authored-by: Abdelkrim Bourennane <abdelkrim.bourennane@consulting-for.edenred.com>
  • Loading branch information
karimkod and Abdelkrim Bourennane authored Apr 22, 2024
1 parent 62894e9 commit 72d9c5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Unleash/Strategies/FlexibleRolloutStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public bool IsEnabled(Dictionary<string, string> parameters, UnleashContext cont
groupId = "";
}

if (!string.IsNullOrEmpty(stickinessId))
if (!(stickinessId is null))
{
var normalizedUserId = StrategyUtils.GetNormalizedNumber(stickinessId, groupId, 0);
return percentage > 0 && normalizedUserId <= percentage;
Expand Down
22 changes: 22 additions & 0 deletions tests/Unleash.Tests/Strategy/FlexibleRolloutStrategyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,27 @@ public void Should_be_enabled_without_a_context() {
// Assert
enabled.Should().BeTrue();
}

[Test]
public void Should_be_enabled_for_empty_userid() {
// Arrange
var strategy = new FlexibleRolloutStrategy();
var parameters = new Dictionary<string, string>
{
{ "rollout", "100" },
{ "stickiness", "default" },
{ "groupId", "Feature.flexible.rollout.custom.stickiness_100" }
};
var context = new UnleashContext
{
UserId = string.Empty
};

// Act
var enabled = strategy.IsEnabled(parameters, context);

// Assert
enabled.Should().BeTrue();
}
}
}

0 comments on commit 72d9c5d

Please sign in to comment.