Search in sources :

Example 11 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageClickActionSendAndRemoveTag.

@Test
public void testInAppMessageClickActionSendAndRemoveTag() 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);
    final JSONObject addTags = new JSONObject() {

        {
            put(IAM_TAG_KEY, IAM_TAG_KEY);
        }
    };
    JSONObject action = new JSONObject() {

        {
            put("id", IAM_CLICK_ID);
            put("tags", new JSONObject() {

                {
                    put("adds", addTags);
                }
            });
        }
    };
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
    threadAndTaskWait();
    // 3. Ensure players call is made
    ShadowOneSignalRestClient.Request iamSendTagRequest = ShadowOneSignalRestClient.requests.get(3);
    assertEquals("players/a2f7f967-e8cc-11e4-bed1-118f05be4511", iamSendTagRequest.url);
    // Requests: Param request + Players Request + Click request + Tag Request
    assertEquals(4, ShadowOneSignalRestClient.requests.size());
    JsonAsserts.equals(addTags, (JSONObject) iamSendTagRequest.payload.get("tags"));
    final JSONArray removeTags = new JSONArray();
    removeTags.put(IAM_TAG_KEY);
    final JSONObject[] lastGetTags = new JSONObject[1];
    JSONObject actionRemove = new JSONObject() {

        {
            put("id", IAM_CLICK_ID);
            put("tags", new JSONObject() {

                {
                    put("removes", removeTags);
                }
            });
        }
    };
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, actionRemove);
    threadAndTaskWait();
    OneSignal.getTags(new OneSignal.OSGetTagsHandler() {

        @Override
        public void tagsAvailable(JSONObject tags) {
            lastGetTags[0] = tags;
        }
    });
    threadAndTaskWait();
    // 3. Ensure no tags
    assertEquals(1, lastGetTags.length);
    assertEquals(0, lastGetTags[0].length());
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) OneSignal(com.onesignal.OneSignal) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 12 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method setMockRegistrationResponseWithMessages.

private void setMockRegistrationResponseWithMessages(ArrayList<OSTestInAppMessageInternal> messages) throws JSONException {
    final JSONArray jsonMessages = new JSONArray();
    for (OSTestInAppMessageInternal message : messages) jsonMessages.put(InAppMessagingHelpers.convertIAMtoJSONObject(message));
    ShadowOneSignalRestClient.setNextSuccessfulRegistrationResponse(new JSONObject() {

        {
            put("id", "df8f05be55ba-b2f7f966-d8cc-11e4-bed1");
            put("success", 1);
            put(OneSignalPackagePrivateHelper.IN_APP_MESSAGES_JSON_KEY, jsonMessages);
        }
    });
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 13 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageClickActionRemoveTag.

@Test
public void testInAppMessageClickActionRemoveTag() throws Exception {
    // 1. Init OneSignal
    OneSignalInit();
    OneSignal.sendTags(new JSONObject("{" + IAM_TAG_KEY + ": \"value1\"}"));
    threadAndTaskWait();
    // 2. Create an IAM
    final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.NOT_EXISTS.toString(), null);
    final JSONArray removeTags = new JSONArray();
    removeTags.put(IAM_TAG_KEY);
    JSONObject actionRemove = new JSONObject() {

        {
            put("id", IAM_CLICK_ID);
            put("tags", new JSONObject() {

                {
                    put("removes", removeTags);
                }
            });
        }
    };
    JSONObject objectExpected = new JSONObject() {

        {
            put(IAM_TAG_KEY, "");
        }
    };
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, actionRemove);
    threadAndTaskWait();
    // 3. Ensure players call is made
    ShadowOneSignalRestClient.Request iamSendTagRequest = ShadowOneSignalRestClient.requests.get(3);
    assertEquals("players/a2f7f967-e8cc-11e4-bed1-118f05be4511", iamSendTagRequest.url);
    // Requests: Param request + Players Request + Click request + Tag Request
    assertEquals(4, ShadowOneSignalRestClient.requests.size());
    JsonAsserts.equals(objectExpected, (JSONObject) iamSendTagRequest.payload.get("tags"));
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Test(org.junit.Test)

Example 14 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageClickActionOutcomeV2.

@Test
public void testInAppMessageClickActionOutcomeV2() 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);
    // 1. Init OneSignal
    OneSignalInit();
    threadAndTaskWait();
    // Enable influence outcomes
    trackerFactory.saveInfluenceParams(new OneSignalPackagePrivateHelper.RemoteOutcomeParams());
    // 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);
        }
    };
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
    // 3. Ensure outcome is sent
    assertMeasureOnV2AtIndex(3, "outcome_name", new JSONArray().put(message.getMessageId()), new JSONArray(), null, null);
}
Also used : MockOSLog(com.onesignal.MockOSLog) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) OSTrackerFactory(com.onesignal.influence.data.OSTrackerFactory) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) MockSessionManager(com.onesignal.MockSessionManager) MockOSSharedPreferences(com.onesignal.MockOSSharedPreferences) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) Test(org.junit.Test)

Example 15 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageClickActionSendTag.

@Test
public void testInAppMessageClickActionSendTag() 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);
    final JSONObject addTags = new JSONObject() {

        {
            put(IAM_TAG_KEY, IAM_TAG_KEY);
        }
    };
    JSONObject action = new JSONObject() {

        {
            put("id", IAM_CLICK_ID);
            put("tags", new JSONObject() {

                {
                    put("adds", addTags);
                }
            });
        }
    };
    OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
    threadAndTaskWait();
    // 3. Ensure players call is made
    ShadowOneSignalRestClient.Request iamSendTagRequest = ShadowOneSignalRestClient.requests.get(3);
    assertEquals("players/a2f7f967-e8cc-11e4-bed1-118f05be4511", iamSendTagRequest.url);
    // Requests: Param request + Players Request + Click request + Tag Request
    assertEquals(4, ShadowOneSignalRestClient.requests.size());
    JsonAsserts.equals(addTags, (JSONObject) iamSendTagRequest.payload.get("tags"));
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject) Test(org.junit.Test)

Aggregations

OSTestInAppMessageInternal (com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal)50 Test (org.junit.Test)43 JSONObject (org.json.JSONObject)19 ShadowOneSignalRestClient (com.onesignal.ShadowOneSignalRestClient)15 JSONArray (org.json.JSONArray)14 OneSignalPackagePrivateHelper (com.onesignal.OneSignalPackagePrivateHelper)8 ArrayList (java.util.ArrayList)5 SuppressLint (android.annotation.SuppressLint)4 OSTestTrigger (com.onesignal.OneSignalPackagePrivateHelper.OSTestTrigger)4 Duration (org.awaitility.Duration)4 MockOSLog (com.onesignal.MockOSLog)3 MockOSSharedPreferences (com.onesignal.MockOSSharedPreferences)3 MockSessionManager (com.onesignal.MockSessionManager)3 OneSignal (com.onesignal.OneSignal)3 OSTrackerFactory (com.onesignal.influence.data.OSTrackerFactory)3 JSONException (org.json.JSONException)3 Cursor (android.database.Cursor)2 OSInAppMessageAction (com.onesignal.OSInAppMessageAction)2 HashSet (java.util.HashSet)2 ThrowingRunnable (org.awaitility.core.ThrowingRunnable)2