Skip to content

Commit 3007efc

Browse files
msohailhussainmikeproeng37
authored andcommitted
fix: Empty bucketing id should be acceptable. (#367)
1 parent c69f2b5 commit 3007efc

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

OptimizelySDKCore/OptimizelySDKCore/OPTLYDecisionService.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ - (NSString *)getBucketingId:(NSString *)userId
166166
// in place of the userID for the murmur hash key
167167

168168
if (attributes != nil) {
169-
NSString *validBucketingId = [attributes[OptimizelyBucketId] getValidString];
170-
if (validBucketingId != nil) {
171-
bucketingId = validBucketingId;
169+
BOOL isValidStringType = [attributes[OptimizelyBucketId] isValidStringType];
170+
if (isValidStringType) {
171+
bucketingId = [attributes[OptimizelyBucketId] getStringOrEmpty];
172172
[self.config.logger logMessage:[NSString stringWithFormat:OPTLYLoggerMessagesDecisionServiceSettingTheBucketingID,
173173
bucketingId]
174174
withLevel:OptimizelyLogLevelDebug];

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYDecisionServiceTest.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,18 @@ - (void)testGetVariationWithInvalidBucketingId {
466466
kExperimentWithAudienceVariationKey, variation.variationKey);
467467
}
468468

469+
- (void)testGetVariationWithEmptyBucketingId {
470+
OPTLYExperiment *experiment = [self.config getExperimentForKey:kExperimentNoAudienceKey];
471+
OPTLYVariation *variation = [self.decisionService getVariation:kUserId experiment:experiment attributes:nil];
472+
473+
XCTAssertNotNil(variation, @"Get variation");
474+
475+
NSDictionary *attributes = @{OptimizelyBucketId: @""};
476+
OPTLYVariation *variationWithEmptyBucketingId = [self.decisionService getVariation:kUserId experiment:experiment attributes:attributes];
477+
478+
XCTAssertNotEqual(variation.variationKey,variationWithEmptyBucketingId.variationKey);
479+
}
480+
469481
- (void)testGetVariationAcceptAllTypeAttributes {
470482

471483
OPTLYExperiment *experiment = [self.config getExperimentForKey:kExperimentNoAudienceKey];

0 commit comments

Comments
 (0)