Skip to content

Commit

Permalink
fix: fix nit
Browse files Browse the repository at this point in the history
  • Loading branch information
PouriaAmini committed Aug 6, 2024
1 parent fc67118 commit 101b34a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 60 deletions.
11 changes: 9 additions & 2 deletions Sources/Amplitude/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class Configuration {
}() {
didSet {
defaultTracking.delegate = self
autocapture = defaultTracking.toAutocaptureOptions
autocapture = defaultTracking.autocaptureOptions
}
}
public internal(set) var autocapture: AutocaptureOptions
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -182,3 +182,10 @@ public class Configuration {
return Configuration.getNormalizeInstanceName(self.instanceName)
}
}

extension Configuration: DefaultTrackingOptionsDelegate {
@available(*, deprecated)
func didChangeOptions(options: DefaultTrackingOptions) {
autocapture = options.autocaptureOptions
}
}
19 changes: 6 additions & 13 deletions Sources/Amplitude/DefaultTrackingOptions.swift
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -29,7 +34,7 @@ public class DefaultTrackingOptions {

weak var delegate: DefaultTrackingOptionsDelegate?

var toAutocaptureOptions: AutocaptureOptions {
var autocaptureOptions: AutocaptureOptions {
return [
sessions ? .sessions : [],
appLifecycles ? .appLifecycles : [],
Expand All @@ -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
}
}
45 changes: 45 additions & 0 deletions Tests/AmplitudeTests/AutocaptureOptionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
45 changes: 0 additions & 45 deletions Tests/AmplitudeTests/ConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 101b34a

Please sign in to comment.