|
141 | 141 | import static com.onesignal.OneSignalPackagePrivateHelper.OneSignal_setTrackerFactory;
|
142 | 142 | import static com.onesignal.OneSignalPackagePrivateHelper.OneSignal_taskQueueWaitingForInit;
|
143 | 143 | import static com.onesignal.OneSignalPackagePrivateHelper.OSObservable;
|
| 144 | +import static com.onesignal.OneSignalPackagePrivateHelper.toUnescapedEUIDString; |
144 | 145 | import static com.onesignal.ShadowOneSignalRestClient.EMAIL_USER_ID;
|
145 | 146 | import static com.onesignal.ShadowOneSignalRestClient.PUSH_USER_ID;
|
146 | 147 | import static com.onesignal.ShadowOneSignalRestClient.REST_METHOD;
|
@@ -3378,6 +3379,69 @@ public void testOSNotificationOpenResultToJSONObject() throws Exception {
|
3378 | 3379 | assertEquals("collapseId1", firstGroupedNotification.optString("collapseId"));
|
3379 | 3380 | }
|
3380 | 3381 |
|
| 3382 | + // ####### Unit test JSONUtils methods |
| 3383 | + @Test |
| 3384 | + public void test_JSONUtils_toUnescapedEUIDString() throws Exception { |
| 3385 | + // 1. Test when EUID is first in the json, and has ($) and (/), and ($) elsewhere |
| 3386 | + |
| 3387 | + // Set up the JSONObject to test with |
| 3388 | + String jsonStringWithDollarAndSlash = "{" + |
| 3389 | + "\"external_user_id\":\"$1$/abc/de$f/\"," + |
| 3390 | + "\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"," + |
| 3391 | + "\"timezone\":\"$Europe/London\"" + |
| 3392 | + "}"; |
| 3393 | + JSONObject jsonWithDollarAndSlash = new JSONObject(jsonStringWithDollarAndSlash); |
| 3394 | + |
| 3395 | + // The expected string which escapes the "timezone" slash (/) only |
| 3396 | + String expected_jsonStringWithDollarAndSlash = "{" + |
| 3397 | + "\"external_user_id\":\"$1$/abc/de$f/\"," + |
| 3398 | + "\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"," + |
| 3399 | + "\"timezone\":\"$Europe\\/London\"" + |
| 3400 | + "}"; |
| 3401 | + |
| 3402 | + // The actual string result from calling JSONUtils.toUnescapedEUIDString() |
| 3403 | + String actual_jsonStringWithDollarAndSlash = toUnescapedEUIDString(jsonWithDollarAndSlash); |
| 3404 | + |
| 3405 | + // These two strings should be equal |
| 3406 | + assertEquals(expected_jsonStringWithDollarAndSlash, actual_jsonStringWithDollarAndSlash); |
| 3407 | + |
| 3408 | + // 2. Test when EUID is first in the json, and has no dollar nor slash |
| 3409 | + |
| 3410 | + String jsonStringWithEUID = "{" + |
| 3411 | + "\"external_user_id\":\"123abc\"," + |
| 3412 | + "\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"," + |
| 3413 | + "\"timezone\":\"$Europe/London\"" + |
| 3414 | + "}"; |
| 3415 | + JSONObject jsonWithEUID = new JSONObject(jsonStringWithEUID); |
| 3416 | + |
| 3417 | + String expected_jsonStringWithEUID = "{" + |
| 3418 | + "\"external_user_id\":\"123abc\"," + |
| 3419 | + "\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"," + |
| 3420 | + "\"timezone\":\"$Europe\\/London\"" + |
| 3421 | + "}"; |
| 3422 | + |
| 3423 | + String actual_jsonStringWithEUID = toUnescapedEUIDString(jsonWithEUID); |
| 3424 | + |
| 3425 | + assertEquals(expected_jsonStringWithEUID, actual_jsonStringWithEUID); |
| 3426 | + |
| 3427 | + // 3. Test when there is no EUID is in the json |
| 3428 | + |
| 3429 | + String jsonStringWithoutEUID = "{" + |
| 3430 | + "\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"," + |
| 3431 | + "\"timezone\":\"Europe/London\"" + |
| 3432 | + "}"; |
| 3433 | + JSONObject jsonWithoutEUID = new JSONObject(jsonStringWithoutEUID); |
| 3434 | + |
| 3435 | + String expected_jsonStringWithoutEUID = "{" + |
| 3436 | + "\"app_id\":\"b4f7f966-d8cc-11e4-bed1-df8f05be55ba\"," + |
| 3437 | + "\"timezone\":\"Europe\\/London\"" + |
| 3438 | + "}"; |
| 3439 | + |
| 3440 | + String actual_jsonStringWithoutEUID = toUnescapedEUIDString(jsonWithoutEUID); |
| 3441 | + |
| 3442 | + assertEquals(expected_jsonStringWithoutEUID, actual_jsonStringWithoutEUID); |
| 3443 | + } |
| 3444 | + |
3381 | 3445 | @Test
|
3382 | 3446 | public void testNotificationOpenedProcessorHandlesEmptyIntent() {
|
3383 | 3447 | NotificationOpenedProcessor_processFromContext(blankActivity, new Intent());
|
|
0 commit comments