@@ -89,41 +89,7 @@ class IterableAutoRegistrationTests: XCTestCase {
8989 wait ( for: [ expectation1] , timeout: testExpectationTimeout)
9090 }
9191
92- func testDoNotCallRegisterIfCreateUserFails( ) {
93- let expectation0 = expectation ( description: " Call create user " )
94- let expectation1 = expectation ( description: " Call registerToken API endpoint " )
95- expectation1. isInverted = true
96-
97- let networkSession = MockNetworkSession ( statusCode: 501 )
98- let config = IterableConfig ( )
99- config. pushIntegrationName = " my-push-integration "
100- let notificationStateProvider = MockNotificationStateProvider ( enabled: true )
101-
102- IterableAPI . initialize ( apiKey: IterableAutoRegistrationTests . apiKey,
103- config: config,
104- networkSession: networkSession,
105- notificationStateProvider: notificationStateProvider)
106- IterableAPI . userId = " userId1 "
107- let token = " zeeToken " . data ( using: . utf8) !
108- networkSession. callback = { ( _, _, _) in
109- expectation0. fulfill ( )
110- 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) ] )
111- let body = networkSession. getRequestBody ( ) as! [ String : Any ]
112- TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_USER_ID, andValue: " userId1 " , inDictionary: body)
113- networkSession. callback = { ( _, _, _) in
114- // first call back will be called on register
115- expectation1. fulfill ( )
116- 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) ] )
117- }
118- }
119- IterableAPI . register ( token: token)
120-
121- // only wait for small time, supposed to error out
122- wait ( for: [ expectation0, expectation1] , timeout: 1.0 )
123- }
124-
12592 func testDoNotCallRegisterForRemoteNotificationsWhenNotificationsAreDisabled( ) {
126- let expectation0 = expectation ( description: " Call create user " )
12793 let expectation1 = expectation ( description: " Call registerToken API endpoint " )
12894 let expectation2 = expectation ( description: " Disable API endpoint called " )
12995 let expectation3 = expectation ( description: " do not call registerForRemoteNotifications " )
@@ -141,31 +107,26 @@ class IterableAutoRegistrationTests: XCTestCase {
141107 IterableAPI . userId = " userId1 "
142108 let token = " zeeToken " . data ( using: . utf8) !
143109 networkSession. callback = { ( _, _, _) in
144- expectation0 . fulfill ( )
145- 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 ) ] )
146- let body = networkSession . getRequestBody ( ) as! [ String : Any ]
147- TestUtils . validateElementPresent ( withName : AnyHashable . ITBL_KEY_USER_ID , andValue : " userId1 " , inDictionary: body )
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 ) ] )
113+ TestUtils . validateMatch ( keyPath : KeyPath ( AnyHashable . ITBL_KEY_PREFER_USER_ID ) , value : true , inDictionary: networkSession . getRequestBody ( ) as! [ String : Any ] , message : " Expected to find preferUserId set to true " )
148114 networkSession. callback = { ( _, _, _) in
149- // second call back will be called on register
150- expectation1. fulfill ( )
151- 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) ] )
152- networkSession. callback = { ( _, _, _) in
153- // third call back is for disable when we set new user id
154- 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) ] )
155- let body = networkSession. getRequestBody ( ) as! [ String : Any ]
156- TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_TOKEN, andValue: ( token as NSData ) . iteHexadecimalString ( ) , inDictionary: body)
157- TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_USER_ID, andValue: " userId1 " , inDictionary: body)
158- expectation2. fulfill ( )
159- }
160- IterableAPI . userId = " userId2 "
115+ // second call back is for disable when we set new user id
116+ 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) ] )
117+ let body = networkSession. getRequestBody ( ) as! [ String : Any ]
118+ TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_TOKEN, andValue: ( token as NSData ) . iteHexadecimalString ( ) , inDictionary: body)
119+ TestUtils . validateElementPresent ( withName: AnyHashable . ITBL_KEY_USER_ID, andValue: " userId1 " , inDictionary: body)
120+ expectation2. fulfill ( )
161121 }
122+ IterableAPI . userId = " userId2 "
162123 }
163124 IterableAPI . register ( token: token)
164125
165126 // only wait for small time, supposed to error out
166- wait ( for: [ expectation0 , expectation1, expectation2, expectation3] , timeout: 1.0 )
127+ wait ( for: [ expectation1, expectation2, expectation3] , timeout: 1.0 )
167128 }
168-
129+
169130 func testDoNotCallDisableOrEnableWhenAutoPushIsOff( ) {
170131 let expectation1 = expectation ( description: " do not call register for remote " )
171132 expectation1. isInverted = true
0 commit comments