-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathapi.test.ts
137 lines (133 loc) · 4.43 KB
/
api.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import { describe, expect, it, test } from 'vitest';
import { getEnvelopeEndpointWithUrlEncodedAuth, getReportDialogEndpoint } from '../../src/api';
import type { DsnComponents, SdkInfo } from '../../src/types-hoist';
import { makeDsn } from '../../src/utils-hoist/dsn';
const ingestDsn = 'https://abc@xxxx.ingest.sentry.io:1234/subpath/123';
const dsnPublic = 'https://abc@sentry.io:1234/subpath/123';
const tunnel = 'https://hello.com/world';
const sdkInfo = { name: 'sentry.javascript.browser', version: '12.31.12' };
const dsnPublicComponents = makeDsn(dsnPublic)!;
describe('API', () => {
describe('getEnvelopeEndpointWithUrlEncodedAuth', () => {
it.each([
[
"doesn't include `sentry_client` when called with only DSN",
dsnPublicComponents,
undefined,
undefined,
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_version=7&sentry_key=abc',
],
['uses `tunnel` value when called with `tunnel` option', dsnPublicComponents, tunnel, undefined, tunnel],
[
'uses `tunnel` value when called with `tunnel` and `sdkInfo` options',
dsnPublicComponents,
tunnel,
sdkInfo,
tunnel,
],
[
'includes `sentry_client` when called with `sdkInfo` in options and no tunnel',
dsnPublicComponents,
undefined,
sdkInfo,
'https://sentry.io:1234/subpath/api/123/envelope/?sentry_version=7&sentry_key=abc&sentry_client=sentry.javascript.browser%2F12.31.12',
],
])(
'%s',
(
_testName: string,
dsnComponents: DsnComponents,
tunnel: string | undefined,
sdkInfo: SdkInfo | undefined,
expected: string,
) => {
expect(getEnvelopeEndpointWithUrlEncodedAuth(dsnComponents, tunnel, sdkInfo)).toBe(expected);
},
);
});
describe('getReportDialogEndpoint', () => {
test.each([
[
'with Ingest DSN',
ingestDsn,
{},
'https://xxxx.ingest.sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@xxxx.ingest.sentry.io:1234/subpath/123',
],
[
'with Public DSN',
dsnPublic,
{},
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123',
],
[
'with Public DSN and dynamic options',
dsnPublic,
{ eventId: 'abc', testy: '2' },
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc&testy=2',
],
[
'with Public DSN, dynamic options and user name and email',
dsnPublic,
{
eventId: 'abc',
user: {
email: 'email',
name: 'yo',
},
},
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc&name=yo&email=email',
],
[
'with Public DSN and user name',
dsnPublic,
{
user: {
name: 'yo',
},
},
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&name=yo',
],
[
'with Public DSN and user email',
dsnPublic,
{
user: {
email: 'email',
},
},
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&email=email',
],
[
'with Public DSN, dynamic options and undefined user',
dsnPublic,
{
eventId: 'abc',
user: undefined,
},
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123&eventId=abc',
],
[
'with Public DSN and undefined user',
dsnPublic,
{ user: undefined },
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123',
],
[
'with Public DSN and onClose callback',
dsnPublic,
{ onClose: () => {} },
'https://sentry.io:1234/subpath/api/embed/error-page/?dsn=https://abc@sentry.io:1234/subpath/123',
],
])(
'%s',
(
_: string,
dsn: Parameters<typeof getReportDialogEndpoint>[0],
options: Parameters<typeof getReportDialogEndpoint>[1],
output: ReturnType<typeof getReportDialogEndpoint>,
) => {
expect(getReportDialogEndpoint(dsn, options)).toBe(output);
},
);
});
});