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);
}
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);
}
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);
}
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;
}
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"));
}
Aggregations