-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-realtime-chat.js
More file actions
68 lines (58 loc) · 2.1 KB
/
test-realtime-chat.js
File metadata and controls
68 lines (58 loc) · 2.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
// Test script to verify real-time messaging functionality
// Run this in the browser console to test message sharing
console.log('Testing real-time chat functionality...');
// Test 1: Check if realtimeChat is available
if (typeof window.realtimeChat !== 'undefined') {
console.log('✅ RealtimeChat is available');
} else {
console.log('❌ RealtimeChat is not available');
}
// Test 2: Check if Supabase client is available
if (typeof window.supabase !== 'undefined') {
console.log('✅ Supabase client is available');
} else {
console.log('❌ Supabase client is not available');
}
// Test 3: Test message sending
async function testMessageSending() {
try {
const testMessage = {
id: crypto.randomUUID(),
clinicId: 'test-clinic-1',
sessionId: 'test-session-' + Date.now(),
authorType: 'user',
text: 'Test message from browser console',
createdAt: new Date(),
moderation: { status: 'allowed' }
};
await window.realtimeChat.addMessage(testMessage);
console.log('✅ Test message sent successfully');
} catch (error) {
console.error('❌ Failed to send test message:', error);
}
}
// Test 4: Test message subscription
function testMessageSubscription() {
const unsubscribe = window.realtimeChat.subscribe((messages) => {
console.log('📨 Received messages:', messages.length);
const latestMessage = messages[messages.length - 1];
if (latestMessage) {
console.log('Latest message:', latestMessage.text);
}
});
console.log('✅ Message subscription active');
// Cleanup after 10 seconds
setTimeout(() => {
unsubscribe();
console.log('🔌 Message subscription cleaned up');
}, 10000);
}
// Run tests
console.log('Starting real-time chat tests...');
testMessageSubscription();
setTimeout(testMessageSending, 2000);
console.log('Test instructions:');
console.log('1. Open this page in another browser/device');
console.log('2. Send a message from the other device');
console.log('3. Check if the message appears here in real-time');
console.log('4. Send a message from here and check if it appears on the other device');