@@ -84,35 +84,45 @@ class UserMergeScenariosTests: XCTestCase, AuthProvider {
84
84
}
85
85
86
86
func testCriteriaNotMetUserIdDefault( ) { // criteria not met with merge default with setUserId
87
+ // Setup
87
88
let config = IterableConfig ( )
88
89
config. enableAnonActivation = true
89
90
IterableAPI . initializeForTesting ( apiKey: UserMergeScenariosTests . apiKey,
90
91
config: config,
91
92
networkSession: mockSession,
92
93
localStorage: localStorage)
93
94
IterableAPI . logoutUser ( )
95
+
94
96
guard let jsonData = mockData. data ( using: . utf8) else { return }
95
97
localStorage. criteriaData = jsonData
98
+
99
+ // trigger custom event
96
100
IterableAPI . track ( event: " testEvent123 " )
97
101
98
- if let events = localStorage. anonymousUserEvents {
99
- XCTAssertFalse ( events. isEmpty, " Expected events to be logged " )
100
- } else {
101
- XCTFail ( " Expected events to be logged but found nil " )
102
- }
102
+ waitForDuration ( seconds: 1 )
103
+
104
+ // Verify no purchase or anon session requests were made initially
105
+ XCTAssertNil ( mockSession. getRequest ( withEndPoint: Const . Path. trackAnonSession) ,
106
+ " There should not be an anon session request " )
107
+ XCTAssertNil ( mockSession. getRequest ( withEndPoint: Const . Path. trackPurchase) ,
108
+ " There should not be a purchase request " )
109
+
103
110
104
111
IterableAPI . setUserId ( " testuser123 " )
112
+
105
113
if let userId = IterableAPI . userId {
106
114
XCTAssertEqual ( userId, " testuser123 " , " Expected userId to be 'testuser123' " )
107
115
} else {
108
116
XCTFail ( " Expected userId but found nil " )
109
117
}
110
118
waitForDuration ( seconds: 5 )
111
119
112
- if localStorage. anonymousUserEvents != nil {
113
- XCTFail ( " Events are not replayed " )
120
+ // Verify purchase request was made after setting user ID
121
+ if let purchaseRequest = mockSession. getRequest ( withEndPoint: Const . Path. trackPurchase) {
122
+ XCTAssertNotNil ( purchaseRequest, " Expected purchase request on event replay " )
123
+ // Optional: Verify request details if needed
114
124
} else {
115
- XCTAssertNil ( localStorage . anonymousUserEvents , " Expected events to be nil " )
125
+ XCTFail ( " No purchase request was made after setting user ID " )
116
126
}
117
127
118
128
// Verify "merge user" API call is not made
0 commit comments