@@ -90,6 +90,7 @@ class IterableAutoRegistrationTests: XCTestCase {
90
90
}
91
91
92
92
func testDoNotCallRegisterForRemoteNotificationsWhenNotificationsAreDisabled( ) {
93
+ let expectation0 = expectation ( description: " Call create user " )
93
94
let expectation1 = expectation ( description: " Call registerToken API endpoint " )
94
95
let expectation2 = expectation ( description: " Disable API endpoint called " )
95
96
let expectation3 = expectation ( description: " do not call registerForRemoteNotifications " )
@@ -107,23 +108,29 @@ class IterableAutoRegistrationTests: XCTestCase {
107
108
IterableAPI . userId = " userId1 "
108
109
let token = " zeeToken " . data ( using: . utf8) !
109
110
networkSession. callback = { ( _, _, _) in
110
- // first call back will be called on register
111
- expectation1. fulfill ( )
112
- TestUtils . validate ( request: networkSession. request!, requestType: . post, apiEndPoint: . ITBL_ENDPOINT_API, path: . ITBL_PATH_REGISTER_DEVICE_TOKEN, queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableAutoRegistrationTests . apiKey) ] )
111
+ expectation0. fulfill ( )
112
+ TestUtils . validate ( request: networkSession. request!, requestType: . post, apiEndPoint: . ITBL_ENDPOINT_API, path: . ITBL_PATH_CREATE_USER, queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableAutoRegistrationTests . apiKey) ] )
113
+ let body = networkSession. getRequestBody ( ) as! [ String : Any ]
114
+ TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_USER_ID, andValue: " userId1 " , inDictionary: body)
113
115
networkSession. callback = { ( _, _, _) in
114
- // second call back is for disable when we set new user id
115
- TestUtils . validate ( request: networkSession. request!, requestType: . post, apiEndPoint: . ITBL_ENDPOINT_API, path: . ITBL_PATH_DISABLE_DEVICE, queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableAutoRegistrationTests . apiKey) ] )
116
- let body = networkSession. getRequestBody ( ) as! [ String : Any ]
117
- TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_TOKEN, andValue: ( token as NSData ) . iteHexadecimalString ( ) , inDictionary: body)
118
- TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_USER_ID, andValue: " userId1 " , inDictionary: body)
119
- expectation2. fulfill ( )
116
+ // first call back will be called on register
117
+ expectation1. fulfill ( )
118
+ TestUtils . validate ( request: networkSession. request!, requestType: . post, apiEndPoint: . ITBL_ENDPOINT_API, path: . ITBL_PATH_REGISTER_DEVICE_TOKEN, queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableAutoRegistrationTests . apiKey) ] )
119
+ networkSession. callback = { ( _, _, _) in
120
+ // second call back is for disable when we set new user id
121
+ TestUtils . validate ( request: networkSession. request!, requestType: . post, apiEndPoint: . ITBL_ENDPOINT_API, path: . ITBL_PATH_DISABLE_DEVICE, queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableAutoRegistrationTests . apiKey) ] )
122
+ let body = networkSession. getRequestBody ( ) as! [ String : Any ]
123
+ TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_TOKEN, andValue: ( token as NSData ) . iteHexadecimalString ( ) , inDictionary: body)
124
+ TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_USER_ID, andValue: " userId1 " , inDictionary: body)
125
+ expectation2. fulfill ( )
126
+ }
127
+ IterableAPI . userId = " userId2 "
120
128
}
121
- IterableAPI . userId = " userId2 "
122
129
}
123
130
IterableAPI . register ( token: token)
124
131
125
132
// only wait for small time, supposed to error out
126
- wait ( for: [ expectation1, expectation2, expectation3] , timeout: 1.0 )
133
+ wait ( for: [ expectation0 , expectation1, expectation2, expectation3] , timeout: 1.0 )
127
134
}
128
135
129
136
func testDoNotCallDisableOrEnableWhenAutoPushIsOff( ) {
0 commit comments