-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-websocket.js
More file actions
52 lines (41 loc) · 1.55 KB
/
Copy pathtest-websocket.js
File metadata and controls
52 lines (41 loc) · 1.55 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
// Bu dosyayı proje kök dizinine koy (taskflow-api/test-websocket.js)
// Çalıştırma: TEST_ACCESS_TOKEN=eyJ... TEST_WORKSPACE_ID=xxx node test-websocket.js
//
// GÜVENLİK: Access token'ı asla kod içine hardcode etme, commit etme.
// Environment variable ile geçir — bu, testin kendisi kadar kolay ama
// git geçmişine sızma riski taşımaz.
const { io } = require('socket.io-client');
const ACCESS_TOKEN = process.env.TEST_ACCESS_TOKEN;
const WORKSPACE_ID = process.env.TEST_WORKSPACE_ID;
if (!ACCESS_TOKEN || !WORKSPACE_ID) {
console.error(
'❌ TEST_ACCESS_TOKEN ve TEST_WORKSPACE_ID environment variable\'ları gerekli.\n' +
'Örnek: TEST_ACCESS_TOKEN=eyJ... TEST_WORKSPACE_ID=xxx node test-websocket.js',
);
process.exit(1);
}
const socket = io('http://localhost:8000', {
auth: { token: ACCESS_TOKEN },
});
socket.on('connect', () => {
console.log('✅ Bağlandı:', socket.id);
socket.emit('workspace:join', { workspaceId: WORKSPACE_ID });
});
socket.on('workspace:joined', (data) => {
console.log('✅ Workspace odasına katıldı:', data);
});
socket.on('exception', (err) => {
console.error('❌ Sunucu hatası (muhtemelen yetkisiz erişim):', err);
});
socket.on('task:created', (task) => {
console.log('📩 task:created event alındı:', task);
});
socket.on('task:updated', (task) => {
console.log('📩 task:updated event alındı:', task);
});
socket.on('connect_error', (err) => {
console.error('❌ Bağlantı hatası:', err.message);
});
socket.on('disconnect', () => {
console.log('🔌 Bağlantı kesildi');
});