Skip to content

Commit 6f8ca69

Browse files
We no longer need to move 'payload' element from inside 'content' element. 'customPayload' element is already there on top level.
1 parent aa98bb7 commit 6f8ca69

File tree

4 files changed

+5
-122
lines changed

4 files changed

+5
-122
lines changed

Tests/swift-sdk-swift-tests/InAppHelperTests.swift

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -304,102 +304,8 @@ class InAppHelperTests: XCTestCase {
304304
TestUtils.validateMatch(keyPath: KeyPath("myPayload.var1"), value: "val1", inDictionary: dict, message: "Expected to find val1")
305305
}
306306

307-
// This tests payload as we are getting now
308-
func testInAppParsingWithCurrentPayload() {
309-
let customPayload1 = """
310-
{
311-
"contentType" : "html",
312-
"inAppType" : "default",
313-
"channelName" : "channel1"
314-
}
315-
"""
316-
let customPayload2 = """
317-
{
318-
"contentType" : "html",
319-
"inAppType" : "inBox",
320-
"channelName" : "channel2",
321-
"promoteToContent" : {
322-
"title" : "title",
323-
"subTitle" : "subtitle",
324-
"imageUrl" : "http://somewhere.com/something.jpg"
325-
}
326-
}
327-
"""
328-
329-
let payload = """
330-
{
331-
"inAppMessages" : [
332-
{
333-
"content" : {
334-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>",
335-
"payload" : \(customPayload1),
336-
},
337-
"messageId" : "messageIdxxx",
338-
"campaignId" : "campaignIdxxx",
339-
"trigger" : {
340-
"type" : "myNewKind",
341-
"myPayload" : {"var1" : "val1"}
342-
}
343-
},
344-
{
345-
"content" : {
346-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>",
347-
"payload" : \(customPayload2),
348-
},
349-
"messageId" : "messageIdxxx",
350-
"campaignId" : "campaignIdxxx",
351-
"trigger" : {
352-
"type" : "myNewKind",
353-
"myPayload" : {"var1" : "val1"}
354-
}
355-
},
356-
{
357-
"content" : {
358-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>",
359-
"payload" : {
360-
},
361-
},
362-
"messageId" : "messageIdxxx",
363-
"campaignId" : "campaignIdxxx",
364-
"trigger" : {
365-
"type" : "myNewKind",
366-
"myPayload" : {"var1" : "val1"}
367-
}
368-
},
369-
{
370-
"content" : {
371-
"html" : "<a href=\\"http://somewhere.com\\">Click here</a>"
372-
},
373-
"messageId" : "messageIdxxx",
374-
"campaignId" : "campaignIdxxx",
375-
"trigger" : {
376-
"type" : "myNewKind",
377-
"myPayload" : {"var1" : "val1"}
378-
}
379-
}
380-
]
381-
}
382-
""".toJsonDict()
383-
let messages = InAppHelper.inAppMessages(fromPayload: payload, internalApi: IterableAPI.internalImplementation!)
384-
385-
XCTAssertEqual(messages.count, 4)
386-
let message1 = messages[0]
387-
XCTAssertEqual(message1.channelName, "channel1")
388-
XCTAssertTrue(TestUtils.areEqual(dict1: message1.extraInfo!, dict2: customPayload1.toJsonDict()))
389-
390-
let message2 = messages[1]
391-
XCTAssertEqual(message2.channelName, "channel2")
392-
XCTAssertTrue(TestUtils.areEqual(dict1: message2.extraInfo!, dict2: customPayload2.toJsonDict()))
393-
394-
let message3 = messages[2]
395-
XCTAssertEqual(message3.channelName, "")
396-
397-
let message4 = messages[3]
398-
XCTAssertEqual(message4.channelName, "")
399-
}
400-
401307
// This tests payload as we expect to get when backend is fixed
402-
func testInAppParsingWithFuturePayload() {
308+
func testInAppPayloadParsing() {
403309
let customPayload1 = """
404310
{
405311
"contentType" : "html",
@@ -497,10 +403,10 @@ class InAppHelperTests: XCTestCase {
497403
"content" : [
498404
"html" : "<a href='href1'>Click Here</a>",
499405
"inAppDisplaySettings" : ["backgroundAlpha" : 0.5, "left" : ["percentage" : 60], "right" : ["percentage" : 60], "bottom" : ["displayOption" : "AutoExpand"], "top" : ["displayOption" : "AutoExpand"]],
500-
"payload" : extraInfo
501406
],
502407
"messageId" : "messageIdxxx",
503408
"campaignId" : "campaignIdxxx",
409+
"customPayload" : extraInfo
504410
]]
505411
]
506412
}

Tests/swift-sdk-swift-tests/TestInAppPayloadGenerator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ struct TestInAppPayloadGenerator {
8181
"content" : [
8282
"html" : "<a href='\(href)'>Click Here</a>",
8383
"inAppDisplaySettings" : ["backgroundAlpha" : 0.5, "left" : ["percentage" : 60], "right" : ["percentage" : 60], "bottom" : ["displayOption" : "AutoExpand"], "top" : ["displayOption" : "AutoExpand"]],
84-
"payload" : ["channelName" : "inBox", "title" : "Product 1 Available", "date" : "2018-11-14T14:00:00:00.32Z"]
8584
],
8685
"messageId" : getMessageId(index: index),
87-
"campaignId" : getCampaignId(index: index)
86+
"campaignId" : getCampaignId(index: index),
87+
"customPayload" : ["channelName" : "inBox", "title" : "Product 1 Available", "date" : "2018-11-14T14:00:00:00.32Z"]
8888
]
8989
}
9090

swift-sdk/ITBConsts.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ public extension AnyHashable {
156156
public static let ITBL_IN_APP_HTML = "html"
157157
public static let ITBL_IN_APP_HREF = "href"
158158
public static let ITBL_IN_APP_DISPLAY_SETTINGS = "inAppDisplaySettings"
159-
public static let ITBL_IN_APP_LEGACY_PAYLOAD = "payload"
160159
public static let ITBL_IN_APP_CUSTOM_PAYLOAD = "customPayload"
161160
public static let ITBL_IN_APP_CHANNEL_NAME = "channelName"
162161
}

swift-sdk/Internal/InAppHelper.swift

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -324,32 +324,10 @@ struct InAppHelper {
324324

325325
private static func parseInApps(fromPayload payload: [AnyHashable : Any]) -> [InAppParseResult] {
326326
return getInAppDicts(fromPayload: payload).map {
327-
parseInApp(fromDict: preProcess(dict:$0))
327+
parseInApp(fromDict: $0)
328328
}
329329
}
330330

331-
// Change the in-app payload coming from the server to one that we expect it to be like
332-
// This is temporary until we fix the backend to do the right thing.
333-
// 1. Move 'payload' from inside 'content' to top level 'customPayload'
334-
// 2. form this 'customPayload' move elements to top level making sure not to
335-
// override 'messageId' etc. Moving elements to top level will help us simulate when we add these
336-
// elements later in backend
337-
#warning("Remove when we have backend support")
338-
private static func preProcess(dict: [AnyHashable : Any]) -> [AnyHashable : Any] {
339-
var result = dict
340-
guard let contentDict = dict[.ITBL_IN_APP_CONTENT] as? [AnyHashable : Any], let legacyPayloadDict = contentDict[.ITBL_IN_APP_LEGACY_PAYLOAD] as? [AnyHashable : Any] else {
341-
return result
342-
}
343-
344-
var newContentDict = contentDict
345-
newContentDict[.ITBL_IN_APP_LEGACY_PAYLOAD] = nil
346-
result[.ITBL_IN_APP_CONTENT] = newContentDict
347-
348-
result[.ITBL_IN_APP_CUSTOM_PAYLOAD] = legacyPayloadDict
349-
350-
return result
351-
}
352-
353331
private static func parseInApp(fromDict dict: [AnyHashable : Any]) -> InAppParseResult {
354332
guard let content = dict[.ITBL_IN_APP_CONTENT] as? [AnyHashable : Any] else {
355333
return .failure(reason: "no message", messageId: nil)

0 commit comments

Comments
 (0)