-
Notifications
You must be signed in to change notification settings - Fork 16
/
PushEventHandlerTest.swift
48 lines (37 loc) · 1.88 KB
/
PushEventHandlerTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@testable import CioMessagingPush
import Foundation
import SharedTests
import XCTest
class PushEventHandlerTest: UnitTest {
private var pushEventHandler: PushEventHandler!
private var pushEventHandlerProxy: PushEventHandlerProxy {
diGraphShared.pushEventHandlerProxy
}
private var pushClickHandler = PushClickHandlerMock()
override func setUp() {
super.setUp()
pushEventHandler = IOSPushEventListener(
jsonAdapter: diGraph.jsonAdapter,
pushEventHandlerProxy: pushEventHandlerProxy,
moduleConfig: diGraphShared.messagingPushConfigOptions,
pushClickHandler: pushClickHandler,
pushHistory: diGraphShared.pushHistory,
logger: diGraph.logger
)
}
// MARK: onPushAction
/*
The CIO SDK push event handler forwards push notifications to other push event handlers in the host app.
But, what if the CIO SDK event handler forwards a push event back to the CIO SDK event handler? This could cause an infinite loop.
This test simulates that scenario to make sure that an inifinite loop would not happen.
*/
func test_onPushAction_expectNoInfiniteLoopIfSdkForwardsPushEventBacktoSdkAgain() {
// The push event handler proxy is what forwards push events to other push event handlers in the app.
// To test if an infinite loop would happen, add ourself as a push event handler to get events forwarded to.
pushEventHandlerProxy.addPushEventHandler(pushEventHandler)
// Make sure push is not from CIO otherwise event does not get forwarded.
let givenPush = PushNotificationStub.getPushNotSentFromCIO()
// Send the CIO SDK push event handler an event. If an infinite loop occurs, this test will timeout or crash.
pushEventHandler.onPushAction(PushNotificationActionStub(push: givenPush, didClickOnPush: true)) {}
}
}