@@ -224,17 +224,17 @@ class InAppHelperTests: XCTestCase {
224
224
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
225
225
}
226
226
227
- func testExtraInfoParsing ( ) {
227
+ func testCustomPayloadParsing ( ) {
228
228
IterableAPI . initializeForTesting ( )
229
229
230
- let extraInfo : [ AnyHashable : Any ] = [ " string1 " : " value1 " , " bool1 " : true , " date1 " : Date ( ) ]
230
+ let customPayload : [ AnyHashable : Any ] = [ " string1 " : " value1 " , " bool1 " : true , " date1 " : Date ( ) ]
231
231
232
- let payload = createInAppPayload ( withExtraInfo : extraInfo )
232
+ let payload = createInAppPayload ( withCustomPayload : customPayload )
233
233
234
234
let messages = InAppHelper . inAppMessages ( fromPayload: payload, internalApi: IterableAPI . internalImplementation!)
235
235
236
236
XCTAssertEqual ( messages. count, 1 )
237
- let obtained = messages [ 0 ] . extraInfo
237
+ let obtained = messages [ 0 ] . customPayload
238
238
XCTAssertEqual ( obtained ? [ " string1 " ] as? String , " value1 " )
239
239
XCTAssertEqual ( obtained ? [ " bool1 " ] as? Bool , true )
240
240
}
@@ -304,45 +304,151 @@ class InAppHelperTests: XCTestCase {
304
304
TestUtils . validateMatch ( keyPath: KeyPath ( " myPayload.var1 " ) , value: " val1 " , inDictionary: dict, message: " Expected to find val1 " )
305
305
}
306
306
307
- // This tests payload as we expect to get when backend is fixed
308
- func testInAppPayloadParsing( ) {
309
- let customPayload1 = """
307
+ // Remove this test when backend is fixed
308
+ // This test assumes that certain parts of payload
309
+ // are in 'customPayload' element instead of the right places.
310
+ func testInAppPayloadParsingWithPreprocessing( ) {
311
+ let customPayloadStr1 = """
310
312
{
311
- " contentType " : " html " ,
312
- " inAppType " : " default " ,
313
- " channelName " : " channel1 "
313
+ " messageId " : " overridden " ,
314
+ " var1 " : " value1 " ,
315
+ " obj1 " : {
316
+ " something " : true,
317
+ " nothing " : " is nothing "
318
+ },
314
319
}
315
320
"""
316
- let customPayload2 = """
321
+ var customPayload1 = customPayloadStr1. toJsonDict ( )
322
+ customPayload1 [ " inAppType " ] = " default "
323
+ customPayload1 [ " contentType " ] = " html "
324
+
325
+ let customPayloadStr2 = """
317
326
{
318
- " contentType " : " html " ,
319
- " inAppType " : " inBox " ,
320
- " channelName " : " channel2 " ,
321
327
" promoteToContent " : {
322
328
" title " : " title " ,
323
329
" subTitle " : " subtitle " ,
324
330
" imageUrl " : " http://somewhere.com/something.jpg "
325
331
}
326
332
}
327
333
"""
334
+ var customPayload2 = customPayloadStr2. toJsonDict ( )
335
+ customPayload2 [ " inAppType " ] = " inbox "
336
+ customPayload2 [ " contentType " ] = " html "
337
+
338
+ let payload = """
339
+ {
340
+ " inAppMessages " : [
341
+ {
342
+ " content " : {
343
+ " html " : " <a href= \\ " http://somewhere.com \\ " >Click here</a> "
344
+ },
345
+ " messageId " : " messageId1 " ,
346
+ " campaignId " : " campaignIdxxx " ,
347
+ " trigger " : {
348
+ " type " : " myNewKind " ,
349
+ " myPayload " : { " var1 " : " val1 " }
350
+ },
351
+ " customPayload " : \( customPayload1. toJsonString ( ) )
352
+ },
353
+ {
354
+ " content " : {
355
+ " html " : " <a href= \\ " http://somewhere.com \\ " >Click here</a> "
356
+ },
357
+ " messageId " : " messageId2 " ,
358
+ " campaignId " : " campaignIdxxx " ,
359
+ " trigger " : {
360
+ " type " : " myNewKind " ,
361
+ " myPayload " : { " var1 " : " val1 " }
362
+ },
363
+ " customPayload " : \( customPayload2. toJsonString ( ) )
364
+ },
365
+ {
366
+ " content " : {
367
+ " html " : " <a href= \\ " http://somewhere.com \\ " >Click here</a> "
368
+ },
369
+ " messageId " : " messageId3 " ,
370
+ " campaignId " : " campaignIdxxx " ,
371
+ " trigger " : {
372
+ " type " : " myNewKind " ,
373
+ " myPayload " : { " var1 " : " val1 " }
374
+ },
375
+ " customPayload " : {}
376
+ },
377
+ {
378
+ " content " : {
379
+ " html " : " <a href= \\ " http://somewhere.com \\ " >Click here</a> "
380
+ },
381
+ " messageId " : " messageId4 " ,
382
+ " campaignId " : " campaignIdxxx " ,
383
+ " trigger " : {
384
+ " type " : " myNewKind " ,
385
+ " myPayload " : { " var1 " : " val1 " }
386
+ }
387
+ }
388
+ ]
389
+ }
390
+ """ . toJsonDict ( )
391
+ let messages = InAppHelper . inAppMessages ( fromPayload: payload, internalApi: IterableAPI . internalImplementation!)
392
+
393
+ XCTAssertEqual ( messages. count, 4 )
394
+ let message1 = messages [ 0 ]
395
+ XCTAssertEqual ( message1. messageId, " messageId1 " )
396
+ XCTAssertEqual ( message1. inAppType, . default)
397
+ XCTAssertTrue ( TestUtils . areEqual ( dict1: message1. customPayload!, dict2: customPayloadStr1. toJsonDict ( ) ) )
328
398
399
+ let message2 = messages [ 1 ]
400
+ XCTAssertEqual ( message2. inAppType, . inbox)
401
+ XCTAssertTrue ( TestUtils . areEqual ( dict1: message2. customPayload!, dict2: customPayloadStr2. toJsonDict ( ) ) )
402
+
403
+ let message3 = messages [ 2 ]
404
+ XCTAssertEqual ( message3. inAppType, . default)
405
+
406
+ let message4 = messages [ 3 ]
407
+ XCTAssertEqual ( message4. inAppType, . default)
408
+ }
409
+
410
+
411
+ func testInAppPayloadParsing( ) {
412
+ let customPayloadStr1 = """
413
+ {
414
+ " var1 " : " value1 " ,
415
+ " obj1 " : {
416
+ " something " : true,
417
+ " nothing " : " is nothing "
418
+ }
419
+ }
420
+ """
421
+ let customPayloadStr2 = """
422
+ {
423
+ " promoteToContent " : {
424
+ " title " : " title " ,
425
+ " subTitle " : " subtitle " ,
426
+ " imageUrl " : " http://somewhere.com/something.jpg "
427
+ }
428
+ }
429
+ """
430
+
329
431
let payload = """
330
432
{
331
433
" inAppMessages " : [
332
434
{
333
435
" content " : {
436
+ " contentType " : " html " ,
334
437
" html " : " <a href= \\ " http://somewhere.com \\ " >Click here</a> "
335
438
},
336
439
" messageId " : " messageIdxxx " ,
337
440
" campaignId " : " campaignIdxxx " ,
441
+ " inAppType " : " default " ,
338
442
" trigger " : {
339
443
" type " : " myNewKind " ,
340
444
" myPayload " : { " var1 " : " val1 " }
341
445
},
342
- " customPayload " : \( customPayload1 )
446
+ " customPayload " : \( customPayloadStr1 )
343
447
},
344
448
{
449
+ " inAppType " : " inbox " ,
345
450
" content " : {
451
+ " contentType " : " html " ,
346
452
" html " : " <a href= \\ " http://somewhere.com \\ " >Click here</a> "
347
453
},
348
454
" messageId " : " messageIdxxx " ,
@@ -351,7 +457,7 @@ class InAppHelperTests: XCTestCase {
351
457
" type " : " myNewKind " ,
352
458
" myPayload " : { " var1 " : " val1 " }
353
459
},
354
- " customPayload " : \( customPayload2 )
460
+ " customPayload " : \( customPayloadStr2 )
355
461
},
356
462
{
357
463
" content " : {
@@ -383,21 +489,21 @@ class InAppHelperTests: XCTestCase {
383
489
384
490
XCTAssertEqual ( messages. count, 4 )
385
491
let message1 = messages [ 0 ]
386
- XCTAssertEqual ( message1. channelName , " channel1 " )
387
- XCTAssertTrue ( TestUtils . areEqual ( dict1: message1. extraInfo !, dict2: customPayload1 . toJsonDict ( ) ) )
492
+ XCTAssertEqual ( message1. inAppType , . default )
493
+ XCTAssertTrue ( TestUtils . areEqual ( dict1: message1. customPayload !, dict2: customPayloadStr1 . toJsonDict ( ) ) )
388
494
389
495
let message2 = messages [ 1 ]
390
- XCTAssertEqual ( message2. channelName , " channel2 " )
391
- XCTAssertTrue ( TestUtils . areEqual ( dict1: message2. extraInfo !, dict2: customPayload2 . toJsonDict ( ) ) )
496
+ XCTAssertEqual ( message2. inAppType , . inbox )
497
+ XCTAssertTrue ( TestUtils . areEqual ( dict1: message2. customPayload !, dict2: customPayloadStr2 . toJsonDict ( ) ) )
392
498
393
499
let message3 = messages [ 2 ]
394
- XCTAssertEqual ( message3. channelName , " " )
395
-
500
+ XCTAssertEqual ( message3. inAppType , . default )
501
+
396
502
let message4 = messages [ 3 ]
397
- XCTAssertEqual ( message4. channelName , " " )
503
+ XCTAssertEqual ( message4. inAppType , . default )
398
504
}
399
505
400
- private func createInAppPayload( withExtraInfo extraInfo : [ AnyHashable : Any ] ) -> [ AnyHashable : Any ] {
506
+ private func createInAppPayload( withCustomPayload customPayload : [ AnyHashable : Any ] ) -> [ AnyHashable : Any ] {
401
507
return [
402
508
" inAppMessages " : [ [
403
509
" content " : [
@@ -406,7 +512,7 @@ class InAppHelperTests: XCTestCase {
406
512
] ,
407
513
" messageId " : " messageIdxxx " ,
408
514
" campaignId " : " campaignIdxxx " ,
409
- " customPayload " : extraInfo
515
+ " customPayload " : customPayload
410
516
] ]
411
517
]
412
518
}
0 commit comments