Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-10136] clears local storage when replay is false #862

Merged
merged 2 commits into from
Nov 7, 2024
Merged
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
2 changes: 0 additions & 2 deletions swift-sdk/Internal/AnonymousUserManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {

IterableAPI.implementation?.updateUser(userUpdate, mergeNestedObjects: false)
}

clearVisitorEventsAndUserData()
}

public func clearVisitorEventsAndUserData() {
Expand Down
1 change: 1 addition & 0 deletions swift-sdk/Internal/AnonymousUserManagerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ import Foundation
func updateAnonSession()
func getAnonCriteria()
func syncEvents()
func clearVisitorEventsAndUserData()
}
1 change: 1 addition & 0 deletions swift-sdk/Internal/InternalIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
} else {
failureHandler?(error, nil)
}
self.anonymousUserManager.clearVisitorEventsAndUserData()
}
}

Expand Down
28 changes: 16 additions & 12 deletions tests/unit-tests/UserMergeScenariosTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
}
waitForDuration(seconds: 5)

let expectation1 = self.expectation(description: "Events properly cleared")
if let events = localStorage.anonymousUserEvents {
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
} else {
XCTFail("Events were incorrectly cleared")
expectation1.fulfill()
}

// Verify "merge user" API call is not made
let expectation = self.expectation(description: "No API call is made to merge user")
let expectation2 = self.expectation(description: "No API call is made to merge user")
DispatchQueue.main.async {
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
XCTFail("merge user API call was made unexpectedly")
} else {
expectation.fulfill()
expectation2.fulfill()
}
}

Expand Down Expand Up @@ -250,19 +251,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
}
waitForDuration(seconds: 5)

let expectation1 = self.expectation(description: "Events properly cleared")
if let events = localStorage.anonymousUserEvents {
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
} else {
XCTFail("Events were incorrectly cleared")
expectation1.fulfill()
}

// Verify "merge user" API call is not made
let expectation = self.expectation(description: "No API call is made to merge user")
let expectation2 = self.expectation(description: "No API call is made to merge user")
DispatchQueue.main.async {
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
XCTFail("merge user API call was made unexpectedly")
} else {
expectation.fulfill()
expectation2.fulfill()
}
}

Expand Down Expand Up @@ -649,19 +651,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
}
waitForDuration(seconds: 5)

let expectation1 = self.expectation(description: "Events properly cleared")
if let events = localStorage.anonymousUserEvents {
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
} else {
XCTFail("Events were incorrectly cleared")
expectation1.fulfill()
}

// Verify "merge user" API call is not made
let expectation = self.expectation(description: "No API call is made to merge user")
let expectation2 = self.expectation(description: "No API call is made to merge user")
DispatchQueue.main.async {
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
XCTFail("merge user API call was made unexpectedly")
} else {
expectation.fulfill()
expectation2.fulfill()
}
}

Expand Down Expand Up @@ -695,19 +698,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
}
waitForDuration(seconds: 5)

let expectation1 = self.expectation(description: "Events properly cleared")
if let events = localStorage.anonymousUserEvents {
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
} else {
XCTFail("Events were incorrectly cleared")
expectation1.fulfill()
}

// Verify "merge user" API call is not made
let expectation = self.expectation(description: "No API call is made to merge user")
let expectation2 = self.expectation(description: "No API call is made to merge user")
DispatchQueue.main.async {
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
XCTFail("merge user API call was made unexpectedly")
} else {
expectation.fulfill()
expectation2.fulfill()
}
}

Expand Down
Loading