10
10
import org .robolectric .RuntimeEnvironment ;
11
11
import org .robolectric .shadows .ShadowApplication ;
12
12
13
+ import java .util .HashMap ;
14
+
13
15
import okhttp3 .mockwebserver .MockWebServer ;
14
16
15
17
import static com .iterable .iterableapi .IterableTestUtils .stubAnyRequestReturningStatusCode ;
@@ -33,12 +35,15 @@ public class IterablePushRegistrationTest extends BaseTest {
33
35
private static final String OLD_TOKEN = "oldToken" ;
34
36
private static final String GCM_SENDER_ID = "1234567890" ;
35
37
public static final String INTEGRATION_NAME = "integrationName" ;
38
+ public static final String DEVICE_ATTRIBUTES_KEY = "SDK" ;
39
+ public static final String DEVICE_ATTRIBUTES_VALUE = "ReactNative 2.3.4" ;
36
40
37
41
private MockWebServer server ;
38
42
private IterableApi originalApi ;
39
43
private IterableApi apiMock ;
40
44
private IterablePushRegistration .Util .UtilImpl originalPushRegistrationUtil ;
41
45
private IterablePushRegistration .Util .UtilImpl pushRegistrationUtilMock ;
46
+ private HashMap <String , String > deviceAttributes = new HashMap <String , String >();
42
47
43
48
@ Before
44
49
public void setUp () throws Exception {
@@ -73,7 +78,8 @@ public void testEnableDevice() throws Exception {
73
78
IterablePushRegistrationData data = new IterablePushRegistrationData (IterableTestUtils .userEmail , null , INTEGRATION_NAME , IterablePushRegistrationData .PushRegistrationAction .ENABLE );
74
79
new IterablePushRegistration ().execute (data );
75
80
76
- verify (apiMock , timeout (100 )).registerDeviceToken (eq (IterableTestUtils .userEmail ), nullable (String .class ), eq (INTEGRATION_NAME ), eq (TEST_TOKEN ));
81
+ verify (apiMock , timeout (100 )).registerDeviceToken (eq (IterableTestUtils .userEmail ), nullable (String .class ), eq (INTEGRATION_NAME ), eq (TEST_TOKEN ), eq (deviceAttributes ));
82
+
77
83
verify (apiMock , never ()).disableToken (eq (IterableTestUtils .userEmail ), nullable (String .class ), any (String .class ), nullable (IterableHelper .SuccessHandler .class ), nullable (IterableHelper .FailureHandler .class ));
78
84
}
79
85
@@ -98,19 +104,21 @@ public void testDisableOldGcmToken() throws Exception {
98
104
when (pushRegistrationUtilMock .getFirebaseToken (eq (GCM_SENDER_ID ), eq (IterableConstants .MESSAGING_PLATFORM_GOOGLE ))).thenReturn (OLD_TOKEN );
99
105
100
106
IterablePushRegistrationData data = new IterablePushRegistrationData (IterableTestUtils .userEmail , null , INTEGRATION_NAME , IterablePushRegistrationData .PushRegistrationAction .ENABLE );
107
+ IterableApi .getInstance ().setDeviceAttribute (DEVICE_ATTRIBUTES_KEY , DEVICE_ATTRIBUTES_VALUE );
101
108
new IterablePushRegistration ().execute (data );
109
+ deviceAttributes .put (DEVICE_ATTRIBUTES_KEY , DEVICE_ATTRIBUTES_VALUE );
102
110
103
111
ArgumentCaptor <IterableHelper .SuccessHandler > successHandlerCaptor = ArgumentCaptor .forClass (IterableHelper .SuccessHandler .class );
104
- verify (apiMock ).registerDeviceToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), eq (INTEGRATION_NAME ), eq (NEW_TOKEN ));
112
+ verify (apiMock ).registerDeviceToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), eq (INTEGRATION_NAME ), eq (NEW_TOKEN ), eq ( deviceAttributes ) );
105
113
verify (apiMock , times (1 )).disableToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), eq (OLD_TOKEN ), successHandlerCaptor .capture (), nullable (IterableHelper .FailureHandler .class ));
106
114
successHandlerCaptor .getValue ().onSuccess (new JSONObject ());
107
115
108
116
reset (apiMock );
109
117
110
118
new IterablePushRegistration ().execute (data );
111
119
112
- verify (apiMock ).registerDeviceToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), eq (INTEGRATION_NAME ), eq (NEW_TOKEN ));
120
+ verify (apiMock ).registerDeviceToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), eq (INTEGRATION_NAME ), eq (NEW_TOKEN ), eq ( deviceAttributes ) );
113
121
verify (apiMock , never ()).disableToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), any (String .class ), nullable (IterableHelper .SuccessHandler .class ), nullable (IterableHelper .FailureHandler .class ));
114
122
}
115
123
116
- }
124
+ }
0 commit comments