Skip to content

Commit bf4198e

Browse files
Kroach/oasis 2768 upgradev2 (#251)
* Forcing old datafile to include anonymizeIP required by V4 format. * Add testOlderV2Datafile unit test
1 parent 010893e commit bf4198e

File tree

7 files changed

+74
-4
lines changed

7 files changed

+74
-4
lines changed

OptimizelySDKCore/OptimizelySDKCore.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
3ECB82061FD92736006505E6 /* OPTLYRollout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3ECB82031FD92736006505E6 /* OPTLYRollout.m */; };
199199
3ECB82071FD92736006505E6 /* OPTLYRollout.m in Sources */ = {isa = PBXBuildFile; fileRef = 3ECB82031FD92736006505E6 /* OPTLYRollout.m */; };
200200
3EE687AA1F312FA30084B375 /* BucketerTestsDatafile2.json in Resources */ = {isa = PBXBuildFile; fileRef = 3E92800D1F26AD4700214C58 /* BucketerTestsDatafile2.json */; };
201+
3EF9D99020AE425000A9B002 /* V2TestDatafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 3EF9D98F20AE424F00A9B002 /* V2TestDatafile.json */; };
202+
3EF9D99120AE425000A9B002 /* V2TestDatafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 3EF9D98F20AE424F00A9B002 /* V2TestDatafile.json */; };
201203
4FFB468BAFC670CF55514638 /* Pods_OptimizelySDKCoreTVOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9A3A368275572C29A76DC80A /* Pods_OptimizelySDKCoreTVOSTests.framework */; };
202204
5E4C07F31DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 5E4C07F21DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json */; };
203205
5E4C07F41DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json in Resources */ = {isa = PBXBuildFile; fileRef = 5E4C07F21DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json */; };
@@ -580,6 +582,7 @@
580582
3ECB81FD1FD926FE006505E6 /* OPTLYVariableUsage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYVariableUsage.m; sourceTree = "<group>"; };
581583
3ECB82021FD92736006505E6 /* OPTLYRollout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OPTLYRollout.h; sourceTree = "<group>"; };
582584
3ECB82031FD92736006505E6 /* OPTLYRollout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYRollout.m; sourceTree = "<group>"; };
585+
3EF9D98F20AE424F00A9B002 /* V2TestDatafile.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = V2TestDatafile.json; sourceTree = "<group>"; };
583586
51B050141BF2E9277B39EEE8 /* Pods-OptimizelySDKCoreiOSTests.rc.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OptimizelySDKCoreiOSTests.rc.xcconfig"; path = "../Pods/Target Support Files/Pods-OptimizelySDKCoreiOSTests/Pods-OptimizelySDKCoreiOSTests.rc.xcconfig"; sourceTree = "<group>"; };
584587
5E4C07F21DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = InvalidDatafileVersionDatafile.json; sourceTree = "<group>"; };
585588
5E4C07FA1DFF66B00042B1F8 /* OPTLYNetworkServiceTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OPTLYNetworkServiceTest.m; sourceTree = "<group>"; };
@@ -1129,6 +1132,7 @@
11291132
EA2FAB971DC6FDFA00B1D81B /* test_data_10_experiments.json */,
11301133
EA2FAB981DC6FDFA00B1D81B /* test_data_25_experiments.json */,
11311134
EA2FAB991DC6FDFA00B1D81B /* test_data_50_experiments.json */,
1135+
3EF9D98F20AE424F00A9B002 /* V2TestDatafile.json */,
11321136
);
11331137
path = TestData;
11341138
sourceTree = "<group>";
@@ -1611,6 +1615,7 @@
16111615
5E4C07F31DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json in Resources */,
16121616
3E99CF7F1FE02C2D00B16B97 /* optimizely_6372300739_v4.json in Resources */,
16131617
EA2FABC91DC6FDFA00B1D81B /* BucketerTestsDatafile.json in Resources */,
1618+
3EF9D99020AE425000A9B002 /* V2TestDatafile.json in Resources */,
16141619
EA2FABD21DC6FDFA00B1D81B /* test_data_25_experiments.json in Resources */,
16151620
3EE687AA1F312FA30084B375 /* BucketerTestsDatafile2.json in Resources */,
16161621
);
@@ -1634,6 +1639,7 @@
16341639
EA2FABD01DC6FDFA00B1D81B /* test_data_10_experiments.json in Resources */,
16351640
3E99CF801FE02C2E00B16B97 /* optimizely_6372300739_v4.json in Resources */,
16361641
5E4C07F41DFF645C0042B1F8 /* InvalidDatafileVersionDatafile.json in Resources */,
1642+
3EF9D99120AE425000A9B002 /* V2TestDatafile.json in Resources */,
16371643
EA2FABCA1DC6FDFA00B1D81B /* BucketerTestsDatafile.json in Resources */,
16381644
EA2FABD31DC6FDFA00B1D81B /* test_data_25_experiments.json in Resources */,
16391645
);

