Skip to content

Commit e55c8ec

Browse files
Simplify
1 parent 458f74d commit e55c8ec

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

Tests/swift-sdk-swift-tests/IterableNotificationResponseTests.swift

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ class IterableNotificationResponseTests: XCTestCase {
3030
dateProvider.currentDate = Date()
3131
}
3232

33-
private func customActionHandler(fromPromise promise: Promise<String, Error>, inContext context:IterableActionContext) -> CustomActionHandler {
33+
private static func customActionHandler(fromPromise promise: Promise<String, Error>) -> CustomActionHandler {
3434
return {(customActionName) in
3535
promise.resolve(with: customActionName)
3636
return true
3737
}
3838
}
3939

40-
private func contextToCustomActionHandler(fromPromise promise: Promise<String, Error>) -> (IterableActionContext) -> CustomActionHandler {
41-
return IterableUtil.curry(customActionHandler(fromPromise:inContext:))(promise)
40+
private static func contextToCustomActionHandler(fromPromise promise: Promise<String, Error>) -> (IterableActionContext) -> CustomActionHandler {
41+
return {(context) in
42+
customActionHandler(fromPromise: promise)
43+
}
4244
}
4345

4446
func testTrackOpenPushWithCustomAction() {
@@ -61,22 +63,23 @@ class IterableNotificationResponseTests: XCTestCase {
6163

6264
let response = MockNotificationResponse(userInfo: userInfo, actionIdentifier: UNNotificationDefaultActionIdentifier)
6365
let pushTracker = MockPushTracker()
64-
var calledCustomActionName:String?
65-
let contextToCustomActionHandler: ((IterableActionContext) -> CustomActionHandler) = {(context) in { (customActionName) in
66-
calledCustomActionName = customActionName
67-
return true
66+
let promise = Promise<String, Error>()
67+
promise.observe { (result) in
68+
switch (result) {
69+
case .error(let error):
70+
XCTFail(error.localizedDescription)
71+
case .value(let customActionName):
72+
XCTAssertEqual(customActionName, "customAction")
6873
}
6974
}
70-
75+
7176
let appIntegration = IterableAppIntegrationInternal(tracker: pushTracker,
7277
versionInfo: MockVersionInfo(version: 10),
7378
contextToUrlHandler: nil,
74-
contextToCustomActionHandler: contextToCustomActionHandler,
79+
contextToCustomActionHandler: IterableNotificationResponseTests.contextToCustomActionHandler(fromPromise: promise),
7580
urlOpener: MockUrlOpener())
7681
appIntegration.userNotificationCenter(nil, didReceive: response, withCompletionHandler: nil)
7782

78-
XCTAssertEqual(calledCustomActionName, "customAction");
79-
8083
XCTAssertEqual(pushTracker.campaignId, 1234)
8184
XCTAssertEqual(pushTracker.templateId, 4321)
8285
XCTAssertEqual(pushTracker.messageId, messageId)
@@ -123,7 +126,7 @@ class IterableNotificationResponseTests: XCTestCase {
123126
let appIntegration = IterableAppIntegrationInternal(tracker: pushTracker,
124127
versionInfo: MockVersionInfo(version: 10),
125128
contextToUrlHandler: nil,
126-
contextToCustomActionHandler: contextToCustomActionHandler(fromPromise: promise),
129+
contextToCustomActionHandler: IterableNotificationResponseTests.contextToCustomActionHandler(fromPromise: promise),
127130
urlOpener: MockUrlOpener())
128131
appIntegration.userNotificationCenter(nil, didReceive: response, withCompletionHandler: nil)
129132

@@ -163,7 +166,7 @@ class IterableNotificationResponseTests: XCTestCase {
163166
let appIntegration = IterableAppIntegrationInternal(tracker: pushTracker,
164167
versionInfo: MockVersionInfo(version: 9),
165168
contextToUrlHandler: nil,
166-
contextToCustomActionHandler: contextToCustomActionHandler(fromPromise: promise),
169+
contextToCustomActionHandler: IterableNotificationResponseTests.contextToCustomActionHandler(fromPromise: promise),
167170
urlOpener: MockUrlOpener())
168171
appIntegration.application(MockApplicationStateProvider(applicationState: .inactive), didReceiveRemoteNotification: userInfo, fetchCompletionHandler: nil)
169172

swift-sdk/IterableActionInterpreter.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ struct IterableActionInterpreter {
107107

108108
// it will partially bind urlDelegate and return a mapping from IterableActionContext to UrlHandler
109109
static func contextToUrlHandler(fromUrlDelegate urlDelegate: IterableURLDelegate?) -> (IterableActionContext) -> UrlHandler {
110-
return IterableUtil.curry(urlHandler(fromUrlDelegate: inContext:))(urlDelegate)
110+
return {(context) in
111+
urlHandler(fromUrlDelegate: urlDelegate, inContext: context)
112+
}
111113
}
112114

113115
// converts from IterableCustomActionDelegate to CustomActionHandler
@@ -124,8 +126,9 @@ struct IterableActionInterpreter {
124126

125127
// it will partially bind customActionDelegate and return a mapping from IterableActionContext to CustomActionHandler
126128
static func contextToCustomActionHandler(fromCustomActionDelegate customActionDelegate: IterableCustomActionDelegate?) -> (IterableActionContext) -> CustomActionHandler {
127-
return IterableUtil.curry(customActionHandler(fromCustomActionDelegate:inContext:))(customActionDelegate)
129+
return {(context) in
130+
customActionHandler(fromCustomActionDelegate: customActionDelegate, inContext: context)
131+
}
128132
}
129-
130133
}
131134

swift-sdk/IterableUtil.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ import os
2828
static func isNotNullOrEmpty(string: String) -> Bool {
2929
return !isNullOrEmpty(string: string)
3030
}
31-
32-
// Given a function that maps (x,y) to z,
33-
// returns a partial function that maps (y) to z.
34-
static func curry<X, Y, Z>(_ f: @escaping (X, Y) -> Z) -> (X) -> ((Y) -> Z) {
35-
return { x in { y in f(x, y) } }
36-
}
3731
}
3832

3933
public func ITBError(_ message: String? = nil, file: String = #file, method: String = #function, line: Int = #line) {

0 commit comments

Comments
 (0)