Skip to content

Commit 709a05e

Browse files
authored
Merge pull request #862 from Iterable/evan/MOB-10136
[MOB-10136] clears local storage when replay is false
2 parents a2579be + 2955f6f commit 709a05e

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

swift-sdk/Internal/AnonymousUserManager.swift

-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ public class AnonymousUserManager: AnonymousUserManagerProtocol {
167167

168168
IterableAPI.implementation?.updateUser(userUpdate, mergeNestedObjects: false)
169169
}
170-
171-
clearVisitorEventsAndUserData()
172170
}
173171

174172
public func clearVisitorEventsAndUserData() {

swift-sdk/Internal/AnonymousUserManagerProtocol.swift

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ import Foundation
1414
func updateAnonSession()
1515
func getAnonCriteria()
1616
func syncEvents()
17+
func clearVisitorEventsAndUserData()
1718
}

swift-sdk/Internal/InternalIterableAPI.swift

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
231231
} else {
232232
failureHandler?(error, nil)
233233
}
234+
self.anonymousUserManager.clearVisitorEventsAndUserData()
234235
}
235236
}
236237

tests/unit-tests/UserMergeScenariosTests.swift

+16-12
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
202202
}
203203
waitForDuration(seconds: 5)
204204

205+
let expectation1 = self.expectation(description: "Events properly cleared")
205206
if let events = localStorage.anonymousUserEvents {
206207
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
207208
} else {
208-
XCTFail("Events were incorrectly cleared")
209+
expectation1.fulfill()
209210
}
210211

211212
// Verify "merge user" API call is not made
212-
let expectation = self.expectation(description: "No API call is made to merge user")
213+
let expectation2 = self.expectation(description: "No API call is made to merge user")
213214
DispatchQueue.main.async {
214215
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
215216
XCTFail("merge user API call was made unexpectedly")
216217
} else {
217-
expectation.fulfill()
218+
expectation2.fulfill()
218219
}
219220
}
220221

@@ -250,19 +251,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
250251
}
251252
waitForDuration(seconds: 5)
252253

254+
let expectation1 = self.expectation(description: "Events properly cleared")
253255
if let events = localStorage.anonymousUserEvents {
254256
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
255257
} else {
256-
XCTFail("Events were incorrectly cleared")
258+
expectation1.fulfill()
257259
}
258260

259261
// Verify "merge user" API call is not made
260-
let expectation = self.expectation(description: "No API call is made to merge user")
262+
let expectation2 = self.expectation(description: "No API call is made to merge user")
261263
DispatchQueue.main.async {
262264
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
263265
XCTFail("merge user API call was made unexpectedly")
264266
} else {
265-
expectation.fulfill()
267+
expectation2.fulfill()
266268
}
267269
}
268270

@@ -649,19 +651,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
649651
}
650652
waitForDuration(seconds: 5)
651653

654+
let expectation1 = self.expectation(description: "Events properly cleared")
652655
if let events = localStorage.anonymousUserEvents {
653656
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
654657
} else {
655-
XCTFail("Events were incorrectly cleared")
658+
expectation1.fulfill()
656659
}
657660

658661
// Verify "merge user" API call is not made
659-
let expectation = self.expectation(description: "No API call is made to merge user")
662+
let expectation2 = self.expectation(description: "No API call is made to merge user")
660663
DispatchQueue.main.async {
661664
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
662665
XCTFail("merge user API call was made unexpectedly")
663666
} else {
664-
expectation.fulfill()
667+
expectation2.fulfill()
665668
}
666669
}
667670

@@ -695,19 +698,20 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
695698
}
696699
waitForDuration(seconds: 5)
697700

701+
let expectation1 = self.expectation(description: "Events properly cleared")
698702
if let events = localStorage.anonymousUserEvents {
699703
XCTAssertFalse(events.isEmpty, "Expected events to be logged")
700704
} else {
701-
XCTFail("Events were incorrectly cleared")
705+
expectation1.fulfill()
702706
}
703707

704708
// Verify "merge user" API call is not made
705-
let expectation = self.expectation(description: "No API call is made to merge user")
709+
let expectation2 = self.expectation(description: "No API call is made to merge user")
706710
DispatchQueue.main.async {
707711
if let _ = self.mockSession.getRequest(withEndPoint: Const.Path.mergeUser) {
708712
XCTFail("merge user API call was made unexpectedly")
709713
} else {
710-
expectation.fulfill()
714+
expectation2.fulfill()
711715
}
712716
}
713717

0 commit comments

Comments
 (0)