-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,567 additions
and
710 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...SentryAndroidTester/app/src/androidTest/java/io/sentry/react/RNSentryJsonConverterTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package io.sentry.react | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.facebook.react.bridge.WritableArray | ||
import com.facebook.react.bridge.WritableMap | ||
import io.sentry.react.RNSentryJsonConverter.convertToWritable | ||
import org.json.JSONArray | ||
import org.json.JSONObject | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertNull | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class RNSentryJsonConverterTest { | ||
@Test | ||
fun testConvertToWritableWithSimpleJsonObject() { | ||
val jsonObject = | ||
JSONObject().apply { | ||
put("floatKey", 12.3f) | ||
put("doubleKey", 12.3) | ||
put("intKey", 123) | ||
put("stringKey", "test") | ||
put("nullKey", JSONObject.NULL) | ||
} | ||
|
||
val result: WritableMap? = convertToWritable(jsonObject) | ||
|
||
assertNotNull(result) | ||
assertEquals(12.3, result!!.getDouble("floatKey"), 0.0001) | ||
assertEquals(12.3, result.getDouble("doubleKey"), 0.0) | ||
assertEquals(123, result.getInt("intKey")) | ||
assertEquals("test", result.getString("stringKey")) | ||
assertNull(result.getString("nullKey")) | ||
} | ||
|
||
@Test | ||
fun testConvertToWritableWithNestedJsonObject() { | ||
val jsonObject = | ||
JSONObject().apply { | ||
put( | ||
"nested", | ||
JSONObject().apply { | ||
put("key", "value") | ||
}, | ||
) | ||
} | ||
|
||
val result: WritableMap? = convertToWritable(jsonObject) | ||
|
||
assertNotNull(result) | ||
val nestedMap = result!!.getMap("nested") | ||
assertNotNull(nestedMap) | ||
assertEquals("value", nestedMap!!.getString("key")) | ||
} | ||
|
||
@Test | ||
fun testConvertToWritableWithJsonArray() { | ||
val jsonArray = | ||
JSONArray().apply { | ||
put(1) | ||
put(2.5) | ||
put("string") | ||
put(JSONObject.NULL) | ||
} | ||
|
||
val result: WritableArray = convertToWritable(jsonArray) | ||
|
||
assertEquals(1, result.getInt(0)) | ||
assertEquals(2.5, result.getDouble(1), 0.0) | ||
assertEquals("string", result.getString(2)) | ||
assertNull(result.getString(3)) | ||
} | ||
|
||
@Test | ||
fun testConvertToWritableWithNestedJsonArray() { | ||
val jsonObject = | ||
JSONObject().apply { | ||
put( | ||
"array", | ||
JSONArray().apply { | ||
put( | ||
JSONObject().apply { | ||
put("key1", "value1") | ||
}, | ||
) | ||
put( | ||
JSONObject().apply { | ||
put("key2", "value2") | ||
}, | ||
) | ||
}, | ||
) | ||
} | ||
|
||
val result: WritableMap? = convertToWritable(jsonObject) | ||
|
||
val array = result?.getArray("array") | ||
assertEquals("value1", array?.getMap(0)?.getString("key1")) | ||
assertEquals("value2", array?.getMap(1)?.getString("key2")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,13 @@ package io.sentry.react | |
import android.content.pm.PackageInfo | ||
import android.content.pm.PackageManager | ||
import com.facebook.react.bridge.Arguments | ||
import com.facebook.react.bridge.JavaOnlyMap | ||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.WritableMap | ||
import com.facebook.react.common.JavascriptException | ||
import io.sentry.Breadcrumb | ||
import io.sentry.ILogger | ||
import io.sentry.SentryLevel | ||
import io.sentry.android.core.SentryAndroidOptions | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
@@ -103,163 +96,4 @@ class RNSentryModuleImplTest { | |
val capturedMap = writableMapCaptor.value | ||
assertEquals(false, capturedMap.getBoolean("has_fetched")) | ||
} | ||
|
||
@Test | ||
fun `when the spotlight option is enabled, the spotlight SentryAndroidOption is set to true and the default url is used`() { | ||
val options = | ||
JavaOnlyMap.of( | ||
"spotlight", | ||
true, | ||
"defaultSidecarUrl", | ||
"http://localhost:8969/teststream", | ||
) | ||
val actualOptions = SentryAndroidOptions() | ||
module.getSentryAndroidOptions(actualOptions, options, logger) | ||
assert(actualOptions.isEnableSpotlight) | ||
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl) | ||
} | ||
|
||
@Test | ||
fun `when the spotlight url is passed, the spotlight is enabled for the given url`() { | ||
val options = JavaOnlyMap.of("spotlight", "http://localhost:8969/teststream") | ||
val actualOptions = SentryAndroidOptions() | ||
module.getSentryAndroidOptions(actualOptions, options, logger) | ||
assert(actualOptions.isEnableSpotlight) | ||
assertEquals("http://localhost:8969/teststream", actualOptions.spotlightConnectionUrl) | ||
} | ||
|
||
@Test | ||
fun `when the spotlight option is disabled, the spotlight SentryAndroidOption is set to false`() { | ||
val options = JavaOnlyMap.of("spotlight", false) | ||
val actualOptions = SentryAndroidOptions() | ||
module.getSentryAndroidOptions(actualOptions, options, logger) | ||
assertFalse(actualOptions.isEnableSpotlight) | ||
} | ||
|
||
@Test | ||
fun `the JavascriptException is added to the ignoredExceptionsForType list on initialisation`() { | ||
val actualOptions = SentryAndroidOptions() | ||
module.getSentryAndroidOptions(actualOptions, JavaOnlyMap.of(), logger) | ||
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java)) | ||
} | ||
|
||
@Test | ||
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = | ||
JavaOnlyMap.of( | ||
"dsn", | ||
"https://[email protected]/1234567", | ||
"devServerUrl", | ||
"http://localhost:8081", | ||
) | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = | ||
Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "https://def.ingest.sentry.io/1234567") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertNull("Breadcrumb should be filtered out", result) | ||
} | ||
|
||
@Test | ||
fun `beforeBreadcrumb callback filters out dev server breadcrumbs`() { | ||
val mockDevServerUrl = "http://localhost:8081" | ||
val options = SentryAndroidOptions() | ||
val rnOptions = | ||
JavaOnlyMap.of( | ||
"dsn", | ||
"https://[email protected]/1234567", | ||
"devServerUrl", | ||
mockDevServerUrl, | ||
) | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = | ||
Breadcrumb().apply { | ||
type = "http" | ||
setData("url", mockDevServerUrl) | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertNull("Breadcrumb should be filtered out", result) | ||
} | ||
|
||
@Test | ||
fun `beforeBreadcrumb callback does not filter out non dev server or dsn breadcrumbs`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = | ||
JavaOnlyMap.of( | ||
"dsn", | ||
"https://[email protected]/1234567", | ||
"devServerUrl", | ||
"http://localhost:8081", | ||
) | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = | ||
Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
|
||
@Test | ||
fun `the breadcrumb is not filtered out when the dev server url and dsn are not passed`() { | ||
val options = SentryAndroidOptions() | ||
module.getSentryAndroidOptions(options, JavaOnlyMap(), logger) | ||
|
||
val breadcrumb = | ||
Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
|
||
@Test | ||
fun `the breadcrumb is not filtered out when the dev server url is not passed and the dsn does not match`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of("dsn", "https://[email protected]/1234567") | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = | ||
Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
|
||
@Test | ||
fun `the breadcrumb is not filtered out when the dev server url does not match and the dsn is not passed`() { | ||
val options = SentryAndroidOptions() | ||
val rnOptions = JavaOnlyMap.of("devServerUrl", "http://localhost:8081") | ||
module.getSentryAndroidOptions(options, rnOptions, logger) | ||
|
||
val breadcrumb = | ||
Breadcrumb().apply { | ||
type = "http" | ||
setData("url", "http://testurl.com/service") | ||
} | ||
|
||
val result = options.beforeBreadcrumb?.execute(breadcrumb, mock()) | ||
|
||
assertEquals(breadcrumb, result) | ||
} | ||
} |
Oops, something went wrong.