Repository navigation
Expand file tree
/
Copy pathtest-profile-update.js
More file actions
103 lines (86 loc) · 3.01 KB
/
Copy pathtest-profile-update.js
File metadata and controls
103 lines (86 loc) · 3.01 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
94
95
96
97
98
99
100
101
102
103
import { createClient } from '@supabase/supabase-js';
import dotenv from 'dotenv';
// Load environment variables
dotenv.config();
const supabaseUrl = process.env.SUPABASE_URL;
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
console.log('🔧 Testing profile update functionality...');
const supabase = createClient(supabaseUrl, supabaseServiceRoleKey, {
auth: {
autoRefreshToken: false,
persistSession: false
}
});
async function testProfileUpdate() {
try {
// Get a test student
console.log('\n📊 Getting test student...');
const { data: students, error: fetchError } = await supabase
.from('students')
.select('*')
.limit(1);
if (fetchError) {
console.error('❌ Error fetching student:', fetchError);
return;
}
if (!students || students.length === 0) {
console.error('❌ No students found in database');
return;
}
const testStudent = students[0];
console.log('✅ Test student found:', testStudent.register_number);
console.log('Current data:', {
name: testStudent.name,
'email id': testStudent['email id'],
'mobile number': testStudent['mobile number']
});
// Test update with the exact same structure as the profile form
console.log('\n🧪 Testing profile update...');
const updateData = {
name: testStudent.name || 'Test Name Updated',
'email id': 'test@example.com',
'mobile number': '1234567890',
updated_at: new Date().toISOString()
};
const { data: updateResult, error: updateError } = await supabase
.from('students')
.update(updateData)
.eq('register_number', testStudent.register_number)
.select();
if (updateError) {
console.error('❌ Profile update failed:', updateError);
console.error('Update data attempted:', updateData);
// Let's check the exact column names
console.log('\n🔍 Checking exact column structure...');
const { data: columnCheck } = await supabase
.from('students')
.select('*')
.eq('register_number', testStudent.register_number)
.limit(1);
if (columnCheck && columnCheck[0]) {
console.log('Available columns:', Object.keys(columnCheck[0]));
}
} else {
console.log('✅ Profile update successful!');
console.log('Updated data:', updateResult[0]);
}
// Test password update
console.log('\n🔐 Testing password update...');
const { data: passwordResult, error: passwordError } = await supabase
.from('students')
.update({
password: 'newpassword123',
updated_at: new Date().toISOString()
})
.eq('register_number', testStudent.register_number)
.select();
if (passwordError) {
console.error('❌ Password update failed:', passwordError);
} else {
console.log('✅ Password update successful!');
}
} catch (error) {
console.error('❌ Unexpected error:', error);
}
}
testProfileUpdate().catch(console.error);