@@ -89,41 +89,7 @@ class IterableAutoRegistrationTests: XCTestCase {
89
89
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
90
90
}
91
91
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
-
125
92
func testDoNotCallRegisterForRemoteNotificationsWhenNotificationsAreDisabled( ) {
126
- let expectation0 = expectation ( description: " Call create user " )
127
93
let expectation1 = expectation ( description: " Call registerToken API endpoint " )
128
94
let expectation2 = expectation ( description: " Disable API endpoint called " )
129
95
let expectation3 = expectation ( description: " do not call registerForRemoteNotifications " )
@@ -141,31 +107,26 @@ class IterableAutoRegistrationTests: XCTestCase {
141
107
IterableAPI . userId = " userId1 "
142
108
let token = " zeeToken " . data ( using: . utf8) !
143
109
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 " )
148
114
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 ( )
161
121
}
122
+ IterableAPI . userId = " userId2 "
162
123
}
163
124
IterableAPI . register ( token: token)
164
125
165
126
// 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 )
167
128
}
168
-
129
+
169
130
func testDoNotCallDisableOrEnableWhenAutoPushIsOff( ) {
170
131
let expectation1 = expectation ( description: " do not call register for remote " )
171
132
expectation1. isInverted = true
0 commit comments