Skip to content

Commit

Permalink
one more test
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Apr 19, 2024
1 parent 42cb0a7 commit a9b30eb
Showing 1 changed file with 82 additions and 2 deletions.
84 changes: 82 additions & 2 deletions packages/core/test/lib/feedback.test.ts
@@ -1,5 +1,5 @@
import { Span } from '@sentry/types';
import { getCurrentScope, setCurrentClient, startSpan } from '../../src';
import type { Span } from '@sentry/types';
import { addBreadcrumb, getCurrentScope, setCurrentClient, startSpan, withIsolationScope, withScope } from '../../src';
import { captureFeedback } from '../../src/feedback';
import { TestClient, getDefaultTestClientOptions } from '../mocks/client';

Expand Down Expand Up @@ -380,4 +380,84 @@ describe('captureFeedback', () => {
],
]);
});

it('applies scope data to feedback', async () => {
const client = new TestClient(
getDefaultTestClientOptions({
dsn: 'https://dsn@ingest.f00.f00/1',
enableSend: true,
enableTracing: true,
// We don't care about transactions here...
beforeSendTransaction() {
return null;
},
}),
);
setCurrentClient(client);
client.init();

const mockTransport = jest.spyOn(client.getTransport()!, 'send');

withIsolationScope(isolationScope => {
isolationScope.setTag('test-1', 'tag');
isolationScope.setExtra('test-1', 'extra');

return withScope(scope => {
scope.setTag('test-2', 'tag');
scope.setExtra('test-2', 'extra');

addBreadcrumb({ message: 'test breadcrumb', timestamp: 12345 });

captureFeedback({
name: 'doe',
email: 're@example.org',
message: 'mi',
});
});
});

expect(mockTransport).toHaveBeenCalledWith([
{
event_id: expect.any(String),
sent_at: expect.any(String),
trace: {
trace_id: expect.any(String),
environment: 'production',
public_key: 'dsn',
},
},
[
[
{ type: 'feedback' },
{
breadcrumbs: [{ message: 'test breadcrumb', timestamp: 12345 }],
contexts: {
trace: {
span_id: expect.any(String),
trace_id: expect.any(String),
},
feedback: {
contact_email: 're@example.org',
message: 'mi',
name: 'doe',
},
},
extra: {
'test-1': 'extra',
'test-2': 'extra',
},
tags: {
'test-1': 'tag',
'test-2': 'tag',
},
level: 'info',
environment: 'production',
event_id: expect.any(String),
timestamp: expect.any(Number),
type: 'feedback',
},
],
],
]);
});
});

0 comments on commit a9b30eb

Please sign in to comment.