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