Skip to content

Commit e43f2a6

Browse files
fix(whitelisting): Invalid whitelisted variation stops bucketing (#308)
* refactor(EventBuilder): Moved decision service and bucketing from EventBuilder to Optimizely (#307) * Send decisions for all experiments using an event * nits * accept tags as event tags even if not convertible to revenue or value tag * Optimizely refactored * make projectConfig a private property of EventBuilder instead passing it to every method * impression event refactored * track and conversion refactored * test cases * fixed test cases * Optimizely coverage increased * EventBuilder coverage increased * LoggerMessages refactored * removed params validation from eventBuilder methods, 
updated license headers, 
removed unused loggerMessages * fix(whitelisting): Invalid whitelisted variation stops bucketing * fix(whitelisting): Invalid whitelisted variation stops bucketing
1 parent f308d68 commit e43f2a6

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYDecisionService.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ - (OPTLYVariation *)getVariation:(NSString *)userId
7676

7777
// ---- check if the experiment is whitelisted ----
7878
if ([self checkWhitelistingForUser:userId experiment:experiment]) {
79-
return [self getWhitelistedVariationForUser:userId
80-
experiment:experiment];
79+
OPTLYVariation *whitelistedVariation = [self getWhitelistedVariationForUser:userId experiment:experiment];
80+
if (whitelistedVariation) {
81+
return whitelistedVariation;
82+
}
8183
}
8284

8385
// ---- check if a valid variation is stored in the user profile ----

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYDecisionServiceTest.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,28 @@ - (void)testGetVariationWithWhitelistedVariation
216216
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);
217217
}
218218

219+
// whitelisted user having invalid whitelisted variation should return bucketed variation for getVariation
220+
- (void)testGetVariationWithInvalidWhitelistedVariation {
221+
222+
OPTLYExperiment *experimentWhitelisted = [self.config getExperimentForKey:@"testExperiment5"];
223+
OPTLYVariation *expectedVariation = experimentWhitelisted.variations[0];
224+
225+
id bucketerMock = OCMPartialMock(self.bucketer);
226+
OCMStub([bucketerMock bucketExperiment:experimentWhitelisted
227+
withBucketingId:kWhitelistedUserId_test_data_10_experiments]).andReturn(expectedVariation);
228+
229+
self.decisionService = [[OPTLYDecisionService alloc] initWithProjectConfig:self.config
230+
bucketer:bucketerMock];
231+
232+
OPTLYVariation *variation = [self.decisionService getVariation:kWhitelistedUserId_test_data_10_experiments
233+
experiment:experimentWhitelisted
234+
attributes:nil];
235+
XCTAssert([variation.variationKey isEqualToString:expectedVariation.variationKey], @"Get variation on an invalid whitelisted variation should return: %@, but instead returns: %@.", expectedVariation.variationKey, variation.variationKey);
236+
OCMVerify([bucketerMock bucketExperiment:experimentWhitelisted withBucketingId:kWhitelistedUserId_test_data_10_experiments]);
237+
[bucketerMock stopMocking];
238+
}
239+
240+
219241
// invalid audience should return nil for getVariation
220242
- (void)testGetVariationWithInvalidAudience
221243
{

OptimizelySDKCore/OptimizelySDKCoreTests/TestData/test_data_10_experiments.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@
106106
"variables": []
107107
}
108108
],
109-
"forcedVariations": {},
109+
"forcedVariations": {
110+
"forced_variation_user": "invalid_variation"
111+
},
110112
"id": "6364835526"
111113
},
112114
{

0 commit comments

Comments
 (0)