Search in sources :

Example 1 with OSEmailSubscriptionObserver

use of com.onesignal.OSEmailSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldAddEmailSubscriptionObserverIfConsentNotGranted.

@Test
public void shouldAddEmailSubscriptionObserverIfConsentNotGranted() throws Exception {
    ShadowOneSignalRestClient.setRemoteParamsRequirePrivacyConsent(true);
    OneSignalInit();
    OSEmailSubscriptionObserver subscriptionObserver = new OSEmailSubscriptionObserver() {

        @Override
        public void onOSEmailSubscriptionChanged(OSEmailSubscriptionStateChanges stateChanges) {
            lastEmailSubscriptionStateChanges = stateChanges;
        }
    };
    OneSignal.addEmailSubscriptionObserver(subscriptionObserver);
    OneSignal.provideUserConsent(true);
    threadAndTaskWait();
    String email = "josh@onesignal.com";
    OneSignal.setEmail(email);
    threadAndTaskWait();
    // make sure the email subscription observer was fired
    assertEquals(email, lastEmailSubscriptionStateChanges.getFrom().getEmailAddress());
    assertNull(lastEmailSubscriptionStateChanges.getFrom().getEmailUserId());
    assertEquals("b007f967-98cc-11e4-bed1-118f05be4522", lastEmailSubscriptionStateChanges.getTo().getEmailUserId());
    assertEquals(email, lastEmailSubscriptionStateChanges.getTo().getEmailAddress());
    assertTrue(lastEmailSubscriptionStateChanges.getTo().isSubscribed());
}
Also used : OSEmailSubscriptionObserver(com.onesignal.OSEmailSubscriptionObserver) OSEmailSubscriptionStateChanges(com.onesignal.OSEmailSubscriptionStateChanges) Test(org.junit.Test)

Example 2 with OSEmailSubscriptionObserver

use of com.onesignal.OSEmailSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldFireEmailSubscriptionObserverOnSetEmail.

@Test
public void shouldFireEmailSubscriptionObserverOnSetEmail() throws Exception {
    OneSignalInit();
    OSEmailSubscriptionObserver subscriptionObserver = new OSEmailSubscriptionObserver() {

        @Override
        public void onOSEmailSubscriptionChanged(OSEmailSubscriptionStateChanges stateChanges) {
            lastEmailSubscriptionStateChanges = stateChanges;
        }
    };
    OneSignal.addEmailSubscriptionObserver(subscriptionObserver);
    OneSignal.setEmail("josh@onesignal.com");
    threadAndTaskWait();
    assertNull(lastEmailSubscriptionStateChanges.getFrom().getEmailUserId());
    assertEquals("b007f967-98cc-11e4-bed1-118f05be4522", lastEmailSubscriptionStateChanges.getTo().getEmailUserId());
    assertEquals("josh@onesignal.com", lastEmailSubscriptionStateChanges.getTo().getEmailAddress());
    assertTrue(lastEmailSubscriptionStateChanges.getTo().isSubscribed());
}
Also used : OSEmailSubscriptionObserver(com.onesignal.OSEmailSubscriptionObserver) OSEmailSubscriptionStateChanges(com.onesignal.OSEmailSubscriptionStateChanges) Test(org.junit.Test)

Example 3 with OSEmailSubscriptionObserver

use of com.onesignal.OSEmailSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldNotFireEmailSubscriptionObserverOnAppRestart.

@Test
public void shouldNotFireEmailSubscriptionObserverOnAppRestart() throws Exception {
    OneSignalInit();
    OneSignal.setEmail("josh@onesignal.com");
    threadAndTaskWait();
    OSEmailSubscriptionObserver subscriptionObserver = new OSEmailSubscriptionObserver() {

        @Override
        public void onOSEmailSubscriptionChanged(OSEmailSubscriptionStateChanges stateChanges) {
            lastEmailSubscriptionStateChanges = stateChanges;
        }
    };
    OneSignal.addEmailSubscriptionObserver(subscriptionObserver);
    threadAndTaskWait();
    assertNotNull(lastEmailSubscriptionStateChanges);
    restartAppAndElapseTimeToNextSession(time);
    OneSignalInit();
    threadAndTaskWait();
    lastEmailSubscriptionStateChanges = null;
    OneSignal.addEmailSubscriptionObserver(subscriptionObserver);
    threadAndTaskWait();
    assertNull(lastEmailSubscriptionStateChanges);
}
Also used : OSEmailSubscriptionObserver(com.onesignal.OSEmailSubscriptionObserver) OSEmailSubscriptionStateChanges(com.onesignal.OSEmailSubscriptionStateChanges) Test(org.junit.Test)

Example 4 with OSEmailSubscriptionObserver

use of com.onesignal.OSEmailSubscriptionObserver in project OneSignal-Android-SDK by OneSignal.

the class MainOneSignalClassRunner method shouldFireEmailSubscriptionObserverOnLogoutEmail.

@Test
public void shouldFireEmailSubscriptionObserverOnLogoutEmail() throws Exception {
    OneSignalInit();
    OSEmailSubscriptionObserver subscriptionObserver = new OSEmailSubscriptionObserver() {

        @Override
        public void onOSEmailSubscriptionChanged(OSEmailSubscriptionStateChanges stateChanges) {
            lastEmailSubscriptionStateChanges = stateChanges;
        }
    };
    OneSignal.addEmailSubscriptionObserver(subscriptionObserver);
    OneSignal.setEmail("josh@onesignal.com");
    threadAndTaskWait();
    OneSignal.logoutEmail();
    threadAndTaskWait();
    assertEquals("b007f967-98cc-11e4-bed1-118f05be4522", lastEmailSubscriptionStateChanges.getFrom().getEmailUserId());
    assertEquals("josh@onesignal.com", lastEmailSubscriptionStateChanges.getFrom().getEmailAddress());
    assertFalse(lastEmailSubscriptionStateChanges.getTo().isSubscribed());
    assertNull(lastEmailSubscriptionStateChanges.getTo().getEmailUserId());
    assertNull(lastEmailSubscriptionStateChanges.getTo().getEmailAddress());
}
Also used : OSEmailSubscriptionObserver(com.onesignal.OSEmailSubscriptionObserver) OSEmailSubscriptionStateChanges(com.onesignal.OSEmailSubscriptionStateChanges) Test(org.junit.Test)

Aggregations

OSEmailSubscriptionObserver (com.onesignal.OSEmailSubscriptionObserver)4 OSEmailSubscriptionStateChanges (com.onesignal.OSEmailSubscriptionStateChanges)4 Test (org.junit.Test)4