Search in sources :

Example 1 with OSTestInAppMessageInternal

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

the class InAppMessagingHelpers method buildTestMessageWithEndTime.

public static OSTestInAppMessageInternal buildTestMessageWithEndTime(final OSTriggerKind kind, final String key, final String operator, final Object value, final boolean pastEndTime) throws JSONException {
    JSONArray triggerJson = basicTrigger(kind, key, operator, value);
    JSONObject json = basicIAMJSONObject(triggerJson);
    if (pastEndTime) {
        json.put("end_time", "1960-01-01T00:00:00.000Z");
    } else {
        json.put("end_time", "2200-01-01T00:00:00.000Z");
    }
    return new OSTestInAppMessageInternal(json);
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 2 with OSTestInAppMessageInternal

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

the class InAppMessagingHelpers method buildTestMessageWithMultipleDisplays.

private static OSTestInAppMessageInternal buildTestMessageWithMultipleDisplays(final JSONArray triggerJson, final int limit, final long delay) throws JSONException {
    JSONObject json = basicIAMJSONObject(triggerJson);
    json.put("redisplay", new JSONObject() {

        {
            put("limit", limit);
            // in seconds
            put("delay", delay);
        }
    });
    return new OSTestInAppMessageInternal(json);
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject)

Example 3 with OSTestInAppMessageInternal

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

the class InAppMessagingHelpers method buildTestMessageWithLiquid.

public static OSTestInAppMessageInternal buildTestMessageWithLiquid(final JSONArray triggerJson) throws JSONException {
    JSONObject json = basicIAMJSONObject(triggerJson);
    json.put(IAM_HAS_LIQUID, true);
    return new OSTestInAppMessageInternal(json);
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject)

Example 4 with OSTestInAppMessageInternal

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

the class TestHelpers method getAllInAppMessages.

static synchronized List<OSTestInAppMessageInternal> getAllInAppMessages(OneSignalDb db) throws JSONException {
    Cursor cursor = db.query(OneSignalPackagePrivateHelper.InAppMessageTable.TABLE_NAME, null, null, null, null, null, null);
    List<OSTestInAppMessageInternal> iams = new ArrayList<>();
    if (cursor.moveToFirst())
        do {
            String messageId = cursor.getString(cursor.getColumnIndex(OneSignalPackagePrivateHelper.InAppMessageTable.COLUMN_NAME_MESSAGE_ID));
            String clickIds = cursor.getString(cursor.getColumnIndex(OneSignalPackagePrivateHelper.InAppMessageTable.COLUMN_CLICK_IDS));
            int displayQuantity = cursor.getInt(cursor.getColumnIndex(OneSignalPackagePrivateHelper.InAppMessageTable.COLUMN_NAME_DISPLAY_QUANTITY));
            long lastDisplay = cursor.getLong(cursor.getColumnIndex(OneSignalPackagePrivateHelper.InAppMessageTable.COLUMN_NAME_LAST_DISPLAY));
            boolean displayed = cursor.getInt(cursor.getColumnIndex(OneSignalPackagePrivateHelper.InAppMessageTable.COLUMN_DISPLAYED_IN_SESSION)) == 1;
            JSONArray clickIdsArray = new JSONArray(clickIds);
            Set<String> clickIdsSet = new HashSet<>();
            for (int i = 0; i < clickIdsArray.length(); i++) {
                clickIdsSet.add(clickIdsArray.getString(i));
            }
            OSTestInAppMessageInternal inAppMessage = new OSTestInAppMessageInternal(messageId, displayQuantity, lastDisplay, displayed, clickIdsSet);
            iams.add(inAppMessage);
        } while (cursor.moveToNext());
    cursor.close();
    return iams;
}
Also used : OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Cursor(android.database.Cursor)

Example 5 with OSTestInAppMessageInternal

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

the class InAppMessageIntegrationTests method testInAppMessageClickActionMultipleOutcomes.

@Test
public void testInAppMessageClickActionMultipleOutcomes() throws Exception {
    // 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);
            put("weight", IAM_OUTCOME_WEIGHT);
        }
    });
    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
    ShadowOneSignalRestClient.Request iamOutcomeRequest = ShadowOneSignalRestClient.requests.get(3);
    ShadowOneSignalRestClient.Request secondIamOutcomeRequest = ShadowOneSignalRestClient.requests.get(4);
    assertEquals("outcomes/measure", iamOutcomeRequest.url);
    assertEquals("outcomes/measure", secondIamOutcomeRequest.url);
    // Requests: Param request + Players Request + Click request + Outcome Request x 2
    assertEquals(5, ShadowOneSignalRestClient.requests.size());
    assertEquals(IAM_OUTCOME_WEIGHT, iamOutcomeRequest.payload.get("weight"));
    assertEquals(IAM_OUTCOME_NAME, iamOutcomeRequest.payload.get("id"));
    assertEquals(1, iamOutcomeRequest.payload.get("device_type"));
    assertFalse(secondIamOutcomeRequest.payload.has("weight"));
    assertEquals(IAM_OUTCOME_NAME, secondIamOutcomeRequest.payload.get("id"));
    assertEquals(1, secondIamOutcomeRequest.payload.get("device_type"));
}
Also used : ShadowOneSignalRestClient(com.onesignal.ShadowOneSignalRestClient) OSTestInAppMessageInternal(com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) OneSignalPackagePrivateHelper(com.onesignal.OneSignalPackagePrivateHelper) 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