-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathtypes-test.ts
More file actions
92 lines (86 loc) · 2.84 KB
/
types-test.ts
File metadata and controls
92 lines (86 loc) · 2.84 KB
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
import { RaygunPayload, RaygunStatic } from '../types/index';
// Test RaygunPayload interface
function testPayloadStructure(): void {
const payload: RaygunPayload = {
OccurredOn: new Date(),
Details: {
Error: {
ClassName: 'Error',
Message: 'Test error',
StackTrace: []
},
Environment: {
UtcOffset: 0,
"User-Language": 'en-US',
"Document-Mode": 11,
"Browser-Width": 1920,
"Browser-Height": 1080,
"Screen-Width": 1920,
"Screen-Height": 1080,
"Color-Depth": 24,
Browser: 'Chrome',
"Browser-Name": 'Chrome',
"Browser-Version": '120.0.0',
Platform: 'Linux'
},
Client: {
Name: 'raygun4js',
Version: '3.1.3'
},
UserCustomData: {},
Tags: [],
Request: {
Url: 'https://example.com',
QueryString: '',
Headers: {
"User-Agent": 'Mozilla/5.0',
Referer: 'https://example.com',
Host: 'example.com'
}
},
Version: '1.0.0',
User: {
Identifier: 'test-user',
IsAnonymous: false,
Email: 'test@example.com',
FullName: 'Test User',
FirstName: 'Test',
UUID: 'test-uuid'
},
GroupingKey: 'test-group',
Breadcrumbs: [
{
type: 'manual',
message: 'Test breadcrumb',
level: 'info',
metadata: { test: true }
}
]
}
};
}
// Test that onBeforeSend callback can access and modify breadcrumbs
function testOnBeforeSendBreadcrumbAccess(): void {
// Mock Raygun instance
const raygun = {} as RaygunStatic;
// This should compile without TypeScript errors
raygun.onBeforeSend((payload: RaygunPayload) => {
// Access breadcrumbs
if (payload.Details.Breadcrumbs) {
// Filter out sensitive breadcrumbs
payload.Details.Breadcrumbs = payload.Details.Breadcrumbs.filter(breadcrumb => {
return breadcrumb.message !== 'sensitive-operation';
});
// Sanitize breadcrumb messages
payload.Details.Breadcrumbs = payload.Details.Breadcrumbs.map(breadcrumb => ({
...breadcrumb,
message: breadcrumb.message?.replace(/password|secret|token/gi, '[REDACTED]')
}));
}
return payload;
});
}
export {
testPayloadStructure,
testOnBeforeSendBreadcrumbAccess,
};