@@ -246,12 +246,90 @@ class RequestCreatorTests: XCTestCase {
246
246
TestUtils . validateMatch ( keyPath: KeyPath ( JsonKey . templateId. jsonKey) , value: templateId, inDictionary: body)
247
247
}
248
248
249
+ func testUserlessUpdateUserRequest( ) {
250
+ let userlessRequestCreator = RequestCreator ( apiKey: apiKey,
251
+ auth: userlessAuth,
252
+ deviceMetadata: deviceMetadata)
253
+
254
+ let result = userlessRequestCreator. createUpdateUserRequest ( dataFields: [ : ] , mergeNestedObjects: false )
255
+
256
+ switch result {
257
+ case . success( _) :
258
+ XCTFail ( " request shouldn't have succeeded " )
259
+ case . failure( let error) :
260
+ XCTAssertEqual ( error. errorDescription, " Both email and userId are nil " )
261
+ }
262
+ }
263
+
264
+ func testUserlessUpdateSubscriptionsRequest( ) {
265
+ let userlessRequestCreator = RequestCreator ( apiKey: apiKey,
266
+ auth: userlessAuth,
267
+ deviceMetadata: deviceMetadata)
268
+
269
+ let result = userlessRequestCreator. createUpdateSubscriptionsRequest ( )
270
+
271
+ switch result {
272
+ case . success( _) :
273
+ XCTFail ( " request shouldn't have succeeded " )
274
+ case . failure( let error) :
275
+ XCTAssertEqual ( error. errorDescription, " Both email and userId are nil " )
276
+ }
277
+ }
278
+
279
+ func testUserlessTrackInboxSessionRequest( ) {
280
+ let userlessRequestCreator = RequestCreator ( apiKey: apiKey,
281
+ auth: userlessAuth,
282
+ deviceMetadata: deviceMetadata)
283
+
284
+ let result = userlessRequestCreator. createTrackInboxSessionRequest ( inboxSession: IterableInboxSession ( ) )
285
+
286
+ switch result {
287
+ case . success( _) :
288
+ XCTFail ( " request shouldn't have succeeded " )
289
+ case . failure( let error) :
290
+ XCTAssertEqual ( error. errorDescription, " Both email and userId are nil " )
291
+ }
292
+ }
293
+
294
+ func testFaultyTrackInboxSessionRequest( ) {
295
+ let condition1 = expectation ( description: " no inbox session ID " )
296
+ let condition2 = expectation ( description: " no inbox session start date " )
297
+ let condition3 = expectation ( description: " no inbox session end date " )
298
+
299
+ func createResultWithInboxSession( _ inboxSession: IterableInboxSession ) -> Result < IterableRequest , IterableError > {
300
+ return createRequestCreator ( ) . createTrackInboxSessionRequest ( inboxSession: inboxSession)
301
+ }
302
+
303
+ let inboxSessions = [ IterableInboxSession ( id: nil , sessionStartTime: Date ( ) , sessionEndTime: Date ( ) ) ,
304
+ IterableInboxSession ( id: " " , sessionStartTime: Date ( ) , sessionEndTime: nil ) ,
305
+ IterableInboxSession ( id: " " , sessionStartTime: nil , sessionEndTime: Date ( ) ) ]
306
+
307
+ for inboxSession in inboxSessions {
308
+ switch createResultWithInboxSession ( inboxSession) {
309
+ case . success( _) :
310
+ XCTFail ( " request shouldn't have succeeded " )
311
+ case . failure( let error) :
312
+ if error. errorDescription == " expecting session UUID " {
313
+ condition1. fulfill ( )
314
+ } else if error. errorDescription == " expecting session start time " {
315
+ condition2. fulfill ( )
316
+ } else if error. errorDescription == " expecting session end time " {
317
+ condition3. fulfill ( )
318
+ }
319
+ }
320
+ }
321
+
322
+ wait ( for: [ condition1, condition2, condition3] , timeout: testExpectationTimeout)
323
+ }
324
+
249
325
private let apiKey = " zee-api-key "
250
326
251
327
private let email = " [email protected] "
252
328
253
329
private let locationKeyPath = " \( JsonKey . inAppMessageContext. jsonKey) . \( JsonKey . inAppLocation. jsonKey) "
254
330
331
+ private let userlessAuth = Auth ( userId: nil , email: nil , authToken: nil )
332
+
255
333
private let deviceMetadata = DeviceMetadata ( deviceId: IterableUtil . generateUUID ( ) ,
256
334
platform: JsonValue . iOS. jsonStringValue,
257
335
appPackageName: Bundle . main. appPackageName ?? " " )
0 commit comments