use of com.onesignal.OSEmailSubscriptionStateChanges 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());
}
use of com.onesignal.OSEmailSubscriptionStateChanges 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());
}
use of com.onesignal.OSEmailSubscriptionStateChanges 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);
}
use of com.onesignal.OSEmailSubscriptionStateChanges 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());
}
Aggregations