@@ -90,6 +90,7 @@ class IterableAutoRegistrationTests: XCTestCase {
9090 }
9191
9292 func testDoNotCallRegisterForRemoteNotificationsWhenNotificationsAreDisabled( ) {
93+ let expectation0 = expectation ( description: " Call create user " )
9394 let expectation1 = expectation ( description: " Call registerToken API endpoint " )
9495 let expectation2 = expectation ( description: " Disable API endpoint called " )
9596 let expectation3 = expectation ( description: " do not call registerForRemoteNotifications " )
@@ -107,23 +108,29 @@ class IterableAutoRegistrationTests: XCTestCase {
107108 IterableAPI . userId = " userId1 "
108109 let token = " zeeToken " . data ( using: . utf8) !
109110 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)
113115 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 "
120128 }
121- IterableAPI . userId = " userId2 "
122129 }
123130 IterableAPI . register ( token: token)
124131
125132 // 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 )
127134 }
128135
129136 func testDoNotCallDisableOrEnableWhenAutoPushIsOff( ) {
0 commit comments