Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.
Closed
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
4 changes: 3 additions & 1 deletion src/main/java/com/launchdarkly/client/Variation.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ else if (attribute.equals("anonymous")) {
uValue = user.getAnonymous();
}
}
else { // Custom attribute

// Always check custom attributes in case interpreted keys were used here
if (uValue == null) { // Custom attribute
JsonElement custom = user.getCustom(attribute);

if (custom != null) {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/launchdarkly/client/FeatureRepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class FeatureRepTest {

private final Variation.TargetRule targetAnonymousOn = new Variation.TargetRule("anonymous", Collections.singletonList(new JsonPrimitive(true)));

private final Variation.TargetRule targetEmailOn = new Variation.TargetRule("email", Collections.singletonList(new JsonPrimitive("test@test.com")));

private final Variation<Boolean> trueVariation = new Variation.Builder<>(true, 80)
.target(targetUserOn)
.target(targetGroupOn)
Expand All @@ -43,6 +45,17 @@ public class FeatureRepTest {
.target(targetLikesDogsOff)
.build();

private final Variation<Boolean> emailOnlyVariation = new Variation.Builder<>(true, 0)
.target(targetEmailOn)
.build();

private final FeatureRep<Boolean> emailRuleFlag = new FeatureRep.Builder<Boolean>("Email rule flag", "email.rule.flag")
.on(true)
.salt("feefifofum")
.variation(emailOnlyVariation)
.build();


private final FeatureRep<Boolean> simpleFlag = new FeatureRep.Builder<Boolean>("Sample flag", "sample.flag")
.on(true)
.salt("feefifofum")
Expand Down Expand Up @@ -201,4 +214,15 @@ public void testFlagWithAnonymousOn() {
assertEquals(true, b);
}

@Test
public void testInterpretedAttributeEvaluatesInCustom() {
LDUser customEmailSetUser = new LDUser.Builder("randomOtherUser@test.com").custom("email", "test@test.com").build();
Boolean b = emailRuleFlag.evaluate(customEmailSetUser);
assertEquals(true, b);

LDUser interpretedEmailSetUser = new LDUser.Builder("randomOtherUser@test.com").email("test@test.com").build();
Boolean b2 = emailRuleFlag.evaluate(interpretedEmailSetUser);
assertEquals(true, b2);
}

}