Skip to content

Commit a9b30eb

Browse files
committed
one more test
1 parent 42cb0a7 commit a9b30eb

File tree

1 file changed

+82
-2
lines changed

1 file changed

+82
-2
lines changed

packages/core/test/lib/feedback.test.ts

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Span } from '@sentry/types';
2-
import { getCurrentScope, setCurrentClient, startSpan } from '../../src';
1+
import type { Span } from '@sentry/types';
2+
import { addBreadcrumb, getCurrentScope, setCurrentClient, startSpan, withIsolationScope, withScope } from '../../src';
33
import { captureFeedback } from '../../src/feedback';
44
import { TestClient, getDefaultTestClientOptions } from '../mocks/client';
55

@@ -380,4 +380,84 @@ describe('captureFeedback', () => {
380380
],
381381
]);
382382
});
383+
384+
it('applies scope data to feedback', async () => {
385+
const client = new TestClient(
386+
getDefaultTestClientOptions({
387+
dsn: 'https://[email protected]/1',
388+
enableSend: true,
389+
enableTracing: true,
390+
// We don't care about transactions here...
391+
beforeSendTransaction() {
392+
return null;
393+
},
394+
}),
395+
);
396+
setCurrentClient(client);
397+
client.init();
398+
399+
const mockTransport = jest.spyOn(client.getTransport()!, 'send');
400+
401+
withIsolationScope(isolationScope => {
402+
isolationScope.setTag('test-1', 'tag');
403+
isolationScope.setExtra('test-1', 'extra');
404+
405+
return withScope(scope => {
406+
scope.setTag('test-2', 'tag');
407+
scope.setExtra('test-2', 'extra');
408+
409+
addBreadcrumb({ message: 'test breadcrumb', timestamp: 12345 });
410+
411+
captureFeedback({
412+
name: 'doe',
413+
414+
message: 'mi',
415+
});
416+
});
417+
});
418+
419+
expect(mockTransport).toHaveBeenCalledWith([
420+
{
421+
event_id: expect.any(String),
422+
sent_at: expect.any(String),
423+
trace: {
424+
trace_id: expect.any(String),
425+
environment: 'production',
426+
public_key: 'dsn',
427+
},
428+
},
429+
[
430+
[
431+
{ type: 'feedback' },
432+
{
433+
breadcrumbs: [{ message: 'test breadcrumb', timestamp: 12345 }],
434+
contexts: {
435+
trace: {
436+
span_id: expect.any(String),
437+
trace_id: expect.any(String),
438+
},
439+
feedback: {
440+
contact_email: '[email protected]',
441+
message: 'mi',
442+
name: 'doe',
443+
},
444+
},
445+
extra: {
446+
'test-1': 'extra',
447+
'test-2': 'extra',
448+
},
449+
tags: {
450+
'test-1': 'tag',
451+
'test-2': 'tag',
452+
},
453+
level: 'info',
454+
environment: 'production',
455+
event_id: expect.any(String),
456+
timestamp: expect.any(Number),
457+
type: 'feedback',
458+
},
459+
],
460+
],
461+
]);
462+
});
383463
});

0 commit comments

Comments
 (0)