-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-integration.js
More file actions
66 lines (62 loc) · 2.27 KB
/
test-integration.js
File metadata and controls
66 lines (62 loc) · 2.27 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
// node test-integration.js
// Sends a realistic batch to localhost:3737/ingest and prints the result.
const ENDPOINT = 'http://localhost:3737/ingest';
const ORG_ID = 'test-org';
const batch = {
sdkVersion: '0.1.0',
sentAt: Date.now(),
events: [
{
count: 3,
dedupeKey: JSON.stringify({ method: 'GET', domain: 'api.example.com', path: '/users', keys: ['page'] }),
data: {
method: 'GET',
protocol: 'https',
domain: 'api.example.com',
path: '/users',
queryParams: { page: 'a3f2c8b4e1d9f0a1c2e3a3f2c8b4e1d9f0a1c2e3a3f2c8b4e1d9f0a1c2e3aabb' },
requestHeaders: { authorization: 'a3f2c8b4e1d9f0a1c2e3aabb d9f0a1c2e3a3f2c8b4e1d9f0a1c2e3aabbccdd' },
requestBody: null,
responseStatus: 200,
responseHeaders: { 'content-type': 'a3f2c8b4e1d9f0a1c2e3aabbccdd1122334455667788990011223344556677889900' },
responseBody: { type: 'json', data: { users: [{ id: 'hashhashhash', name: 'hashhashhash' }] } },
timestamp: Date.now() - 200,
duration: 142,
},
},
{
count: 1,
dedupeKey: JSON.stringify({ method: 'POST', domain: 'api.example.com', path: '/graphql', keys: [], op: 'GetCurrentUser' }),
data: {
method: 'POST',
protocol: 'https',
domain: 'api.example.com',
path: '/graphql',
queryParams: {},
requestHeaders: { 'content-type': 'a3f2c8b4e1d9f0a1c2e3aabb' },
requestBody: { type: 'graphql', operationName: 'GetCurrentUser', data: { query: 'hashhashhash', variables: { id: 'hashhashhash' } } },
responseStatus: 200,
responseHeaders: {},
responseBody: { type: 'graphql', operationName: 'GetCurrentUser', data: { data: { me: { id: 'hashhashhash' } } } },
timestamp: Date.now() - 100,
duration: 88,
graphqlOperationName: 'GetCurrentUser',
},
},
],
};
const res = await fetch(ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Org-Id': ORG_ID,
},
body: JSON.stringify(batch),
});
console.log(`POST ${ENDPOINT} → ${res.status} ${res.statusText}`);
if (!res.ok) {
const text = await res.text();
console.error('Response body:', text);
process.exit(1);
}
console.log('OK — check server output for the parsed batch.');