-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-database.js
More file actions
92 lines (75 loc) · 2.16 KB
/
test-database.js
File metadata and controls
92 lines (75 loc) · 2.16 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
// Test script to verify Supabase database setup
// Run this in your browser console after the database is set up
import { supabase } from './src/lib/supabaseClient.js';
// Test 1: Check if users table exists and can insert data
async function testUsersTable() {
console.log('Testing users table...');
try {
// Try to insert a test user
const { data, error } = await supabase
.from('users')
.insert([{
username: 'testuser',
password: 'testpassword123'
}])
.select()
.single();
if (error) {
console.error('Users table error:', error);
return false;
}
console.log('✅ Users table working:', data);
// Clean up - delete the test user
await supabase
.from('users')
.delete()
.eq('username', 'testuser');
return true;
} catch (err) {
console.error('Users table test failed:', err);
return false;
}
}
// Test 2: Check if pastes table has username column
async function testPastesTable() {
console.log('Testing pastes table...');
try {
// Try to insert a test paste with username
const { data, error } = await supabase
.from('pastes')
.insert([{
title: 'Test Paste',
content: 'This is a test paste',
username: 'testuser'
}])
.select()
.single();
if (error) {
console.error('Pastes table error:', error);
return false;
}
console.log('✅ Pastes table working:', data);
// Clean up - delete the test paste
await supabase
.from('pastes')
.delete()
.eq('id', data.id);
return true;
} catch (err) {
console.error('Pastes table test failed:', err);
return false;
}
}
// Run all tests
async function runTests() {
console.log('🧪 Starting Supabase database tests...');
const usersTest = await testUsersTable();
const pastesTest = await testPastesTable();
if (usersTest && pastesTest) {
console.log('🎉 All tests passed! Database is ready for SafeNote.');
} else {
console.log('❌ Some tests failed. Please check your database setup.');
}
}
// Export for manual testing
window.testSupabase = runTests;