-
-
Notifications
You must be signed in to change notification settings - Fork 354
Use appLaunchedInForeground to determine invalid app start data on Android #4146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2b596fa
Check if appLaunchedInForeground and launch duration for native app s…
antonis 177ed85
Updates changelog
antonis cc5b409
Merge branch 'main' into antonis/3995-appLaunchedInForeground
antonis 00e48fb
Removes 1 minute check since this is already implemented
antonis 8864ff1
Adds tests for the fetchNativeAppStart function logic
antonis ee5b85e
Fixes inverted test logic
antonis 6212a23
Guards execution when app is not launched in the foreground
antonis 27bd810
Removes unnecessary line
antonis 94123f4
Merge branch 'main' into antonis/3995-appLaunchedInForeground
antonis f632e1c
Merge branch 'main' into antonis/3995-appLaunchedInForeground
antonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
97 changes: 97 additions & 0 deletions
97
RNSentryAndroidTester/app/src/test/java/io/sentry/react/RNSentryModuleImplTest.kt
This file contains hidden or 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,97 @@ | ||
| 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.Promise | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.bridge.WritableMap | ||
| import io.sentry.ILogger | ||
| import io.sentry.SentryLevel | ||
| import org.junit.After | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.junit.runners.JUnit4 | ||
| import org.mockito.ArgumentCaptor | ||
| import org.mockito.Captor | ||
| import org.mockito.Mockito.* | ||
| import org.mockito.MockitoAnnotations | ||
| import org.mockito.MockedStatic | ||
| import org.mockito.Mockito.mockStatic | ||
| import org.mockito.kotlin.whenever | ||
|
|
||
| @RunWith(JUnit4::class) | ||
| class RNSentryModuleImplTest { | ||
|
|
||
| private lateinit var module: RNSentryModuleImpl | ||
| private lateinit var promise: Promise | ||
| private lateinit var logger: ILogger | ||
| private var argumentsMock: MockedStatic<Arguments>? = null | ||
|
|
||
| @Captor | ||
| private lateinit var writableMapCaptor: ArgumentCaptor<WritableMap> | ||
|
|
||
|
|
||
| @Before | ||
| fun setUp() { | ||
| MockitoAnnotations.openMocks(this) | ||
| val reactContext = mock(ReactApplicationContext::class.java) | ||
| promise = mock(Promise::class.java) | ||
| logger = mock(ILogger::class.java) | ||
| val packageManager = mock(PackageManager::class.java) | ||
| val packageInfo = mock(PackageInfo::class.java) | ||
|
|
||
| whenever(reactContext.packageManager).thenReturn(packageManager) | ||
| whenever(packageManager.getPackageInfo(anyString(), anyInt())).thenReturn(packageInfo) | ||
|
|
||
| module = RNSentryModuleImpl(reactContext) | ||
|
|
||
| // Mock the Arguments class | ||
| argumentsMock = mockStatic(Arguments::class.java) | ||
| val writableMap = mock(WritableMap::class.java) | ||
| whenever(Arguments.createMap()).thenReturn(writableMap) | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| argumentsMock?.close() | ||
| } | ||
|
|
||
| @Test | ||
| fun `fetchNativeAppStart resolves promise with null when app is not launched in the foreground`() { | ||
| // Mock the app start measurement | ||
| val appStartMeasurement = mapOf<String, Any>() | ||
|
|
||
| // Call the method | ||
| module.fetchNativeAppStart(promise, appStartMeasurement, logger, false) | ||
|
|
||
| // Verify a warning log is emitted | ||
| verify(logger, org.mockito.kotlin.times(1)).log( | ||
| SentryLevel.WARNING, | ||
| "Invalid app start data: app not launched in foreground." | ||
| ) | ||
|
|
||
| // Verify the promise is resolved with null | ||
| verify(promise).resolve(null) | ||
| } | ||
|
|
||
| @Test | ||
| fun `fetchNativeAppStart resolves promise with app start data when app is launched in the foreground`() { | ||
| // Mock the app start measurement | ||
| val appStartMeasurement = mapOf<String, Any>() | ||
|
|
||
| // Call the method | ||
| module.fetchNativeAppStart(promise, appStartMeasurement, logger, true) | ||
|
|
||
| // Verify no logs are emitted | ||
| verify(logger, org.mockito.kotlin.times(0)).log(any(), any()) | ||
|
|
||
| // Verify the promise is resolved with the expected data | ||
| verify(promise).resolve(any(WritableMap::class.java)) | ||
| verify(promise).resolve(writableMapCaptor.capture()) | ||
| val capturedMap = writableMapCaptor.value | ||
| assertEquals(false, capturedMap.getBoolean("has_fetched")) | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.