update
This commit is contained in:
76
scripts/test-api-teachers.js
Normal file
76
scripts/test-api-teachers.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Test API endpoint for teachers
|
||||
*/
|
||||
|
||||
const API_BASE = 'http://localhost:4000/api';
|
||||
|
||||
async function testTeachersAPI() {
|
||||
console.log('🧪 Testing Teachers API\n');
|
||||
console.log('='.repeat(60));
|
||||
|
||||
try {
|
||||
// Test 1: Get all teachers with school filter
|
||||
console.log('\n📝 Test 1: GET /api/teachers with school_id filter');
|
||||
console.log('URL: ' + API_BASE + '/teachers?school_id=95ec32e9-cdcb-4f3a-a8ee-8af20bdfe2cc&page=1&limit=5');
|
||||
|
||||
const response1 = await fetch(`${API_BASE}/teachers?school_id=95ec32e9-cdcb-4f3a-a8ee-8af20bdfe2cc&page=1&limit=5`);
|
||||
const data1 = await response1.json();
|
||||
|
||||
if (data1.success) {
|
||||
console.log('✅ Success!');
|
||||
console.log(` Total: ${data1.data.pagination.total}`);
|
||||
console.log(` Returned: ${data1.data.teachers.length}`);
|
||||
|
||||
if (data1.data.teachers.length > 0) {
|
||||
const teacher = data1.data.teachers[0];
|
||||
console.log('\n📋 Sample Teacher:');
|
||||
console.log(` ID: ${teacher.id}`);
|
||||
console.log(` Code: ${teacher.teacher_code}`);
|
||||
console.log(` Type: ${teacher.teacher_type}`);
|
||||
console.log(` Status: ${teacher.status}`);
|
||||
console.log(` Profile: ${teacher.profile ? '✅ EXISTS' : '❌ NULL'}`);
|
||||
|
||||
if (teacher.profile) {
|
||||
console.log(` - Full Name: ${teacher.profile.full_name}`);
|
||||
console.log(` - Phone: ${teacher.profile.phone || 'N/A'}`);
|
||||
console.log(` - School ID: ${teacher.profile.school_id}`);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('❌ Failed:', data1.message);
|
||||
}
|
||||
|
||||
// Test 2: Get all teachers without filter
|
||||
console.log('\n\n📝 Test 2: GET /api/teachers (no filter)');
|
||||
console.log('URL: ' + API_BASE + '/teachers?page=1&limit=3');
|
||||
|
||||
const response2 = await fetch(`${API_BASE}/teachers?page=1&limit=3`);
|
||||
const data2 = await response2.json();
|
||||
|
||||
if (data2.success) {
|
||||
console.log('✅ Success!');
|
||||
console.log(` Total: ${data2.data.pagination.total}`);
|
||||
console.log(` Returned: ${data2.data.teachers.length}`);
|
||||
|
||||
console.log('\n📋 Teachers:');
|
||||
data2.data.teachers.forEach((t, i) => {
|
||||
console.log(` ${i + 1}. ${t.teacher_code} - Profile: ${t.profile ? '✅' : '❌'}`);
|
||||
if (t.profile) {
|
||||
console.log(` Name: ${t.profile.full_name}`);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('❌ Failed:', data2.message);
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(60));
|
||||
console.log('✅ Tests completed!');
|
||||
console.log('='.repeat(60) + '\n');
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Test failed:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Run test
|
||||
testTeachersAPI();
|
||||
Reference in New Issue
Block a user