use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageOnlyReceivesOneClick_onColdRestart.
@Test
public void testInAppMessageOnlyReceivesOneClick_onColdRestart() throws Exception {
// 1. Init OneSignal
OneSignalInit();
threadAndTaskWait();
// 2. Create an IAM
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
// 2. Count IAM as clicked
JSONObject action = new JSONObject() {
{
put("id", IAM_CLICK_ID);
}
};
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// 3. Cold restart app and re-init OneSignal
fastColdRestartApp();
OneSignalInit();
threadAndTaskWait();
// 4. Click on IAM again
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// Since the app restart and another message shown callback only 1 more request should exist
// So verify 4 requests exist (3 old and 1 new)
ShadowOneSignalRestClient.Request mostRecentRequest = ShadowOneSignalRestClient.requests.get(3);
assertEquals(4, ShadowOneSignalRestClient.requests.size());
// Now verify the most recent request was not a click request
boolean isIamClickUrl = mostRecentRequest.url.equals("in_app_messages/" + message.getMessageId() + "/click");
assertFalse(isIamClickUrl);
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageClickActionDisabledOutcomes.
@Test
public void testInAppMessageClickActionDisabledOutcomes() throws Exception {
// 1. Init OneSignal
OneSignalInit();
threadAndTaskWait();
// Disable influence outcomes
trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams(false, false, false));
// 2. Create an IAM
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
final JSONArray outcomes = new JSONArray();
outcomes.put(new JSONObject() {
{
put("name", IAM_OUTCOME_NAME);
}
});
JSONObject action = new JSONObject() {
{
put("id", IAM_CLICK_ID);
put("outcomes", outcomes);
}
};
// 3. Send IAM action
// With unattributed outcomes disable no outcome request should happen
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// Requests: Param request + Players Request + Click request
assertEquals(3, ShadowOneSignalRestClient.requests.size());
assertEquals("in_app_messages/" + message.getMessageId() + "/click", ShadowOneSignalRestClient.requests.get(2).url);
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageIdTracked.
@Test
public void testInAppMessageIdTracked() throws Exception {
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// For mocking behaviour
OneSignal_setTrackerFactory(trackerFactory);
OneSignal_setSessionManager(sessionManager);
// Init OneSignal IAM with redisplay
OneSignalInit();
threadAndTaskWait();
// Check no influence id saved
JSONArray lastReceivedIds = trackerFactory.getIAMChannelTracker().getLastReceivedIds();
assertEquals(0, lastReceivedIds.length());
// Add trigger to make IAM display
OneSignal.addTrigger("test_1", 2);
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Check influence id saved
lastReceivedIds = trackerFactory.getIAMChannelTracker().getLastReceivedIds();
assertEquals(1, lastReceivedIds.length());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testOnIAMActionSendsOutcome_usingOutcomesV2.
@Test
public void testOnIAMActionSendsOutcome_usingOutcomesV2() throws Exception {
// Enable IAM v2
preferences = new MockOSSharedPreferences();
preferences.saveBool(preferences.getPreferencesName(), preferences.getOutcomesV2KeyName(), true);
trackerFactory = new OSTrackerFactory(preferences, new MockOSLog(), time);
sessionManager = new MockSessionManager(OneSignal_getSessionListener(), trackerFactory, new MockOSLog());
OneSignal_setSharedPreferences(preferences);
OneSignal_setTrackerFactory(trackerFactory);
OneSignal_setSessionManager(sessionManager);
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// 1. Init OneSignal
OneSignalInit();
threadAndTaskWait();
// Enable influence outcomes
trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
final OSInAppMessageAction[] lastAction = new OSInAppMessageAction[1];
OneSignal.setInAppMessageClickHandler(new OneSignal.OSInAppMessageClickHandler() {
@Override
public void inAppMessageClicked(OSInAppMessageAction result) {
lastAction[0] = result;
// Ensure we are on the main thread when running the callback, since the app developer
// will most likely need to update UI.
assertMainThread();
OneSignal.sendOutcome("test");
try {
// Ensure outcome is sent
assertMeasureOnV2AtIndex(4, "test", new JSONArray().put(message.getMessageId()), new JSONArray(), null, null);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
threadAndTaskWait();
// Add trigger to make IAM display
OneSignal.addTrigger("test_1", 2);
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, new JSONObject() {
{
put("id", "button_id_123");
put("name", "my_click_name");
}
});
// Ensure we fire public callback that In-App was clicked.
assertEquals(lastAction[0].getClickName(), "my_click_name");
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageOnlyReceivesClickIdOnce.
@Test
public void testInAppMessageOnlyReceivesClickIdOnce() throws Exception {
// 1. Init OneSignal
OneSignalInit();
threadAndTaskWait();
// 2. Create an IAM
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
// 2. Count IAM as clicked
JSONObject action = new JSONObject() {
{
put("id", IAM_CLICK_ID);
}
};
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// 3. Ensure click is sent
ShadowOneSignalRestClient.Request iamImpressionRequest = ShadowOneSignalRestClient.requests.get(2);
assertEquals("in_app_messages/" + message.getMessageId() + "/click", iamImpressionRequest.url);
assertEquals(3, ShadowOneSignalRestClient.requests.size());
// 4. Call IAM clicked again, ensure a 2nd network call is not made.
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
assertEquals(3, ShadowOneSignalRestClient.requests.size());
// Verify clickId was persisted locally
Set<String> testClickedMessages = TestOneSignalPrefs.getStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_CLICKED_CLICK_IDS_IAMS, null);
assertEquals(1, testClickedMessages.size());
}
Aggregations