OptimizelySDKCore/OptimizelySDKCore/OPTLYEventBuilder.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ - (NSDictionary *)createCommonParams:(OPTLYProjectConfig *)config userId:(NSStri
262262
params[OPTLYEventParameterKeysClientEngine] = [OPTLYEventBuilderDefault stringOrEmpty:[config clientEngine]];
263263
params[OPTLYEventParameterKeysClientVersion] = [OPTLYEventBuilderDefault stringOrEmpty:[config clientVersion]];
264264
params[OPTLYEventParameterKeysRevision] = [OPTLYEventBuilderDefault stringOrEmpty:config.revision];
265-
params[OPTLYEventParameterKeysAnonymizeIP] = config.anonymizeIP ? @YES : @NO;
265+
params[OPTLYEventParameterKeysAnonymizeIP] = @(config.anonymizeIP.boolValue);
266266

267267
return [params copy];
268268
}

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ NS_ASSUME_NONNULL_END
4545
/// Datafile Revision number
4646
@property (nonatomic, strong, nonnull) NSString *revision;
4747
/// Flag for IP anonymization
48-
@property (nonatomic, assign) BOOL anonymizeIP;
48+
@property (nonatomic) NSNumber<Optional> *anonymizeIP;
4949
/// List of Optimizely Experiment objects
5050
@property (nonatomic, strong, nonnull) NSArray<OPTLYExperiment> *experiments;
5151
/// List of Optimizely Event Type objects

OptimizelySDKCore/OptimizelySDKCore/OPTLYProjectConfig.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ - (instancetype)initWithBuilder:(OPTLYProjectConfigBuilder *)builder {
113113
[builder.logger logMessage:logMessage withLevel:OptimizelyLogLevelWarning];
114114
}
115115

116+
if (projectConfig.anonymizeIP == nil) {
117+
NSString *logMessage = @"Forcing old datafile to include anonymizeIP required by V4 format.";
118+
[builder.logger logMessage:logMessage withLevel:OptimizelyLogLevelWarning];
119+
projectConfig.anonymizeIP = @1;
120+
}
121+
116122
if (datafileError)
117123
{
118124
NSError *error = [NSError errorWithDomain:OPTLYErrorHandlerMessagesDomain

OptimizelySDKCore/OptimizelySDKCoreTests/OPTLYProjectConfigTest.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ - (void)testInitWithAnonymizeIPFalse {
153153
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kDatafileNameAnonymizeIPFalse];
154154
OPTLYProjectConfig *projectConfig = [[OPTLYProjectConfig alloc] initWithDatafile:datafile];
155155

156-
XCTAssertFalse(projectConfig.anonymizeIP, @"IP anonymization should be set to false.");
156+
XCTAssertFalse(projectConfig.anonymizeIP.boolValue, @"IP anonymization should be set to false.");
157157
}
158158

159159
#pragma mark - Test getExperimentForKey:
@@ -467,7 +467,7 @@ - (void)checkProjectConfigProperties:(OPTLYProjectConfig *)projectConfig
467467
NSAssert([projectConfig.revision isEqualToString:kRevision], @"Invalid revision number.");
468468

469469
// validate IP anonymization value
470-
XCTAssertTrue(projectConfig.anonymizeIP, @"IP anonymization should be set to true.");
470+
XCTAssertTrue(projectConfig.anonymizeIP.boolValue, @"IP anonymization should be set to true.");
471471

472472
// check experiments
473473
NSAssert([projectConfig.experiments count] == kNumberOfExperimentObjects, @"deserializeJSONArray failed to deserialize the right number of experiments objects in project config.");

OptimizelySDKCore/OptimizelySDKCoreTests/OptimizelyTest.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
static NSString *const kEventNameWithMultipleExperiments = @"testEventWithMultipleExperiments";
3838

3939
// datafiles
40+
static NSString *const kV2TestDatafileName = @"V2TestDatafile";
4041
static NSString *const kBucketerTestDatafileName = @"BucketerTestsDatafile";
4142

4243
// user IDs
@@ -157,6 +158,15 @@ - (void)testVariationWithAudience {
157158
XCTAssertNotNil(variation);
158159
}
159160

161+
// Test initializing with older V2 datafile
162+
- (void)testOlderV2Datafile {
163+
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kV2TestDatafileName];
164+
Optimizely *optimizely = [Optimizely init:^(OPTLYBuilder * _Nullable builder) {
165+
builder.datafile = datafile;
166+
}];
167+
XCTAssertNotNil(optimizely);
168+
}
169+
160170
// Test whitelisting works with get variation
161171
- (void)testVariationWhitelisting {
162172
NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kBucketerTestDatafileName];
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"accountId": "12345",
3+
"projectId": "23456",
4+
"revision": "6",
5+
"version": "2",
6+
"experiments": [
7+
{
8+
"key": "my_experiment",
9+
"id": "45678",
10+
"layerId": "34567",
11+
"status": "Running",
12+
"variations": [
13+
{
14+
"id": "56789",
15+
"key": "control"
16+
},
17+
{
18+
"id": "67890",
19+
"key": "treatment"
20+
}
21+
],
22+
"trafficAllocation": [
23+
{
24+
"entityId": "56789",
25+
"endOfRange": 5000
26+
},
27+
{
28+
"entityId": "67890",
29+
"endOfRange": 10000
30+
}
31+
],
32+
"audienceIds": [],
33+
"forcedVariations": {}
34+
}
35+
],
36+
"events": [
37+
{
38+
"experimentIds": [
39+
"34567"
40+
],
41+
"id": "56789",
42+
"key": "my_conversion"
43+
}
44+
],
45+
"audiences": [],
46+
"attributes": [],
47+
"groups": []
48+
}

0 commit comments

Comments
 (0)