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(whitelisting): Invalid whitelisted variation stops bucketing #308

Merged
merged 4 commits into from
Sep 24, 2018
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
6 changes: 4 additions & 2 deletions OptimizelySDKCore/OptimizelySDKCore/OPTLYDecisionService.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ - (OPTLYVariation *)getVariation:(NSString *)userId

// ---- check if the experiment is whitelisted ----
if ([self checkWhitelistingForUser:userId experiment:experiment]) {
return [self getWhitelistedVariationForUser:userId
experiment:experiment];
OPTLYVariation *whitelistedVariation = [self getWhitelistedVariationForUser:userId experiment:experiment];
if (whitelistedVariation) {
return whitelistedVariation;
}
}

// ---- check if a valid variation is stored in the user profile ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ - (void)testGetVariationWithWhitelistedVariation
XCTAssert([variation.variationKey isEqualToString:kWhitelistedVariation_test_data_10_experiments], @"Get variation on a whitelisted variation should return: %@, but instead returns: %@.", kWhitelistedVariation_test_data_10_experiments, variation.variationKey);
}

// whitelisted user having invalid whitelisted variation should return bucketed variation for getVariation
- (void)testGetVariationWithInvalidWhitelistedVariation {

OPTLYExperiment *experimentWhitelisted = [self.config getExperimentForKey:@"testExperiment5"];
OPTLYVariation *expectedVariation = experimentWhitelisted.variations[0];

id bucketerMock = OCMPartialMock(self.bucketer);
OCMStub([bucketerMock bucketExperiment:experimentWhitelisted
withBucketingId:kWhitelistedUserId_test_data_10_experiments]).andReturn(expectedVariation);

self.decisionService = [[OPTLYDecisionService alloc] initWithProjectConfig:self.config
bucketer:bucketerMock];

OPTLYVariation *variation = [self.decisionService getVariation:kWhitelistedUserId_test_data_10_experiments
experiment:experimentWhitelisted
attributes:nil];
XCTAssert([variation.variationKey isEqualToString:expectedVariation.variationKey], @"Get variation on an invalid whitelisted variation should return: %@, but instead returns: %@.", expectedVariation.variationKey, variation.variationKey);
OCMVerify([bucketerMock bucketExperiment:experimentWhitelisted withBucketingId:kWhitelistedUserId_test_data_10_experiments]);
[bucketerMock stopMocking];
}


// invalid audience should return nil for getVariation
- (void)testGetVariationWithInvalidAudience
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@
"variables": []
}
],
"forcedVariations": {},
"forcedVariations": {
"forced_variation_user": "invalid_variation"
},
"id": "6364835526"
},
{
Expand Down