-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix feature variable when feature disabled (#3707) (#123)
- Loading branch information
1 parent
a5eb95b
commit 1f38e54
Showing
3 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
OptimizelySDK/OptimizelyTests/OptimizelyTests-APIs/OptimizelyManagerTests_Variables.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// OptimizelyManagerTests_Variables.swift | ||
// OptimizelyTests-APIs-iOS | ||
// | ||
// Created by Jae Kim on 3/11/19. | ||
// Copyright © 2019 Optimizely. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
|
||
class OptimizelyManagerTests_Variables: XCTestCase { | ||
|
||
let kVariableId = "1111" | ||
let kVariableDefaultValue = 20 | ||
let kVariableValueA = 30 | ||
|
||
let kUserId = "12345" | ||
let kExperimentId = "11111" | ||
|
||
var sampleExperimentData: [String: Any] { return | ||
[ | ||
"status": "Running", | ||
"id": kExperimentId, | ||
"key": "43432134", | ||
"layerId": "10420273888", | ||
"trafficAllocation": [ | ||
[ | ||
"entityId": "10389729780", | ||
"endOfRange": 10000 | ||
] | ||
], | ||
"audienceIds": [], | ||
"variations": [ | ||
[ | ||
"variables": [ | ||
["id": kVariableId, "value": String(kVariableValueA)] | ||
], | ||
"id": "10389729780", | ||
"key": "16456523121" | ||
] | ||
], | ||
"forcedVariations":[:] | ||
] | ||
} | ||
var sampleFeatureFlagData: [String: Any] { return | ||
[ | ||
"id": "553339214", | ||
"key": "house", | ||
"experimentIds":[kExperimentId], | ||
"rolloutId": "", | ||
"variables": [ | ||
[ | ||
"defaultValue": String(kVariableDefaultValue), | ||
"type": "integer", | ||
"id": kVariableId, | ||
"key": "window" | ||
] | ||
] | ||
] | ||
} | ||
|
||
var optimizely: OptimizelyManager! | ||
var experiment: Experiment! | ||
var featureFlag: FeatureFlag! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
optimizely = OTUtils.createOptimizely(datafileName: "empty_datafile", | ||
clearUserProfileService: true)! | ||
|
||
let featureFlag: FeatureFlag = try! OTUtils.model(from: sampleFeatureFlagData) | ||
optimizely.config!.project.featureFlags = [featureFlag] | ||
} | ||
|
||
|
||
func testFeatureVariableWhenFeatureEnabled() { | ||
var experiment: Experiment = try! OTUtils.model(from: sampleExperimentData) | ||
experiment.variations[0].featureEnabled = true | ||
optimizely.config!.project.experiments = [experiment] | ||
|
||
let value = try! optimizely.getFeatureVariableInteger(featureKey: "house", variableKey: "window", userId: kUserId) | ||
|
||
XCTAssertEqual(value, kVariableValueA) | ||
} | ||
|
||
func testFeatureVariableWhenFeatureDisabled() { | ||
var experiment: Experiment = try! OTUtils.model(from: sampleExperimentData) | ||
experiment.variations[0].featureEnabled = false | ||
optimizely.config!.project.experiments = [experiment] | ||
|
||
let value = try! optimizely.getFeatureVariableInteger(featureKey: "house", variableKey: "window", userId: kUserId) | ||
|
||
XCTAssertEqual(value, kVariableDefaultValue) | ||
} | ||
|
||
func testFeatureVariableWhenFeatureEnabledNil() { | ||
var experiment: Experiment = try! OTUtils.model(from: sampleExperimentData) | ||
experiment.variations[0].featureEnabled = nil | ||
optimizely.config!.project.experiments = [experiment] | ||
|
||
let value = try! optimizely.getFeatureVariableInteger(featureKey: "house", variableKey: "window", userId: kUserId) | ||
|
||
XCTAssertEqual(value, kVariableDefaultValue) | ||
} | ||
|
||
} |