|
1 | 1 | /****************************************************************************
|
2 |
| - * Copyright 2016-2019, Optimizely, Inc. and contributors * |
| 2 | + * Copyright 2016-2020, Optimizely, Inc. and contributors * |
3 | 3 | * *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); *
|
5 | 5 | * you may not use this file except in compliance with the License. *
|
@@ -255,28 +255,63 @@ - (void)testDecisionNotificationForBasicGetVariation {
|
255 | 255 | XCTAssertNotNil(experiment);
|
256 | 256 | OPTLYVariation *variation;
|
257 | 257 |
|
258 |
| - // test just experiment key |
| 258 | + __block NSString *decisionNotificationExperimentKey = nil; |
| 259 | + __block NSString *decisionNotificationVariationKey = nil; |
| 260 | + |
| 261 | + [self.optimizely.notificationCenter addDecisionNotificationListener:^(NSString * _Nonnull type, NSString * _Nonnull userId, NSDictionary<NSString *,id> * _Nullable attributes, NSDictionary<NSString *,id> * _Nonnull decisionInfo) { |
| 262 | + decisionNotificationExperimentKey = decisionInfo[ExperimentDecisionInfo.ExperimentKey]; |
| 263 | + decisionNotificationVariationKey = decisionInfo[ExperimentDecisionInfo.VariationKey]; |
| 264 | + }]; |
| 265 | + |
259 | 266 | variation = [self.optimizely variation:experimentKey userId:kUserId];
|
260 | 267 | XCTAssertNotNil(variation);
|
261 | 268 | XCTAssertTrue([variation.variationKey isEqualToString:@"control"]);
|
262 | 269 | XCTAssertTrue([variation.variationId isEqualToString:@"6384330451"]);
|
| 270 | + XCTAssertEqualObjects(decisionNotificationExperimentKey, experimentKey); |
| 271 | + XCTAssertEqualObjects(decisionNotificationVariationKey, variation.variationKey); |
| 272 | +} |
| 273 | + |
| 274 | +- (void)testDecisionNotificationForBadExperimentKey { |
| 275 | + __block NSString *decisionNotificationExperimentKey = nil; |
| 276 | + __block NSString *decisionNotificationVariationKey = nil; |
| 277 | + NSString *experimentKey = @"badKey"; |
| 278 | + OPTLYExperiment *experiment = [self.optimizely.config getExperimentForKey:experimentKey]; |
263 | 279 |
|
264 |
| - // test with bad experiment key |
| 280 | + XCTAssertNil(experiment); |
| 281 | + OPTLYVariation *variation; |
265 | 282 |
|
| 283 | + [self.optimizely.notificationCenter addDecisionNotificationListener:^(NSString * _Nonnull type, NSString * _Nonnull userId, NSDictionary<NSString *,id> * _Nullable attributes, NSDictionary<NSString *,id> * _Nonnull decisionInfo) { |
| 284 | + decisionNotificationExperimentKey = decisionInfo[ExperimentDecisionInfo.ExperimentKey]; |
| 285 | + decisionNotificationVariationKey = decisionInfo[ExperimentDecisionInfo.VariationKey]; |
| 286 | + }]; |
| 287 | + |
| 288 | + variation = [self.optimizely variation:experimentKey userId:kUserId]; |
| 289 | + XCTAssertNil(variation); |
| 290 | + XCTAssertNil(decisionNotificationExperimentKey); |
| 291 | + XCTAssertNil(decisionNotificationVariationKey); |
| 292 | +} |
| 293 | + |
| 294 | +- (void)testDecisionNotificationForEmptyExperimentKey { |
266 | 295 | __block NSString *decisionNotificationExperimentKey = nil;
|
267 | 296 | __block NSString *decisionNotificationVariationKey = nil;
|
| 297 | + NSString *experimentKey = @""; |
| 298 | + OPTLYExperiment *experiment = [self.optimizely.config getExperimentForKey:experimentKey]; |
| 299 | + |
| 300 | + XCTAssertNil(experiment); |
| 301 | + OPTLYVariation *variation; |
268 | 302 |
|
269 | 303 | [self.optimizely.notificationCenter addDecisionNotificationListener:^(NSString * _Nonnull type, NSString * _Nonnull userId, NSDictionary<NSString *,id> * _Nullable attributes, NSDictionary<NSString *,id> * _Nonnull decisionInfo) {
|
270 | 304 | decisionNotificationExperimentKey = decisionInfo[ExperimentDecisionInfo.ExperimentKey];
|
271 | 305 | decisionNotificationVariationKey = decisionInfo[ExperimentDecisionInfo.VariationKey];
|
272 | 306 | }];
|
273 | 307 |
|
274 |
| - variation = [self.optimizely variation:@"bad" userId:kUserId]; |
| 308 | + variation = [self.optimizely variation:experimentKey userId:kUserId]; |
275 | 309 | XCTAssertNil(variation);
|
276 |
| - XCTAssertEqualObjects(decisionNotificationExperimentKey, @"bad"); |
277 |
| - XCTAssertEqualObjects(decisionNotificationVariationKey, [NSNull null]); |
| 310 | + XCTAssertNil(decisionNotificationExperimentKey); |
| 311 | + XCTAssertNil(decisionNotificationVariationKey); |
278 | 312 | }
|
279 | 313 |
|
| 314 | + |
280 | 315 | // Test whitelisting works with get variation
|
281 | 316 | - (void)testDecisionNotificationForVariationWhitelisting {
|
282 | 317 | NSData *datafile = [OPTLYTestHelper loadJSONDatafileIntoDataObject:kBucketerTestDatafileName];
|
|
0 commit comments