Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Sources/Data Model/Experiment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ struct Experiment: Codable, ExperimentCore {
// datafile spec defines this as [String: Any]. Supposed to be [ExperimentKey: VariationKey]
var forcedVariations: [String: String]
var cmab: Cmab?

var type: String?

enum CodingKeys: String, CodingKey {
case id, key, status, layerId, variations, trafficAllocation, audienceIds, audienceConditions, forcedVariations, cmab
case id, key, status, layerId, variations, trafficAllocation, audienceIds, audienceConditions, forcedVariations, cmab, type
}

// MARK: - OptimizelyConfig
Expand All @@ -59,7 +60,8 @@ extension Experiment: Equatable {
lhs.audienceIds == rhs.audienceIds &&
lhs.audienceConditions == rhs.audienceConditions &&
lhs.forcedVariations == rhs.forcedVariations &&
lhs.cmab == rhs.cmab
lhs.cmab == rhs.cmab &&
lhs.type == rhs.type
}
}

Expand Down
26 changes: 25 additions & 1 deletion Tests/OptimizelyTests-DataModel/ExperimentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,35 @@ extension ExperimentTests {
func testDecodeFailWithMissingForcedVariations() {
var data: [String: Any] = ExperimentTests.sampleData
data["forcedVariations"] = nil

let model: Experiment? = try? OTUtils.model(from: data)
XCTAssertNil(model)
}

func testDecodeSuccessWithUnknownType() {
var data: [String: Any] = ExperimentTests.sampleData
data["type"] = "new_unknown_type"

let model: Experiment = try! OTUtils.model(from: data)
XCTAssertEqual(model.type, "new_unknown_type")
XCTAssertEqual(model.id, "11111")
XCTAssertEqual(model.key, "background")
}

func testDecodeSuccessWithKnownType() {
var data: [String: Any] = ExperimentTests.sampleData
data["type"] = "fr"

let model: Experiment = try! OTUtils.model(from: data)
XCTAssertEqual(model.type, "fr")
}

func testDecodeSuccessWithNilType() {
let data: [String: Any] = ExperimentTests.sampleData
let model: Experiment = try! OTUtils.model(from: data)
XCTAssertNil(model.type)
}

}

// MARK: - Encode
Expand Down
Loading