Skip to content

Commit 15fab87

Browse files
committed
Updated tests for removed idsAvailable
1 parent 37f0fc2 commit 15fab87

File tree

1 file changed

+9
-74
lines changed

1 file changed

+9
-74
lines changed

OneSignalSDK/unittest/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 9 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,6 @@ public class MainOneSignalClassRunner {
199199
private MockSessionManager sessionManager;
200200
private MockOneSignalDBHelper dbHelper;
201201

202-
private static String lastUserId, lastRegistrationId;
203-
private static void getIdsAvailableHandler() {
204-
OneSignal.idsAvailable((userId, registrationId) -> {
205-
lastUserId = userId;
206-
lastRegistrationId = registrationId;
207-
});
208-
}
209-
210202
private static String lastNotificationOpenedBody;
211203
private static OneSignal.OSNotificationOpenedHandler getNotificationOpenedHandler() {
212204
return openedResult -> {
@@ -227,8 +219,6 @@ private static void getGetTagsHandler() {
227219
}
228220

229221
private static void cleanUp() throws Exception {
230-
lastUserId = lastRegistrationId = null;
231-
232222
lastNotificationOpenedBody = null;
233223
lastGetTags = null;
234224
lastExternalUserIdResponse = null;
@@ -908,8 +898,7 @@ public void testPutStillCalledOnChanges() throws Exception {
908898
threadAndTaskWait();
909899

910900
assertEquals(4, ShadowOneSignalRestClient.networkCallCount);
911-
getIdsAvailableHandler();
912-
assertEquals("players/" + lastUserId, ShadowOneSignalRestClient.lastUrl);
901+
assertEquals("players/" + OneSignal.getDeviceState().getUserId(), ShadowOneSignalRestClient.lastUrl);
913902
assertEquals("{\"carrier\":\"test2\",\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"}", ShadowOneSignalRestClient.lastPost.toString());
914903
}
915904

@@ -947,8 +936,7 @@ public void testOnSessionEvenIfQuickAppRestart() throws Exception {
947936

948937
// 4. Ensure we made 4 network calls. (2 to android_params and 1 create player call)
949938
assertEquals(5, ShadowOneSignalRestClient.networkCallCount);
950-
getIdsAvailableHandler();
951-
assertEquals("players/" + lastUserId + "/on_session", ShadowOneSignalRestClient.lastUrl);
939+
assertEquals("players/" + OneSignal.getDeviceState().getUserId() + "/on_session", ShadowOneSignalRestClient.lastUrl);
952940
assertEquals(REST_METHOD.POST, ShadowOneSignalRestClient.requests.get(4).method);
953941
}
954942

@@ -1244,7 +1232,6 @@ public void testUnsubscribeStatusShouldBeSetIfFCMErrored() throws Exception {
12441232

12451233
@Test
12461234
public void testInvalidGoogleProjectNumberWithSuccessfulRegisterResponse() throws Exception {
1247-
getIdsAvailableHandler();
12481235
// A more real test would be "missing support library" but bad project number is an easier setup
12491236
// and is testing the same logic.
12501237
ShadowPushRegistratorFCM.fail = true;
@@ -1255,14 +1242,14 @@ public void testInvalidGoogleProjectNumberWithSuccessfulRegisterResponse() throw
12551242

12561243
assertEquals(-7, ShadowOneSignalRestClient.lastPost.getInt("notification_types"));
12571244
// Test that idsAvailable still fires
1258-
assertEquals(ShadowOneSignalRestClient.pushUserId, lastUserId);
1259-
assertNull(lastRegistrationId); // Since FCM registration failed, this should be null
1245+
assertEquals(ShadowOneSignalRestClient.pushUserId, OneSignal.getDeviceState().getUserId());
1246+
assertNull(OneSignal.getDeviceState().getPushToken()); // Since FCM registration failed, this should be null
12601247

12611248
// We now get a push token after the device registers with Onesignal,
12621249
// the idsAvailable callback should fire a 2nd time with a registrationId automatically
12631250
ShadowPushRegistratorFCM.manualFireRegisterForPush();
12641251
threadAndTaskWait();
1265-
assertEquals(ShadowPushRegistratorFCM.regId, lastRegistrationId);
1252+
assertEquals(ShadowPushRegistratorFCM.regId, OneSignal.getDeviceState().getPushToken());
12661253
}
12671254

12681255
@Test
@@ -1284,31 +1271,14 @@ public void testGMSErrorsAfterSuccessfulSubscribeDoNotUnsubscribeTheDevice() thr
12841271
public void testInvalidGoogleProjectNumberWithFailedRegisterResponse() throws Exception {
12851272
// Ensures lower number notification_types do not over right higher numbered ones.
12861273
ShadowPushRegistratorFCM.fail = true;
1287-
getIdsAvailableHandler();
12881274
// OneSignalInitWithBadProjectNum();
12891275
OneSignalInit();
12901276
threadAndTaskWait();
12911277
Robolectric.getForegroundThreadScheduler().runOneTask();
12921278
assertEquals(-7, ShadowOneSignalRestClient.lastPost.getInt("notification_types"));
12931279

12941280
// Test that idsAvailable still fires
1295-
assertEquals(ShadowOneSignalRestClient.pushUserId, lastUserId);
1296-
}
1297-
1298-
@Test
1299-
public void testUnsubcribedShouldMakeRegIdNullToIdsAvailable() throws Exception {
1300-
getIdsAvailableHandler();
1301-
OneSignalInit();
1302-
threadAndTaskWait();
1303-
assertEquals(ShadowPushRegistratorFCM.regId, ShadowOneSignalRestClient.lastPost.getString("identifier"));
1304-
1305-
Robolectric.getForegroundThreadScheduler().runOneTask();
1306-
assertEquals(ShadowPushRegistratorFCM.regId, lastRegistrationId);
1307-
1308-
OneSignal.disablePush(false);
1309-
getIdsAvailableHandler();
1310-
threadAndTaskWait();
1311-
assertNull(lastRegistrationId);
1281+
assertEquals(ShadowOneSignalRestClient.pushUserId, OneSignal.getDeviceState().getUserId());
13121282
}
13131283

13141284
@Test
@@ -1414,25 +1384,6 @@ public void shouldAllowMultipleSetSubscription() throws Exception {
14141384
assertNull(ShadowOneSignalRestClient.lastPost);
14151385
}
14161386

1417-
private static boolean userIdWasNull = false;
1418-
@Test
1419-
public void shouldNotFireIdsAvailableWithoutUserId() throws Exception {
1420-
ShadowOneSignalRestClient.failNext = true;
1421-
ShadowPushRegistratorFCM.fail = true;
1422-
1423-
OneSignal.idsAvailable(new OneSignal.OSIdsAvailableHandler() {
1424-
@Override
1425-
public void idsAvailable(String userId, String registrationId) {
1426-
if (userId == null)
1427-
userIdWasNull = true;
1428-
}
1429-
});
1430-
1431-
OneSignalInit();
1432-
assertFalse(userIdWasNull);
1433-
threadAndTaskWait();
1434-
}
1435-
14361387
@Test
14371388
public void testFCMTimeOutThenSuccessesLater() throws Exception {
14381389
// Init with a bad connection to Google.
@@ -1939,7 +1890,6 @@ public void shouldSendTagsWithRequestBatching() throws Exception {
19391890
public void shouldNotAttemptToSendTagsBeforeGettingPlayerId() throws Exception {
19401891
ShadowPushRegistratorFCM.skipComplete = true;
19411892
OneSignalInit();
1942-
getIdsAvailableHandler();
19431893
threadAndTaskWait();
19441894

19451895
assertEquals(1, ShadowOneSignalRestClient.networkCallCount);
@@ -1954,7 +1904,7 @@ public void shouldNotAttemptToSendTagsBeforeGettingPlayerId() throws Exception {
19541904
threadAndTaskWait();
19551905

19561906
assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
1957-
assertNotNull(lastUserId);
1907+
assertNotNull(OneSignal.getDeviceState().getUserId());
19581908
}
19591909

19601910
private static class TestChangeTagsUpdateHandler implements ChangeTagsUpdateHandler {
@@ -2224,24 +2174,10 @@ public void tagsAvailable(JSONObject tags) {
22242174
});
22252175
threadAndTaskWait();
22262176

2227-
final AtomicBoolean callbackFired = new AtomicBoolean(false);
2228-
OneSignal.OSIdsAvailableHandler idsAvailableHandler = new OneSignal.OSIdsAvailableHandler() {
2229-
@Override
2230-
public void idsAvailable(String userId, String registrationId) {
2231-
//Assert the userId being returned
2232-
callbackFired.set(true);
2233-
assertEquals(ShadowOneSignalRestClient.pushUserId, userId);
2234-
}
2235-
};
2236-
2237-
OneSignal.idsAvailable(idsAvailableHandler);
2238-
System.gc(); //make sure the IdsAvailableHandler is retained...
2239-
2240-
22412177
// ----- END QUEUE ------
22422178

2243-
//there should be 503 pending operations in the queue
2244-
assertEquals(503, OneSignal_taskQueueWaitingForInit().size());
2179+
// There should be 502 pending operations in the queue
2180+
assertEquals(502, OneSignal_taskQueueWaitingForInit().size());
22452181

22462182
OneSignalInit(); //starts the pending tasks executor
22472183

@@ -2283,7 +2219,6 @@ public void tagsAvailable(JSONObject tags) {
22832219

22842220
//Assert that the queued up operations ran in correct order
22852221
// and that the correct user state was POSTed and synced
2286-
assertTrue(callbackFired.get()); //check if the callback got fired
22872222

22882223
//assert the hashed email which should be test1@test.com, NOT test@test.com
22892224
assertEquals("94fba03762323f286d7c3ca9e001c541", ShadowOneSignalRestClient.lastPost.getString("em_m"));

0 commit comments

Comments
 (0)