1010import org .robolectric .RuntimeEnvironment ;
1111import org .robolectric .shadows .ShadowApplication ;
1212
13+ import java .util .HashMap ;
14+
1315import okhttp3 .mockwebserver .MockWebServer ;
1416
1517import static com .iterable .iterableapi .IterableTestUtils .stubAnyRequestReturningStatusCode ;
@@ -33,12 +35,15 @@ public class IterablePushRegistrationTest extends BaseTest {
3335 private static final String OLD_TOKEN = "oldToken" ;
3436 private static final String GCM_SENDER_ID = "1234567890" ;
3537 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" ;
3640
3741 private MockWebServer server ;
3842 private IterableApi originalApi ;
3943 private IterableApi apiMock ;
4044 private IterablePushRegistration .Util .UtilImpl originalPushRegistrationUtil ;
4145 private IterablePushRegistration .Util .UtilImpl pushRegistrationUtilMock ;
46+ private HashMap <String , String > deviceAttributes = new HashMap <String , String >();
4247
4348 @ Before
4449 public void setUp () throws Exception {
@@ -73,7 +78,8 @@ public void testEnableDevice() throws Exception {
7378 IterablePushRegistrationData data = new IterablePushRegistrationData (IterableTestUtils .userEmail , null , INTEGRATION_NAME , IterablePushRegistrationData .PushRegistrationAction .ENABLE );
7479 new IterablePushRegistration ().execute (data );
7580
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+
7783 verify (apiMock , never ()).disableToken (eq (IterableTestUtils .userEmail ), nullable (String .class ), any (String .class ), nullable (IterableHelper .SuccessHandler .class ), nullable (IterableHelper .FailureHandler .class ));
7884 }
7985
@@ -98,19 +104,21 @@ public void testDisableOldGcmToken() throws Exception {
98104 when (pushRegistrationUtilMock .getFirebaseToken (eq (GCM_SENDER_ID ), eq (IterableConstants .MESSAGING_PLATFORM_GOOGLE ))).thenReturn (OLD_TOKEN );
99105
100106 IterablePushRegistrationData data = new IterablePushRegistrationData (IterableTestUtils .userEmail , null , INTEGRATION_NAME , IterablePushRegistrationData .PushRegistrationAction .ENABLE );
107+ IterableApi .getInstance ().setDeviceAttribute (DEVICE_ATTRIBUTES_KEY , DEVICE_ATTRIBUTES_VALUE );
101108 new IterablePushRegistration ().execute (data );
109+ deviceAttributes .put (DEVICE_ATTRIBUTES_KEY , DEVICE_ATTRIBUTES_VALUE );
102110
103111 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 ) );
105113 verify (apiMock , times (1 )).disableToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), eq (OLD_TOKEN ), successHandlerCaptor .capture (), nullable (IterableHelper .FailureHandler .class ));
106114 successHandlerCaptor .getValue ().onSuccess (new JSONObject ());
107115
108116 reset (apiMock );
109117
110118 new IterablePushRegistration ().execute (data );
111119
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 ) );
113121 verify (apiMock , never ()).disableToken (eq (IterableTestUtils .userEmail ), isNull (String .class ), any (String .class ), nullable (IterableHelper .SuccessHandler .class ), nullable (IterableHelper .FailureHandler .class ));
114122 }
115123
116- }
124+ }
0 commit comments