Skip to content

Commit 2b7a319

Browse files
committed
Add tests for defaults and finals
1 parent 5b9665a commit 2b7a319

File tree

1 file changed

+67
-7
lines changed

1 file changed

+67
-7
lines changed

packages/core/RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryStartTest.kt

+67-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import com.facebook.react.bridge.JavaOnlyMap
55
import com.facebook.react.common.JavascriptException
66
import io.sentry.Breadcrumb
77
import io.sentry.ILogger
8+
import io.sentry.SentryEvent
9+
import io.sentry.android.core.CurrentActivityHolder
810
import io.sentry.android.core.SentryAndroidOptions
11+
import io.sentry.protocol.SdkVersion
912
import org.junit.Assert.assertEquals
1013
import org.junit.Assert.assertFalse
14+
import org.junit.Assert.assertNotNull
1115
import org.junit.Assert.assertNull
1216
import org.junit.Assert.assertTrue
1317
import org.junit.Before
@@ -62,13 +66,6 @@ class RNSentryStartTest {
6266
assertFalse(actualOptions.isEnableSpotlight)
6367
}
6468

65-
@Test
66-
fun `the JavascriptException is added to the ignoredExceptionsForType list on with react defaults`() {
67-
val actualOptions = SentryAndroidOptions()
68-
RNSentryStart.updateWithReactDefaults(actualOptions, activity)
69-
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
70-
}
71-
7269
@Test
7370
fun `beforeBreadcrumb callback filters out Sentry DSN requests breadcrumbs`() {
7471
val options = SentryAndroidOptions()
@@ -188,4 +185,67 @@ class RNSentryStartTest {
188185

189186
assertEquals(breadcrumb, result)
190187
}
188+
189+
@Test
190+
fun `the JavascriptException is added to the ignoredExceptionsForType list on with react defaults`() {
191+
val actualOptions = SentryAndroidOptions()
192+
RNSentryStart.updateWithReactDefaults(actualOptions, activity)
193+
assertTrue(actualOptions.ignoredExceptionsForType.contains(JavascriptException::class.java))
194+
}
195+
196+
@Test
197+
fun `the sdk version information is added to the initialisation options with react defaults`() {
198+
val actualOptions = SentryAndroidOptions()
199+
RNSentryStart.updateWithReactDefaults(actualOptions, activity)
200+
assertEquals(RNSentryVersion.ANDROID_SDK_NAME, actualOptions.sdkVersion?.name)
201+
assertEquals(
202+
io.sentry.android.core.BuildConfig.VERSION_NAME,
203+
actualOptions.sdkVersion?.version,
204+
)
205+
assertEquals(true, actualOptions.sdkVersion?.packages?.isNotEmpty())
206+
assertEquals(
207+
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_NAME,
208+
actualOptions.sdkVersion
209+
?.packages
210+
?.last()
211+
?.name,
212+
)
213+
assertEquals(
214+
RNSentryVersion.REACT_NATIVE_SDK_PACKAGE_VERSION,
215+
actualOptions.sdkVersion
216+
?.packages
217+
?.last()
218+
?.version,
219+
)
220+
}
221+
222+
@Test
223+
fun `the tracing options are added to the initialisation options with react defaults`() {
224+
val actualOptions = SentryAndroidOptions()
225+
RNSentryStart.updateWithReactDefaults(actualOptions, activity)
226+
assertNull(actualOptions.tracesSampleRate)
227+
assertNull(actualOptions.tracesSampler)
228+
assertEquals(false, actualOptions.enableTracing)
229+
}
230+
231+
@Test
232+
fun `the current activity is added to the initialisation options with react defaults`() {
233+
val actualOptions = SentryAndroidOptions()
234+
RNSentryStart.updateWithReactDefaults(actualOptions, activity)
235+
assertEquals(activity, CurrentActivityHolder.getInstance().activity)
236+
}
237+
238+
@Test
239+
fun `beforeSend callback that sets event tags is set with react finals`() {
240+
val options = SentryAndroidOptions()
241+
val event =
242+
SentryEvent().apply { sdk = SdkVersion(RNSentryVersion.ANDROID_SDK_NAME, "1.0") }
243+
244+
RNSentryStart.updateWithReactFinals(options)
245+
val result = options.beforeSend?.execute(event, mock())
246+
247+
assertNotNull(result)
248+
assertEquals("android", result?.getTag("event.origin"))
249+
assertEquals("java", result?.getTag("event.environment"))
250+
}
191251
}

0 commit comments

Comments
 (0)