From 101b34acd4d828ffa918837677c14c1aebd645fc Mon Sep 17 00:00:00 2001 From: "pouria.amini" Date: Tue, 6 Aug 2024 16:14:35 -0700 Subject: [PATCH] fix: fix nit --- Sources/Amplitude/Configuration.swift | 11 ++++- .../Amplitude/DefaultTrackingOptions.swift | 19 +++----- .../AutocaptureOptionsTests.swift | 45 +++++++++++++++++++ Tests/AmplitudeTests/ConfigurationTests.swift | 45 ------------------- 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/Sources/Amplitude/Configuration.swift b/Sources/Amplitude/Configuration.swift index 653db27e..590c4fba 100644 --- a/Sources/Amplitude/Configuration.swift +++ b/Sources/Amplitude/Configuration.swift @@ -38,7 +38,7 @@ public class Configuration { }() { didSet { defaultTracking.delegate = self - autocapture = defaultTracking.toAutocaptureOptions + autocapture = defaultTracking.autocaptureOptions } } public internal(set) var autocapture: AutocaptureOptions @@ -97,7 +97,7 @@ public class Configuration { enableCoppaControl: enableCoppaControl, flushEventsOnClose: flushEventsOnClose, minTimeBetweenSessionsMillis: minTimeBetweenSessionsMillis, - autocapture: defaultTracking.toAutocaptureOptions, + autocapture: defaultTracking.autocaptureOptions, identifyBatchIntervalMillis: identifyBatchIntervalMillis, migrateLegacyData: migrateLegacyData, offline: offline) @@ -182,3 +182,10 @@ public class Configuration { return Configuration.getNormalizeInstanceName(self.instanceName) } } + +extension Configuration: DefaultTrackingOptionsDelegate { + @available(*, deprecated) + func didChangeOptions(options: DefaultTrackingOptions) { + autocapture = options.autocaptureOptions + } +} diff --git a/Sources/Amplitude/DefaultTrackingOptions.swift b/Sources/Amplitude/DefaultTrackingOptions.swift index 6b651721..d4c4c2f6 100644 --- a/Sources/Amplitude/DefaultTrackingOptions.swift +++ b/Sources/Amplitude/DefaultTrackingOptions.swift @@ -1,5 +1,10 @@ import Foundation +protocol DefaultTrackingOptionsDelegate: AnyObject { + @available(*, deprecated) + func didChangeOptions(options: DefaultTrackingOptions) +} + @available(*, deprecated, renamed: "AutocaptureOptions", message: "Please use `AutocaptureOptions` instead") public class DefaultTrackingOptions { public static var ALL: DefaultTrackingOptions { @@ -29,7 +34,7 @@ public class DefaultTrackingOptions { weak var delegate: DefaultTrackingOptionsDelegate? - var toAutocaptureOptions: AutocaptureOptions { + var autocaptureOptions: AutocaptureOptions { return [ sessions ? .sessions : [], appLifecycles ? .appLifecycles : [], @@ -52,15 +57,3 @@ public class DefaultTrackingOptions { self.delegate = delegate } } - -protocol DefaultTrackingOptionsDelegate: AnyObject { - @available(*, deprecated) - func didChangeOptions(options: DefaultTrackingOptions) -} - -extension Configuration: DefaultTrackingOptionsDelegate { - @available(*, deprecated) - func didChangeOptions(options: DefaultTrackingOptions) { - autocapture = options.toAutocaptureOptions - } -} diff --git a/Tests/AmplitudeTests/AutocaptureOptionsTests.swift b/Tests/AmplitudeTests/AutocaptureOptionsTests.swift index 740837f9..5a308c67 100644 --- a/Tests/AmplitudeTests/AutocaptureOptionsTests.swift +++ b/Tests/AmplitudeTests/AutocaptureOptionsTests.swift @@ -18,4 +18,49 @@ final class AutocaptureOptionsTests: XCTestCase { XCTAssertFalse(options.contains(.sessions)) XCTAssertTrue(options.contains(.elementInteractions)) } + + func testDefaultTrackingOptionChangesReflectInAutocapture() { + let configuration = Configuration( + apiKey: "test-api-key" + ) + + XCTAssertTrue(configuration.autocapture.contains(.sessions)) + + (configuration as DeprecationWarningDiscardable).setDefaultTrackingOptions(sessions: false, appLifecycles: true, screenViews: true) + + XCTAssertFalse(configuration.autocapture.contains(.sessions)) + XCTAssertTrue(configuration.autocapture.contains(.appLifecycles)) + XCTAssertTrue(configuration.autocapture.contains(.screenViews)) + } + + func testDefaultTrackingInstanceChangeReflectInAutocapture() { + let configuration = Configuration( + apiKey: "test-api-key" + ) + + (configuration as DeprecationWarningDiscardable).setDefaultTracking(sessions: false, appLifecycles: true, screenViews: true) + + XCTAssertFalse(configuration.autocapture.contains(.sessions)) + XCTAssertTrue(configuration.autocapture.contains(.appLifecycles)) + XCTAssertTrue(configuration.autocapture.contains(.screenViews)) + } +} + +private protocol DeprecationWarningDiscardable { + func setDefaultTracking(sessions: Bool, appLifecycles: Bool, screenViews: Bool) + func setDefaultTrackingOptions(sessions: Bool, appLifecycles: Bool, screenViews: Bool) +} + +extension Configuration: DeprecationWarningDiscardable { + @available(*, deprecated) + func setDefaultTracking(sessions: Bool, appLifecycles: Bool, screenViews: Bool) { + defaultTracking = DefaultTrackingOptions(sessions: sessions, appLifecycles: appLifecycles, screenViews: screenViews) + } + + @available(*, deprecated) + func setDefaultTrackingOptions(sessions: Bool, appLifecycles: Bool, screenViews: Bool) { + defaultTracking.sessions = sessions + defaultTracking.appLifecycles = appLifecycles + defaultTracking.screenViews = screenViews + } } diff --git a/Tests/AmplitudeTests/ConfigurationTests.swift b/Tests/AmplitudeTests/ConfigurationTests.swift index a5ae8a83..e39eb770 100644 --- a/Tests/AmplitudeTests/ConfigurationTests.swift +++ b/Tests/AmplitudeTests/ConfigurationTests.swift @@ -88,49 +88,4 @@ final class ConfigurationTests: XCTestCase { XCTAssertTrue(eventStorageUrl?.contains(expectedStoragePostfix) ?? false) XCTAssertTrue(identifyStorageUrl?.contains(expectedStoragePostfix) ?? false) } - - func testDefaultTrackingOptionChangesReflectInAutocapture() { - let configuration = Configuration( - apiKey: "test-api-key" - ) - - XCTAssertTrue(configuration.autocapture.contains(.sessions)) - - (configuration as DeprecationWarningDiscardable).setDefaulTrackingOptions(sessions: false, appLifecycles: true, screenViews: true) - - XCTAssertFalse(configuration.autocapture.contains(.sessions)) - XCTAssertTrue(configuration.autocapture.contains(.appLifecycles)) - XCTAssertTrue(configuration.autocapture.contains(.screenViews)) - } - - func testDefaultTrackingInstanceChangeReflectInAutocapture() { - let configuration = Configuration( - apiKey: "test-api-key" - ) - - (configuration as DeprecationWarningDiscardable).setDefaulTracking(sessions: false, appLifecycles: true, screenViews: true) - - XCTAssertFalse(configuration.autocapture.contains(.sessions)) - XCTAssertTrue(configuration.autocapture.contains(.appLifecycles)) - XCTAssertTrue(configuration.autocapture.contains(.screenViews)) - } -} - -private protocol DeprecationWarningDiscardable { - func setDefaulTracking(sessions: Bool, appLifecycles: Bool, screenViews: Bool) - func setDefaulTrackingOptions(sessions: Bool, appLifecycles: Bool, screenViews: Bool) -} - -extension Configuration: DeprecationWarningDiscardable { - @available(*, deprecated) - func setDefaulTracking(sessions: Bool, appLifecycles: Bool, screenViews: Bool) { - defaultTracking = DefaultTrackingOptions(sessions: sessions, appLifecycles: appLifecycles, screenViews: screenViews) - } - - @available(*, deprecated) - func setDefaulTrackingOptions(sessions: Bool, appLifecycles: Bool, screenViews: Bool) { - defaultTracking.sessions = sessions - defaultTracking.appLifecycles = appLifecycles - defaultTracking.screenViews = screenViews - } }