-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
prepareReplayEvent.test.ts
77 lines (66 loc) · 2.01 KB
/
prepareReplayEvent.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type { Hub, Scope } from '@sentry/core';
import { getCurrentHub } from '@sentry/core';
import type { Client, ReplayEvent } from '@sentry/types';
import { REPLAY_EVENT_NAME } from '../../../src/constants';
import { prepareReplayEvent } from '../../../src/util/prepareReplayEvent';
import { getDefaultClientOptions, TestClient } from '../../utils/TestClient';
describe('Unit | util | prepareReplayEvent', () => {
let hub: Hub;
let client: Client;
let scope: Scope;
beforeEach(() => {
hub = getCurrentHub();
client = new TestClient(getDefaultClientOptions());
hub.bindClient(client);
client = hub.getClient()!;
scope = hub.getScope()!;
jest.spyOn(client, 'getSdkMetadata').mockImplementation(() => {
return {
sdk: {
name: 'sentry.javascript.testSdk',
version: '1.0.0',
},
};
});
});
afterEach(() => {
jest.clearAllMocks();
});
it('works', async () => {
expect(client).toBeDefined();
expect(scope).toBeDefined();
const replayId = 'replay-ID';
const event: ReplayEvent = {
// @ts-ignore private api
type: REPLAY_EVENT_NAME,
timestamp: 1670837008.634,
error_ids: ['error-ID'],
trace_ids: ['trace-ID'],
urls: ['https://sentry.io/'],
replay_id: replayId,
replay_type: 'session',
segment_id: 3,
};
const replayEvent = await prepareReplayEvent({ scope, client, replayId, event });
expect(client.getSdkMetadata).toHaveBeenCalledTimes(1);
expect(replayEvent).toEqual({
type: 'replay_event',
timestamp: 1670837008.634,
error_ids: ['error-ID'],
trace_ids: ['trace-ID'],
urls: ['https://sentry.io/'],
replay_id: 'replay-ID',
replay_type: 'session',
segment_id: 3,
platform: 'javascript',
event_id: 'replay-ID',
environment: 'production',
sdk: {
name: 'sentry.javascript.testSdk',
version: '1.0.0',
},
sdkProcessingMetadata: {},
breadcrumbs: undefined,
});
});
});