Search in sources :

Example 1 with OSInAppMessageAction

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

the class InAppMessagingUnitTests method testOnMessageActionOccurredOnMessage.

@Test
public void testOnMessageActionOccurredOnMessage() throws Exception {
    OneSignal.setInAppMessageClickHandler(new OneSignal.OSInAppMessageClickHandler() {

        @Override
        public void inAppMessageClicked(OSInAppMessageAction result) {
            lastAction = result;
            // Ensure we are on the main thread when running the callback, since the app developer
            // will most likely need to update UI.
            assertMainThread();
        }
    });
    threadAndTaskWait();
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, new JSONObject() {

        {
            put("id", "button_id_123");
            put("name", "my_click_name");
        }
    });
    // Ensure we make REST call to OneSignal to report click.
    ShadowOneSignalRestClient.Request iamClickRequest = ShadowOneSignalRestClient.requests.get(2);
    assertEquals("in_app_messages/" + message.getMessageId() + "/click", iamClickRequest.url);
    assertEquals(InAppMessagingHelpers.ONESIGNAL_APP_ID, iamClickRequest.payload.get("app_id"));
    assertEquals(1, iamClickRequest.payload.get("device_type"));
    assertEquals(message.variants.get("android").get("en"), iamClickRequest.payload.get("variant_id"));
    assertEquals(ShadowOneSignalRestClient.pushUserId, iamClickRequest.payload.get("player_id"));
    assertEquals(true, iamClickRequest.payload.get("first_click"));
    assertEquals("button_id_123", iamClickRequest.payload.get("click_id"));
    // Ensure we fire public callback that In-App was clicked.
    assertEquals(lastAction.getClickName(), "my_click_name");
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OneSignal(com.onesignal.OneSignal) JSONObject(org.json.JSONObject) OSInAppMessageAction(com.onesignal.OSInAppMessageAction) Test(org.junit.Test)

Example 2 with OSInAppMessageAction

use of com.onesignal.OSInAppMessageAction 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");
}
Also used : MockOSLog(com.onesignal.MockOSLog) OneSignal(com.onesignal.OneSignal) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONObject(org.json.JSONObject) MockSessionManager(com.onesignal.MockSessionManager) OSInAppMessageAction(com.onesignal.OSInAppMessageAction) Test(org.junit.Test)

Example 3 with OSInAppMessageAction

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

the class InAppMessageIntegrationTests method testOnIAMActionSendsOutcome_afterDismiss_usingOutcomesV2.

@Test
public void testOnIAMActionSendsOutcome_afterDismiss_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();
        }
    });
    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");
    OneSignalPackagePrivateHelper.dismissCurrentMessage();
    OneSignal.sendOutcome("test1");
    try {
        // Ensure outcome is sent but with INDIRECT influence from IAM
        assertMeasureOnV2AtIndex(5, "test1", null, null, new JSONArray().put(message.getMessageId()), new JSONArray());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : MockOSLog(com.onesignal.MockOSLog) OneSignal(com.onesignal.OneSignal) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONObject(org.json.JSONObject) MockSessionManager(com.onesignal.MockSessionManager) OSInAppMessageAction(com.onesignal.OSInAppMessageAction) Test(org.junit.Test)

Aggregations

OSInAppMessageAction (com.onesignal.OSInAppMessageAction)3 OneSignal (com.onesignal.OneSignal)3 JSONObject (org.json.JSONObject)3 Test (org.junit.Test)3 MockOSLog (com.onesignal.MockOSLog)2 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)2 MockSessionManager (com.onesignal.MockSessionManager)2 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)2 OSTestInAppMessageInternal (com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal)2 OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 ShadowOneSignalRestClient (com.onesignal.ShadowOneSignalRestClient)1