use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessagingUnitTests method comparativeOperatorTest.
/**
* Convenience function that saves a local trigger (localValue) for the property name "test_property"
* then creates an in-app message with a trigger (triggerValue) for the same property name. It
* then evaluates the message for the given trigger conditions and returns the boolean, which
* indicates whether or not the message should be shown.
*
* For example, we can set up a test where the app has a property value of 3 and we want to
* test to make sure that if a message has a trigger value of 2 and an operator > that it
* returns true when evaluated, because 3 > 2
*/
private static boolean comparativeOperatorTest(OSTriggerOperator operator, Object triggerValue, Object localValue) throws JSONException {
setLocalTriggerValue("test_property", localValue);
OSTestInAppMessageInternal testMessage = InAppMessagingHelpers.buildTestMessageWithSingleTrigger(OSTriggerKind.CUSTOM, "test_property", operator.toString(), triggerValue);
return InAppMessagingHelpers.evaluateMessage(testMessage);
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageClickActionOutcome.
@Test
public void testInAppMessageClickActionOutcome() 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);
}
});
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);
assertEquals("outcomes/measure", iamOutcomeRequest.url);
// Requests: Param request + Players Request + Click request + Outcome Request
assertEquals(4, ShadowOneSignalRestClient.requests.size());
assertFalse(iamOutcomeRequest.payload.has("weight"));
assertFalse(iamOutcomeRequest.payload.has("direct"));
assertEquals(IAM_OUTCOME_NAME, iamOutcomeRequest.payload.get("id"));
assertEquals(1, iamOutcomeRequest.payload.get("device_type"));
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testCachedIAMSharedPreferenceAndSQL_cleanedAfterSixMonths.
@Test
public void testCachedIAMSharedPreferenceAndSQL_cleanedAfterSixMonths() throws Exception {
final long currentTimeInSeconds = System.currentTimeMillis() / 1_000L;
// 1. Setup IAMs
// Create an IAM younger than 6 months
final OSTestInAppMessageInternal iam1 = InAppMessagingHelpers.buildTestMessage(null);
iam1.setRedisplayStats(1, currentTimeInSeconds - SIX_MONTHS_TIME_SECONDS + 10);
String clickId1 = "iam1_click_id_1";
iam1.addClickId(clickId1);
TestHelpers.saveIAM(iam1, dbHelper);
// Create an IAM older than 6 months
final OSTestInAppMessageInternal iam2 = InAppMessagingHelpers.buildTestMessage(null);
iam2.setRedisplayStats(1, currentTimeInSeconds - SIX_MONTHS_TIME_SECONDS - 10);
String clickId2 = "iam2_click_id_1";
iam2.addClickId(clickId2);
TestHelpers.saveIAM(iam2, dbHelper);
// 2. Cache IAMs as dismissed, impressioned, and clicked
Set<String> messageIds = new HashSet<String>() {
{
add(iam1.getMessageId());
add(iam2.getMessageId());
}
};
TestOneSignalPrefs.saveStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_DISMISSED_IAMS, messageIds);
TestOneSignalPrefs.saveStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_IMPRESSIONED_IAMS, messageIds);
Set<String> clickedClickIds = new HashSet<String>() {
{
addAll(iam1.getClickedClickIds());
addAll(iam2.getClickedClickIds());
}
};
TestOneSignalPrefs.saveStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_CLICKED_CLICK_IDS_IAMS, clickedClickIds);
// 3. Init OneSignal so it attempts to clean IAM cache
OneSignalInit();
threadAndTaskWait();
// 4. Validate all data associated with the 6 month old IAM has been deleted
Set<String> testDismissedMessages = TestOneSignalPrefs.getStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_DISMISSED_IAMS, null);
assertEquals(1, testDismissedMessages.size());
assertTrue(testDismissedMessages.contains(iam1.getMessageId()));
Set<String> testImpressionedMessages = TestOneSignalPrefs.getStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_IMPRESSIONED_IAMS, null);
assertEquals(1, testImpressionedMessages.size());
assertTrue(testImpressionedMessages.contains(iam1.getMessageId()));
Set<String> testClickedClickIds = TestOneSignalPrefs.getStringSet(TestOneSignalPrefs.PREFS_ONESIGNAL, TestOneSignalPrefs.PREFS_OS_CLICKED_CLICK_IDS_IAMS, null);
assertEquals(1, testClickedClickIds.size());
assertTrue(testClickedClickIds.contains(clickId1));
// 5. Make sure only IAM left is the IAM younger than 6 months
List<OSTestInAppMessageInternal> savedInAppMessagesAfterInit = TestHelpers.getAllInAppMessages(dbHelper);
assertEquals(1, savedInAppMessagesAfterInit.size());
assertEquals(iam1.getMessageId(), savedInAppMessagesAfterInit.get(0).getMessageId());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testMessagesDoNotDisplayPastEndTime.
@Test
public void testMessagesDoNotDisplayPastEndTime() throws Exception {
final OSTestInAppMessageInternal message = InAppMessagingHelpers.buildTestMessageWithEndTime(OSTriggerKind.CUSTOM, "test_key", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 3, true);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message);
}
});
// the SDK should read the message from registration JSON, set up a timer, and once
// the timer fires the message should get shown.
OneSignalInit();
threadAndTaskWait();
// We will set the trigger. However, since the end time is in the past the message should not be shown
OneSignal.addTrigger("test_key", 3);
// Make no IAMs are in the display queue
assertEquals(0, OneSignalPackagePrivateHelper.getInAppMessageDisplayQueue().size());
// Make sure no IAM is showing
assertFalse(OneSignalPackagePrivateHelper.isInAppMessageShowing());
}
use of com.onesignal.OneSignalPackagePrivateHelper.OSTestInAppMessageInternal in project OneSignal-Android-SDK by OneSignal.
the class InAppMessageIntegrationTests method testInAppMessageRedisplayCacheCleaning.
@Test
public void testInAppMessageRedisplayCacheCleaning() throws Exception {
final long currentTimeInSeconds = System.currentTimeMillis() / 1000;
final OSTestInAppMessageInternal inAppMessage = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_saved", OneSignalPackagePrivateHelper.OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
String firstID = inAppMessage.getMessageId() + "_test";
inAppMessage.setMessageId(firstID);
inAppMessage.getRedisplayStats().setLastDisplayTime(currentTimeInSeconds - SIX_MONTHS_TIME_SECONDS + 1);
TestHelpers.saveIAM(inAppMessage, dbHelper);
inAppMessage.getRedisplayStats().setLastDisplayTime(currentTimeInSeconds - SIX_MONTHS_TIME_SECONDS - 1);
inAppMessage.setMessageId(inAppMessage.getMessageId() + "1");
TestHelpers.saveIAM(inAppMessage, dbHelper);
List<OSTestInAppMessageInternal> savedInAppMessages = TestHelpers.getAllInAppMessages(dbHelper);
assertEquals(2, savedInAppMessages.size());
final OSTestInAppMessageInternal message1 = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_1", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
final OSTestInAppMessageInternal message2 = InAppMessagingHelpers.buildTestMessageWithSingleTriggerAndRedisplay(OSTriggerKind.CUSTOM, "test_2", OSTestTrigger.OSTriggerOperator.EQUAL_TO.toString(), 2, LIMIT, DELAY);
setMockRegistrationResponseWithMessages(new ArrayList<OSTestInAppMessageInternal>() {
{
add(message1);
add(message2);
}
});
// Init OneSignal with IAM with redisplay
OneSignalInit();
threadAndTaskWait();
List<OSTestInAppMessageInternal> savedInAppMessagesAfterInit = TestHelpers.getAllInAppMessages(dbHelper);
// Message with old display time should be removed
assertEquals(1, savedInAppMessagesAfterInit.size());
assertEquals(firstID, savedInAppMessagesAfterInit.get(0).getMessageId());
}
Aggregations