@@ -165,6 +165,78 @@ class IterableAPITests: XCTestCase {
165
165
166
166
wait ( for: [ expectation] , timeout: testExpectationTimeout)
167
167
}
168
+
169
+ func testSetEmailWithCallbackSuccess( ) {
170
+ let expectation = XCTestExpectation ( description: " Set email with callback success " )
171
+
172
+ let config = IterableConfig ( )
173
+ let networkSession = MockNetworkSession ( statusCode: 200 )
174
+ let internalAPI = InternalIterableAPI . initializeForTesting ( apiKey: IterableAPITests . apiKey, config: config, networkSession: networkSession)
175
+
176
+ internalAPI
. setEmail ( " [email protected] " , successHandler
: { success
in
177
+ XCTAssertNotNil ( success)
178
+ expectation. fulfill ( )
179
+ } , failureHandler: { _, _ in
180
+ XCTFail ( " Failed to set email " )
181
+ expectation. fulfill ( )
182
+ } )
183
+ internalAPI. register ( token: " zeeToken " . data ( using: . utf8) !)
184
+ wait ( for: [ expectation] , timeout: testExpectationTimeout)
185
+ }
186
+
187
+ func testSetEmailWithCallbackFailure( ) {
188
+ let expectation = XCTestExpectation ( description: " Set email with callback failure " )
189
+
190
+ let config = IterableConfig ( )
191
+ let networkSession = MockNetworkSession ( statusCode: 400 )
192
+ let internalAPI = InternalIterableAPI . initializeForTesting ( apiKey: IterableAPITests . apiKey, config: config, networkSession: networkSession)
193
+
194
+ internalAPI. setEmail ( " invalid_email " , successHandler: { success in
195
+ XCTFail ( " Email should not be set successfully " )
196
+ expectation. fulfill ( )
197
+ } , failureHandler: { _, error in
198
+ XCTAssertNotNil ( error)
199
+ expectation. fulfill ( )
200
+ } )
201
+ internalAPI. register ( token: " zeeToken " . data ( using: . utf8) !)
202
+ wait ( for: [ expectation] , timeout: testExpectationTimeout)
203
+ }
204
+
205
+ func testSetUserIdWithCallbackSuccess( ) {
206
+ let expectation = XCTestExpectation ( description: " Set user ID with callback success " )
207
+
208
+ let config = IterableConfig ( )
209
+ let networkSession = MockNetworkSession ( statusCode: 200 )
210
+ let internalAPI = InternalIterableAPI . initializeForTesting ( apiKey: IterableAPITests . apiKey, config: config, networkSession: networkSession)
211
+
212
+ internalAPI. setUserId ( " user123 " , successHandler: { success in
213
+ XCTAssertNotNil ( success)
214
+ expectation. fulfill ( )
215
+ } , failureHandler: { _, _ in
216
+ XCTFail ( " Failed to set user ID " )
217
+ expectation. fulfill ( )
218
+ } )
219
+ internalAPI. register ( token: " zeeToken " . data ( using: . utf8) !)
220
+ wait ( for: [ expectation] , timeout: testExpectationTimeout)
221
+ }
222
+
223
+ func testSetUserIdWithCallbackFailure( ) {
224
+ let expectation = XCTestExpectation ( description: " Set user ID with callback failure " )
225
+
226
+ let config = IterableConfig ( )
227
+ let networkSession = MockNetworkSession ( statusCode: 400 )
228
+ let internalAPI = InternalIterableAPI . initializeForTesting ( apiKey: IterableAPITests . apiKey, config: config, networkSession: networkSession)
229
+
230
+ internalAPI. setUserId ( " user123 " , successHandler: { success in
231
+ XCTFail ( " User ID should not be set successfully " )
232
+ expectation. fulfill ( )
233
+ } , failureHandler: { _, error in
234
+ XCTAssertNotNil ( error)
235
+ expectation. fulfill ( )
236
+ } )
237
+ internalAPI. register ( token: " zeeToken " . data ( using: . utf8) !)
238
+ wait ( for: [ expectation] , timeout: testExpectationTimeout)
239
+ }
168
240
169
241
func testEmailPersistence( ) {
170
242
let internalAPI = InternalIterableAPI . initializeForTesting ( )
0 commit comments