Skip to content

Commit 817eac8

Browse files
committed
Update the client implementation to use the new capture feedback js api
1 parent 8ab11b6 commit 817eac8

File tree

3 files changed

+34
-55
lines changed

3 files changed

+34
-55
lines changed

packages/core/src/js/client.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { eventFromException, eventFromMessage } from '@sentry/browser';
1+
import { captureFeedback as captureFeedbackApi, eventFromException, eventFromMessage } from '@sentry/browser';
22
import { BaseClient } from '@sentry/core';
33
import type {
44
ClientReportEnvelope,
@@ -7,9 +7,9 @@ import type {
77
Event,
88
EventHint,
99
Outcome,
10+
SendFeedbackParams,
1011
SeverityLevel,
1112
TransportMakeRequestResponse,
12-
UserFeedback,
1313
} from '@sentry/types';
1414
import { dateTimestampInSeconds, logger, SentryError } from '@sentry/utils';
1515
import { Alert } from 'react-native';
@@ -20,7 +20,7 @@ import { getDefaultSidecarUrl } from './integrations/spotlight';
2020
import type { ReactNativeClientOptions } from './options';
2121
import type { mobileReplayIntegration } from './replay/mobilereplay';
2222
import { MOBILE_REPLAY_INTEGRATION_NAME } from './replay/mobilereplay';
23-
import { createUserFeedbackEnvelope, items } from './utils/envelope';
23+
import { items } from './utils/envelope';
2424
import { ignoreRequireCycleLogs } from './utils/ignorerequirecyclelogs';
2525
import { mergeOutcomes } from './utils/outcome';
2626
import { ReactNativeLibraries } from './utils/rnlibraries';
@@ -86,14 +86,8 @@ export class ReactNativeClient extends BaseClient<ReactNativeClientOptions> {
8686
/**
8787
* Sends user feedback to Sentry.
8888
*/
89-
public captureUserFeedback(feedback: UserFeedback): void {
90-
const envelope = createUserFeedbackEnvelope(feedback, {
91-
metadata: this._options._metadata,
92-
dsn: this.getDsn(),
93-
tunnel: undefined,
94-
});
95-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
96-
this.sendEnvelope(envelope);
89+
public captureFeedback(feedback: SendFeedbackParams): void {
90+
captureFeedbackApi(feedback);
9791
}
9892

9993
/**

packages/core/test/client.test.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import * as mockedtimetodisplaynative from './tracing/mockedtimetodisplaynative';
22
jest.mock('../src/js/tracing/timetodisplaynative', () => mockedtimetodisplaynative);
33

4-
import { defaultStackParser } from '@sentry/browser';
5-
import type { Envelope, Event, Outcome, Transport, TransportMakeRequestResponse } from '@sentry/types';
4+
import { captureFeedback as captureFeedbackApi, defaultStackParser } from '@sentry/browser';
5+
import type {
6+
Envelope,
7+
Event,
8+
Outcome,
9+
SendFeedbackParams,
10+
Transport,
11+
TransportMakeRequestResponse,
12+
} from '@sentry/types';
613
import { rejectedSyncPromise, SentryError } from '@sentry/utils';
714
import * as RN from 'react-native';
815

@@ -19,7 +26,6 @@ import {
1926
envelopeItems,
2027
firstArg,
2128
getMockSession,
22-
getMockUserFeedback,
2329
getSyncPromiseRejectOnFirstCall,
2430
} from './testutils';
2531

@@ -76,6 +82,14 @@ jest.mock(
7682
}),
7783
);
7884

85+
jest.mock('@sentry/browser', () => {
86+
const actual = jest.requireActual('@sentry/browser');
87+
return {
88+
...actual,
89+
captureFeedback: jest.fn(),
90+
};
91+
});
92+
7993
const EXAMPLE_DSN = 'https://[email protected]/148053';
8094

8195
const DEFAULT_OPTIONS: ReactNativeClientOptions = {
@@ -187,15 +201,6 @@ describe('Tests ReactNativeClient', () => {
187201
expect(mockTransport.send).not.toBeCalled();
188202
});
189203

190-
test('captureUserFeedback does not call transport when enabled false', () => {
191-
const mockTransport = createMockTransport();
192-
const client = createDisabledClientWith(mockTransport);
193-
194-
client.captureUserFeedback(getMockUserFeedback());
195-
196-
expect(mockTransport.send).not.toBeCalled();
197-
});
198-
199204
function createDisabledClientWith(transport: Transport) {
200205
return new ReactNativeClient({
201206
...DEFAULT_OPTIONS,
@@ -290,34 +295,26 @@ describe('Tests ReactNativeClient', () => {
290295
});
291296

292297
describe('UserFeedback', () => {
293-
test('sends UserFeedback to native Layer', () => {
298+
test('sends UserFeedback', () => {
294299
const mockTransportSend: jest.Mock = jest.fn(() => Promise.resolve());
295300
const client = new ReactNativeClient({
296301
...DEFAULT_OPTIONS,
297302
dsn: EXAMPLE_DSN,
298-
transport: () => ({
299-
send: mockTransportSend,
300-
flush: jest.fn(),
301-
}),
302303
});
304+
jest.mock('@sentry/browser', () => ({
305+
captureFeedback: jest.fn(),
306+
}));
303307

304-
client.captureUserFeedback({
305-
comments: 'Test Comments',
308+
const feedback: SendFeedbackParams = {
309+
message: 'Test Comments',
306310
307311
name: 'Test User',
308-
event_id: 'testEvent123',
309-
});
312+
associatedEventId: 'testEvent123',
313+
};
310314

311-
expect(mockTransportSend.mock.calls[0][firstArg][envelopeHeader].event_id).toEqual('testEvent123');
312-
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemHeader].type).toEqual(
313-
'user_report',
314-
);
315-
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload]).toEqual({
316-
comments: 'Test Comments',
317-
318-
name: 'Test User',
319-
event_id: 'testEvent123',
320-
});
315+
client.captureFeedback(feedback);
316+
317+
expect(captureFeedbackApi).toHaveBeenCalledWith(feedback);
321318
});
322319
});
323320

@@ -417,11 +414,6 @@ describe('Tests ReactNativeClient', () => {
417414
client.captureSession(getMockSession());
418415
expect(getSdkInfoFrom(mockTransportSend)).toStrictEqual(expectedSdkInfo);
419416
});
420-
421-
test('send SdkInfo in the user feedback envelope header', () => {
422-
client.captureUserFeedback(getMockUserFeedback());
423-
expect(getSdkInfoFrom(mockTransportSend)).toStrictEqual(expectedSdkInfo);
424-
});
425417
});
426418

427419
describe('event data enhancement', () => {

packages/core/test/testutils.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Session, Transport, UserFeedback } from '@sentry/types';
1+
import type { Session, Transport } from '@sentry/types';
22
import { rejectedSyncPromise } from '@sentry/utils';
33

44
export type MockInterface<T> = {
@@ -36,13 +36,6 @@ export const getMockSession = (): Session => ({
3636
}),
3737
});
3838

39-
export const getMockUserFeedback = (): UserFeedback => ({
40-
comments: 'comments_test_value',
41-
email: 'email_test_value',
42-
name: 'name_test_value',
43-
event_id: 'event_id_test_value',
44-
});
45-
4639
export const getSyncPromiseRejectOnFirstCall = <Y extends any[]>(reason: unknown): jest.Mock => {
4740
let shouldSyncReject = true;
4841
return jest.fn((..._args: Y) => {

0 commit comments

Comments
 (0)