-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-test-result.js
More file actions
93 lines (85 loc) · 3.1 KB
/
create-test-result.js
File metadata and controls
93 lines (85 loc) · 3.1 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
const http = require('http');
// Get pending tasks
http.get('http://127.0.0.1:4000/api/v1/scraping/tasks/pending', {
headers: { 'X-API-Key': 'sk-test-integration-1234567890' }
}, (res) => {
let data = '';
res.on('data', c => data += c);
res.on('end', () => {
const json = JSON.parse(data);
if (json.tasks && json.tasks.length > 0) {
const taskId = json.tasks[0].id;
console.log('✅ Using task:', taskId);
// Start task
const startOpts = {
hostname: '127.0.0.1',
port: 4000,
path: `/api/v1/scraping/tasks/${taskId}/start`,
method: 'POST',
headers: { 'X-API-Key': 'sk-test-integration-1234567890' }
};
const startReq = http.request(startOpts, (startRes) => {
let startData = '';
startRes.on('data', c => startData += c);
startRes.on('end', () => {
console.log('✅ Task started:', startData);
// Submit result after 500ms
setTimeout(() => {
const resultData = JSON.stringify({
taskId,
platformId: 'tiktok',
success: true,
data: {
items: [{
id: `tiktok-zachking-${Date.now()}`,
title: 'Zach King',
description: 'Bringing a little more wonder into the world',
url: 'https://www.tiktok.com/@zachking',
metadata: {
username: 'zachking',
displayName: 'Zach King',
bio: 'Bringing a little more wonder',
stats: {
followers: 84300000,
likes: 1200000000,
following: 166
},
engagement: { rate: 14.23 }
}
}],
pageInfo: { currentPage: 1, totalPages: 1 }
},
timestamp: new Date().toISOString(),
executionTime: 1500
});
const resultOpts = {
hostname: '127.0.0.1',
port: 4000,
path: `/api/v1/scraping/tasks/${taskId}/result`,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(resultData),
'X-API-Key': 'sk-test-integration-1234567890'
}
};
const resultReq = http.request(resultOpts, (resultRes) => {
let resultData = '';
resultRes.on('data', c => resultData += c);
resultRes.on('end', () => {
console.log('✅ Result submitted:', resultData);
});
});
resultReq.on('error', e => console.error('❌ Result error:', e));
resultReq.write(resultData);
resultReq.end();
}, 500);
});
});
startReq.on('error', e => console.error('❌ Start error:', e));
startReq.end();
} else {
console.log('❌ No pending tasks found');
}
});
}).on('error', e => console.error('❌ Request error:', e));