-
-
Notifications
You must be signed in to change notification settings - Fork 337
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
8 changed files
with
116 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,24 @@ | |
## Unreleased | ||
|
||
### Features | ||
|
||
- Adds new `captureFeedback` and deprecates the `captureUserFeedback` API ([#4320](https://github.com/getsentry/sentry-react-native/pull/4320)) | ||
|
||
|
||
```jsx | ||
import * as Sentry from "@sentry/react-native"; | ||
|
||
const eventId = Sentry.lastEventId(); | ||
|
||
Sentry.captureFeedback({ | ||
name: "John Doe", | ||
email: "[email protected]", | ||
message: "Hello World!", | ||
associatedEventId: eventId, // optional | ||
}); | ||
``` | ||
|
||
### Fixes | ||
|
||
- Return `lastEventId` export from `@sentry/core` ([#4315](https://github.com/getsentry/sentry-react-native/pull/4315)) | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,15 @@ | ||
import * as mockedtimetodisplaynative from './tracing/mockedtimetodisplaynative'; | ||
jest.mock('../src/js/tracing/timetodisplaynative', () => mockedtimetodisplaynative); | ||
|
||
import { defaultStackParser } from '@sentry/browser'; | ||
import type { Envelope, Event, Outcome, Transport, TransportMakeRequestResponse } from '@sentry/types'; | ||
import { captureFeedback as captureFeedbackApi, defaultStackParser } from '@sentry/browser'; | ||
import type { | ||
Envelope, | ||
Event, | ||
Outcome, | ||
SendFeedbackParams, | ||
Transport, | ||
TransportMakeRequestResponse, | ||
} from '@sentry/types'; | ||
import { rejectedSyncPromise, SentryError } from '@sentry/utils'; | ||
import * as RN from 'react-native'; | ||
|
||
|
@@ -19,7 +26,6 @@ import { | |
envelopeItems, | ||
firstArg, | ||
getMockSession, | ||
getMockUserFeedback, | ||
getSyncPromiseRejectOnFirstCall, | ||
} from './testutils'; | ||
|
||
|
@@ -76,6 +82,14 @@ jest.mock( | |
}), | ||
); | ||
|
||
jest.mock('@sentry/browser', () => { | ||
const actual = jest.requireActual('@sentry/browser'); | ||
return { | ||
...actual, | ||
captureFeedback: jest.fn(), | ||
}; | ||
}); | ||
|
||
const EXAMPLE_DSN = 'https://[email protected]/148053'; | ||
|
||
const DEFAULT_OPTIONS: ReactNativeClientOptions = { | ||
|
@@ -187,15 +201,6 @@ describe('Tests ReactNativeClient', () => { | |
expect(mockTransport.send).not.toBeCalled(); | ||
}); | ||
|
||
test('captureUserFeedback does not call transport when enabled false', () => { | ||
const mockTransport = createMockTransport(); | ||
const client = createDisabledClientWith(mockTransport); | ||
|
||
client.captureUserFeedback(getMockUserFeedback()); | ||
|
||
expect(mockTransport.send).not.toBeCalled(); | ||
}); | ||
|
||
function createDisabledClientWith(transport: Transport) { | ||
return new ReactNativeClient({ | ||
...DEFAULT_OPTIONS, | ||
|
@@ -290,34 +295,25 @@ describe('Tests ReactNativeClient', () => { | |
}); | ||
|
||
describe('UserFeedback', () => { | ||
test('sends UserFeedback to native Layer', () => { | ||
const mockTransportSend: jest.Mock = jest.fn(() => Promise.resolve()); | ||
test('sends UserFeedback', () => { | ||
const client = new ReactNativeClient({ | ||
...DEFAULT_OPTIONS, | ||
dsn: EXAMPLE_DSN, | ||
transport: () => ({ | ||
send: mockTransportSend, | ||
flush: jest.fn(), | ||
}), | ||
}); | ||
jest.mock('@sentry/browser', () => ({ | ||
captureFeedback: jest.fn(), | ||
})); | ||
|
||
client.captureUserFeedback({ | ||
comments: 'Test Comments', | ||
const feedback: SendFeedbackParams = { | ||
message: 'Test Comments', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
event_id: 'testEvent123', | ||
}); | ||
associatedEventId: 'testEvent123', | ||
}; | ||
|
||
expect(mockTransportSend.mock.calls[0][firstArg][envelopeHeader].event_id).toEqual('testEvent123'); | ||
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemHeader].type).toEqual( | ||
'user_report', | ||
); | ||
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload]).toEqual({ | ||
comments: 'Test Comments', | ||
email: '[email protected]', | ||
name: 'Test User', | ||
event_id: 'testEvent123', | ||
}); | ||
client.captureFeedback(feedback); | ||
|
||
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback); | ||
}); | ||
}); | ||
|
||
|
@@ -417,11 +413,6 @@ describe('Tests ReactNativeClient', () => { | |
client.captureSession(getMockSession()); | ||
expect(getSdkInfoFrom(mockTransportSend)).toStrictEqual(expectedSdkInfo); | ||
}); | ||
|
||
test('send SdkInfo in the user feedback envelope header', () => { | ||
client.captureUserFeedback(getMockUserFeedback()); | ||
expect(getSdkInfoFrom(mockTransportSend)).toStrictEqual(expectedSdkInfo); | ||
}); | ||
}); | ||
|
||
describe('event data enhancement', () => { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet, Text, TextInput, Image, Button } from 'react-native'; | ||
import * as Sentry from '@sentry/react-native'; | ||
import { UserFeedback } from '@sentry/react-native'; | ||
import { SendFeedbackParams, UserFeedback } from '@sentry/react-native'; | ||
|
||
export const DEFAULT_COMMENTS = "It's broken again! Please fix it."; | ||
|
||
|
@@ -48,6 +48,23 @@ export function UserFeedbackModal(props: { onDismiss: () => void }) { | |
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Send feedback without event" | ||
color="#6C5FC7" | ||
onPress={async () => { | ||
onDismiss(); | ||
|
||
const userFeedback: SendFeedbackParams = { | ||
message: comments, | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}; | ||
|
||
Sentry.captureFeedback(userFeedback); | ||
clearComments(); | ||
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Close" | ||
color="#6C5FC7" | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import React from 'react'; | ||
import { View, StyleSheet, Text, TextInput, Image, Button } from 'react-native'; | ||
import * as Sentry from '@sentry/react-native'; | ||
import { UserFeedback } from '@sentry/react-native'; | ||
import { SendFeedbackParams, UserFeedback } from '@sentry/react-native'; | ||
|
||
export const DEFAULT_COMMENTS = "It's broken again! Please fix it."; | ||
|
||
|
@@ -48,6 +48,23 @@ export function UserFeedbackModal(props: { onDismiss: () => void }) { | |
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Send feedback without event" | ||
color="#6C5FC7" | ||
onPress={async () => { | ||
onDismiss(); | ||
|
||
const userFeedback: SendFeedbackParams = { | ||
message: comments, | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
}; | ||
|
||
Sentry.captureFeedback(userFeedback); | ||
clearComments(); | ||
}} | ||
/> | ||
<View style={styles.buttonSpacer} /> | ||
<Button | ||
title="Close" | ||
color="#6C5FC7" | ||
|