-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
userIntegrations.test.ts
105 lines (95 loc) · 4.88 KB
/
userIntegrations.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
import { RewriteFrames } from '@sentry/integrations';
import { Integration } from '@sentry/types';
import { addOrUpdateIntegration, updateIntegration, UserIntegrationsFunction } from '../../src/utils/userIntegrations';
const testIntegration = new RewriteFrames();
describe('addOrUpdateIntegration()', () => {
describe('user integrations without any integrations', () => {
test('as an array', () => {
const userIntegrations: Integration[] = [];
// Should get a single integration
let finalIntegrations = addOrUpdateIntegration(testIntegration, userIntegrations);
expect(finalIntegrations).toBeInstanceOf(Array);
finalIntegrations = finalIntegrations as Integration[];
expect(finalIntegrations).toHaveLength(1);
expect(finalIntegrations[0]).toMatchObject(testIntegration);
});
test('as a function', () => {
const userIntegrationFnc: UserIntegrationsFunction = (): Integration[] => [];
// Should get a single integration
const integrationWrapper = addOrUpdateIntegration(testIntegration, userIntegrationFnc);
expect(integrationWrapper).toBeInstanceOf(Function);
const finalIntegrations = (integrationWrapper as UserIntegrationsFunction)([]);
expect(finalIntegrations).toHaveLength(1);
expect(finalIntegrations[0]).toMatchObject(testIntegration);
});
});
describe('user integrations with integrations', () => {
test('as an array', () => {
const userIntegrations = [new RewriteFrames()];
// Should get the same array (with no patches)
const finalIntegrations = addOrUpdateIntegration(testIntegration, userIntegrations);
expect(finalIntegrations).toMatchObject(userIntegrations);
});
test('as a function', () => {
const userIntegrations = [new RewriteFrames()];
const integrationsFnc: UserIntegrationsFunction = (_integrations: Integration[]): Integration[] => {
return userIntegrations;
};
// Should get a function that returns the test integration
let finalIntegrations = addOrUpdateIntegration(testIntegration, integrationsFnc);
expect(typeof finalIntegrations === 'function').toBe(true);
expect(finalIntegrations).toBeInstanceOf(Function);
finalIntegrations = finalIntegrations as UserIntegrationsFunction;
expect(finalIntegrations([])).toMatchObject(userIntegrations);
});
});
});
describe('updateIntegration()', () => {
describe('integrations function', () => {
test('should update an integration if it exists', () => {
const intagration = new RewriteFrames() as any;
const userIntegrations = [intagration];
const integrationsFnc: UserIntegrationsFunction = (_integrations: Integration[]): Integration[] => {
return userIntegrations;
};
// Should get a function that returns the test integration
let finalIntegrations = updateIntegration('RewriteFrames', integrationsFnc, { _option: true });
expect(typeof finalIntegrations === 'function').toBe(true);
finalIntegrations = finalIntegrations as UserIntegrationsFunction;
const evaluatedIntegrations = finalIntegrations([]);
expect(evaluatedIntegrations).toMatchObject(userIntegrations);
expect(intagration._option).toBe(true);
});
test("should not update an integration if it doesn't exist", () => {
const intagration = new RewriteFrames() as any;
const userIntegrations = [intagration];
const integrationsFnc: UserIntegrationsFunction = (_integrations: Integration[]): Integration[] => {
return userIntegrations;
};
let finalIntegrations = updateIntegration('UncaughtException', integrationsFnc, { _option: true });
expect(typeof finalIntegrations === 'function').toBe(true);
finalIntegrations = finalIntegrations as UserIntegrationsFunction;
const evaluatedIntegrations = finalIntegrations([]);
expect(evaluatedIntegrations).toMatchObject(userIntegrations);
expect(intagration._option).not.toBeDefined();
});
});
describe('integrations array', () => {
test('should update an integration if it exists', () => {
const intagration = new RewriteFrames() as any;
const userIntegrations = [intagration];
const finalIntegrations = updateIntegration('RewriteFrames', userIntegrations, { _option: true });
expect(finalIntegrations).toBeInstanceOf(Array);
expect(finalIntegrations).toMatchObject(userIntegrations);
expect(intagration._option).toBe(true);
});
test("should not update an integration if it doesn't exist", () => {
const intagration = new RewriteFrames() as any;
const userIntegrations = [intagration];
const finalIntegrations = updateIntegration('UncaughtException', userIntegrations, { _option: true });
expect(finalIntegrations).toBeInstanceOf(Array);
expect(finalIntegrations).toMatchObject(userIntegrations);
expect(intagration._option).not.toBeDefined();
});
});
});