use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testTimedMessageDisplayedAfterAllTriggersValid.
/**
* If an in-app message should only be shown if (A) session_duration is > 30 seconds and
* (B) a key/value trigger is set, and it should not set up a timer until all of the non-timer
* based triggers for that message evaluate to true
* <p>
* For this test, a timer should never be scheduled because the key/value 'test_key' trigger
* will not be set until the session duration has already exceeded the minimum (0.05 seconds)
*/
@Test
public void testTimedMessageDisplayedAfterAllTriggersValid() throws Exception {
ArrayList<ArrayList<OSTestTrigger>> triggers = new ArrayList<ArrayList<OSTestTrigger>>() {
{
add(new ArrayList<OSTestTrigger>() {
{
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.CUSTOM, "test_key", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), "squirrel"));
add(InAppMessagingHelpers.buildTrigger(OSTriggerKind.SESSION_TIME, null, OSTestTrigger.OSTriggerOperator.GREATER_THAN.toString(), 0.01));
}
});
}
};
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithMultipleTriggers(triggers);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
OneSignalInit();
threadAndTaskWait();
// no timer should be scheduled since 'test_key' != 'squirrel'
assertFalse(ShadowDynamicTimer.hasScheduledTimer);
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// since we are not actually waiting on any logic to finish, sleeping here is fine
Thread.sleep(20);
// the message still should not be displayed
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// after setting this trigger the message should be displayed immediately
OneSignal.addTrigger("test_key", "squirrel");
threadAndTaskWait();
// the message should now have been displayed
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
assertFalse(ShadowDynamicTimer.hasScheduledTimer);
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageClickActionUniqueOutcome.
@Test
public void testInAppMessageClickActionUniqueOutcome() 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("unique", true);
}
});
JSONObject action = new JSONObject() {
{
put("id", IAM_CLICK_ID);
put("outcomes", outcomes);
}
};
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
threadAndTaskWait();
// 3. Ensure outcome is sent
ShadowOneSignalRestClient.Request iamOutcomeRequest = ShadowOneSignalRestClient.requests.get(3);
assertEquals("outcomes/measure", iamOutcomeRequest.url);
// Requests: Param request + Players Request + Click request + Outcome Request
assertEquals(4, ShadowOneSignalRestClient.requests.size());
assertEquals(IAM_OUTCOME_NAME, iamOutcomeRequest.payload.get("id"));
assertEquals(1, iamOutcomeRequest.payload.get("device_type"));
// 4. Call IAM clicked again, ensure no 2nd outcome call is made.
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// 5. Check no additional request was made
assertEquals(4, ShadowOneSignalRestClient.requests.size());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageMultipleRedisplayReceivesClickId.
@Test
public void testInAppMessageMultipleRedisplayReceivesClickId() throws Exception {
// Init OneSignal
OneSignalInit();
threadAndTaskWait();
// Create an IAM
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
assertTrue(message.getClickedClickIds().isEmpty());
// Count IAM as clicked
JSONObject action = new JSONObject() {
{
put("id", IAM_CLICK_ID);
}
};
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// Ensure click is sent
ShadowOneSignalRestClient.Request firstIAMClickRequest = ShadowOneSignalRestClient.requests.get(2);
assertEquals("in_app_messages/" + message.getMessageId() + "/click", firstIAMClickRequest.url);
assertEquals(3, ShadowOneSignalRestClient.requests.size());
// Call IAM clicked again, ensure a 2nd network call isn't 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());
// Verify click id is associated with message
assertEquals(1, message.getClickedClickIds().size());
assertTrue(message.getClickedClickIds().contains(IAM_CLICK_ID));
message.clearClickIds();
assertTrue(message.getClickedClickIds().isEmpty());
// Click should be received twice
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// Call IAM clicked again, ensure a 2nd network call is made.
ShadowOneSignalRestClient.Request secondIAMClickRequest = ShadowOneSignalRestClient.requests.get(3);
assertEquals("in_app_messages/" + message.getMessageId() + "/click", secondIAMClickRequest.url);
assertEquals(4, ShadowOneSignalRestClient.requests.size());
// Verify clickId was persisted locally
Set<String> secondRestClickedMessages = TestOneSignalPrefs.getStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_CLICKED_CLICK_IDS_IAMS, null);
assertEquals(1, secondRestClickedMessages.size());
// Verify click id is associated with message
assertEquals(1, message.getClickedClickIds().size());
assertTrue(message.getClickedClickIds().contains(IAM_CLICK_ID));
// Call IAM clicked again
OneSignalPackagePrivateHelper.onMessageActionOccurredOnMessage(message, action);
// Call IAM clicked again, ensure a 3nd network call isn't made.
assertEquals("in_app_messages/" + message.getMessageId() + "/click", secondIAMClickRequest.url);
assertEquals(4, ShadowOneSignalRestClient.requests.size());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageInternalToJSONObject_messageId.
// Test toJSONObject() method currently only checks JSON for "messageId"
@Test
public void testInAppMessageInternalToJSONObject_messageId() throws Exception {
// 1. Create a basic test IAM
OSTestInAppMessageInternal iam = InAppMessagingHelpers.buildTestMessage(null);
// 2. Set a message ID for the IAM
String messageId = new String(new char[64]).replace('\0', '0');
iam.setMessageId(messageId);
// 3. Init
OneSignalInit();
threadAndTaskWait();
// 4. call toJSONObject() on IAM
JSONObject testJsonObj = iam.toJSONObject();
// 5. Check "messageId" in JSON Object
assertEquals(messageId, testJsonObj.optString("messageId"));
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageNoDisplayMultipleTimes_Limit.
@Test
public void testInAppMessageNoDisplayMultipleTimes_Limit() throws Exception {
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, 1, DELAY);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// Init OneSignal with IAM with redisplay
OneSignalInit();
threadAndTaskWait();
// Add trigger to make IAM display
OneSignal.addTrigger("test_1", 2);
assertEquals(1, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Dismiss IAM will make display quantity increase and last display time to change
OneSignalPackagePrivateHelper.dismissCurrentMessage();
// Check if data after dismiss is set correctly
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
long lastDisplayTime = OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime();
assertTrue(lastDisplayTime > 0);
// Wait for the delay between redisplay
time.advanceSystemTimeBy(DELAY);
// Set trigger, will evaluate IAMs again
OneSignal.addTrigger("test_1", 2);
// Check that the IAM was not displayed again because Limit of display is 1
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().size());
assertEquals(1, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getDisplayQuantity());
assertEquals(lastDisplayTime, OneSignalPackagePrivateHelper.getRedisplayInAppMessages().get(0).getRedisplayStats().getLastDisplayTime());
}
Aggregations