forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
113 lines (99 loc) · 2.46 KB
/
Copy pathmiddleware.js
File metadata and controls
113 lines (99 loc) · 2.46 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import { expect, jest } from '@jest/globals'
import { post } from '../../../tests/helpers/e2etest.js'
describe('POST /events', () => {
jest.setTimeout(60 * 1000)
async function checkEvent(data, code) {
const body = JSON.stringify(data)
const res = await post('/api/events', {
body,
headers: {
'content-type': 'application/json',
},
})
expect(res.statusCode).toBe(code)
}
const baseExample = {
context: {
// Primitives
event_id: 'a35d7f88-3f48-4f36-ad89-5e3c8ebc3df7',
user: '703d32a8-ed0f-45f9-8d78-a913d4dc6f19',
version: '1.0.0',
created: '2020-10-02T17:12:18.620Z',
// Content information
path: '/github/docs/issues',
hostname: 'github.com',
referrer: 'https://github.com/github/docs',
search: '?q=is%3Aissue+is%3Aopen+example+',
href: 'https://github.com/github/docs/issues?q=is%3Aissue+is%3Aopen+example+',
path_language: 'en',
// Device information
os: 'linux',
os_version: '18.04',
browser: 'chrome',
browser_version: '85.0.4183.121',
viewport_width: 1418,
viewport_height: 501,
// Location information
timezone: -7,
user_language: 'en-US',
},
}
const pageExample = { ...baseExample, type: 'page' }
it('should require a type', () => checkEvent(baseExample, 400))
it('should record a page event', () => checkEvent(pageExample, 200))
it('should require an event_id in uuid', () =>
checkEvent(
{
...pageExample,
context: {
...pageExample.context,
event_id: 'asdfghjkl',
},
},
400
))
it('should require a user in uuid', () =>
checkEvent(
{
...pageExample,
context: {
...pageExample.context,
user: 'asdfghjkl',
},
},
400
))
it('should require a version', () =>
checkEvent(
{
...pageExample,
context: {
...pageExample.context,
version: undefined,
},
},
400
))
it('should require created timestamp', () =>
checkEvent(
{
...pageExample,
context: {
...pageExample.context,
timestamp: 1234,
},
},
400
))
it('should not allow a honeypot token', () =>
checkEvent(
{
...pageExample,
context: {
...pageExample.context,
token: 'zxcv',
},
},
400
))
})