From d5ebde4613bead1625adb9a6420907ee19790235 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 2 Feb 2023 08:41:28 +0530 Subject: [PATCH 1/6] Make `Variation` confirm to Codable. --- Sources/Experiments/ABTesting.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Experiments/ABTesting.swift b/Sources/Experiments/ABTesting.swift index 3186e7a2..93fb57ad 100644 --- a/Sources/Experiments/ABTesting.swift +++ b/Sources/Experiments/ABTesting.swift @@ -1,6 +1,6 @@ import Foundation -public enum Variation: Equatable { +public enum Variation: Equatable, Codable { case control case treatment case customTreatment(name: String) From 72e0f76e6983f61f2b15f0d360461cdf1344df64 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 2 Feb 2023 08:42:44 +0530 Subject: [PATCH 2/6] Stop returning control as default variation by making the return type optional. --- Sources/Experiments/ABTesting.swift | 2 +- Sources/Experiments/ExPlat.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Experiments/ABTesting.swift b/Sources/Experiments/ABTesting.swift index 93fb57ad..bee6a4b0 100644 --- a/Sources/Experiments/ABTesting.swift +++ b/Sources/Experiments/ABTesting.swift @@ -13,5 +13,5 @@ public protocol ABTesting { func refresh(completion: (() -> Void)?) /// Return an experiment variation - func experiment(_ name: String) -> Variation + func experiment(_ name: String) -> Variation? } diff --git a/Sources/Experiments/ExPlat.swift b/Sources/Experiments/ExPlat.swift index 24cbd89b..278e487f 100644 --- a/Sources/Experiments/ExPlat.swift +++ b/Sources/Experiments/ExPlat.swift @@ -95,10 +95,10 @@ import Cocoa } } - public func experiment(_ name: String) -> Variation { + public func experiment(_ name: String) -> Variation? { guard let assignments = UserDefaults.standard.object(forKey: assignmentsKey) as? [String: String?], case let variation?? = assignments[name] else { - return .control + return nil } switch variation { From 72fb4a54c7e0f24b8aa497ad096d72172d924823 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 2 Feb 2023 08:46:49 +0530 Subject: [PATCH 3/6] Bump podspec version. --- Automattic-Tracks-iOS.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Automattic-Tracks-iOS.podspec b/Automattic-Tracks-iOS.podspec index 49804706..f5af3162 100644 --- a/Automattic-Tracks-iOS.podspec +++ b/Automattic-Tracks-iOS.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'Automattic-Tracks-iOS' - s.version = '1.0.0' + s.version = '1.1.0-beta' s.summary = 'Simple way to track events in an iOS app with Automattic Tracks internal service' s.description = <<-DESC From 3c15eb0450aa5f70aff29bc2e465e6005ce41a47 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 2 Feb 2023 08:49:55 +0530 Subject: [PATCH 4/6] Update library version in constants to fix CI. --- Sources/Model/ObjC/Constants/TracksConstants.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Model/ObjC/Constants/TracksConstants.m b/Sources/Model/ObjC/Constants/TracksConstants.m index 7abc8947..5b1f8348 100644 --- a/Sources/Model/ObjC/Constants/TracksConstants.m +++ b/Sources/Model/ObjC/Constants/TracksConstants.m @@ -1,4 +1,4 @@ #import "TracksConstants.h" NSString *const TracksErrorDomain = @"TracksErrorDomain"; -NSString *const TracksLibraryVersion = @"1.0.0"; +NSString *const TracksLibraryVersion = @"1.1.0-beta"; From d7d220bee5ceb51942dc54c2df74cc4486bb2c09 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 2 Feb 2023 09:22:14 +0530 Subject: [PATCH 5/6] Expect nil in unit tests. --- Tests/Tests/ABTesting/ExPlatTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Tests/ABTesting/ExPlatTests.swift b/Tests/Tests/ABTesting/ExPlatTests.swift index 1fe51bd7..c44ac5e9 100644 --- a/Tests/Tests/ABTesting/ExPlatTests.swift +++ b/Tests/Tests/ABTesting/ExPlatTests.swift @@ -21,7 +21,7 @@ class ExPlatTests: XCTestCase { let abTesting = ExPlat(configuration: exPlatTestConfiguration, service: ExPlatServiceMock()) abTesting.refresh { - XCTAssertEqual(abTesting.experiment("experiment"), .control) + XCTAssertNil(abTesting.experiment("experiment")) XCTAssertEqual(abTesting.experiment("another_experiment"), .treatment) XCTAssertEqual(abTesting.experiment("experiment_multiple_variation"), .customTreatment(name: "another_treatment")) expectation.fulfill() @@ -70,7 +70,7 @@ class ExPlatTests: XCTestCase { serviceMock.returnAssignments = false abTesting.refresh { - XCTAssertEqual(abTesting.experiment("experiment"), .control) + XCTAssertNil(abTesting.experiment("experiment")) XCTAssertEqual(abTesting.experiment("another_experiment"), .treatment) XCTAssertEqual(abTesting.experiment("experiment_multiple_variation"), .customTreatment(name: "another_treatment")) expectation.fulfill() From f990056f1d7f5ccac2d8c8d6e0a41ef60ea9c004 Mon Sep 17 00:00:00 2001 From: Sharma Elanthiraiyan Date: Thu, 2 Feb 2023 09:22:36 +0530 Subject: [PATCH 6/6] Update change log. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c4aac3a..42d7922f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ _None._ - `logErrorImmediately` and `logErrorsImmediately` no longer have a `Result` parameter in their callback [#232] - `logErrorImmediately` and `logErrorsImmediately` no longer `throws` [#236] +- `ExPlat` returns optional instead of assuming `control` as variant. This lets the client know that there is no variant for an experiment. [#247] ### New Features @@ -49,3 +50,4 @@ _None._ - Add this changelog file [#234] - Log a message if events won't be collected because the user opted out [#239] +- Make `Variation` confirm to cobable. [#247]