Skip to content

Commit

Permalink
Fix idsAvailable not firing a 2nd time
Browse files Browse the repository at this point in the history
* Fixed issue where idsAvailable would not fire a 2nd time if registrationId the first time
  • Loading branch information
jkasten2 committed Jun 16, 2018
1 parent 13f12eb commit cc67b06
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Expand Up @@ -1683,7 +1683,7 @@ public void run() {
runIdsAvailable.run();
}

private static void fireIdsAvailableCallback() {
static void fireIdsAvailableCallback() {
if (idsAvailableHandler != null) {
OSUtils.runOnMainUIThread(new Runnable() {
@Override
Expand Down
Expand Up @@ -157,5 +157,7 @@ protected void fireEventsForUpdateFailure(JSONObject jsonFields) {
protected void onSuccessfulSync(JSONObject jsonFields) {
if (jsonFields.has("email"))
OneSignal.fireEmailUpdateSuccess();
if (jsonFields.has("identifier"))
OneSignal.fireIdsAvailableCallback();
}
}
Expand Up @@ -591,13 +591,19 @@ public void testInvalidGoogleProjectNumberWithSuccessfulRegisterResponse() throw
// and is testing the same logic.
ShadowPushRegistratorGCM.fail = true;
OneSignalInitWithBadProjectNum();

threadAndTaskWait();
Robolectric.getForegroundThreadScheduler().runOneTask();
assertEquals(-7, ShadowOneSignalRestClient.lastPost.getInt("notification_types"));

assertEquals(-7, ShadowOneSignalRestClient.lastPost.getInt("notification_types"));
// Test that idsAvailable still fires
assertEquals(ShadowOneSignalRestClient.pushUserId, callBackUseId);
assertNull(getCallBackRegId); // Since GCM registration failed, this should be null

// We now get a push token after the device registers with Onesignal,
// the idsAvailable callback should fire a 2nd time with a registrationId automatically
ShadowPushRegistratorGCM.manualFireRegisterForPush();
threadAndTaskWait();
assertEquals(ShadowPushRegistratorGCM.regId, getCallBackRegId);
}

@Test
Expand Down

0 comments on commit cc67b06

Please sign in to comment.