-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_school_sorting.js
More file actions
43 lines (36 loc) · 1.63 KB
/
test_school_sorting.js
File metadata and controls
43 lines (36 loc) · 1.63 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
import 'dotenv/config';
import { SchoolRepository } from './src/repositories/schoolRepository.js';
import { SchoolService } from './src/services/schoolService.js';
async function testSorting() {
const repository = new SchoolRepository();
const service = new SchoolService();
const city = 'Kanpur';
try {
console.log(`\n--- Test 1: getByCity('${city}') ---`);
console.log('This repository method uses explicit sorting by sort_order.');
const schools = await repository.getByCity(city);
if (schools.length > 0) {
console.log('Schools found (sorted by sort_order ASC, then name ASC):');
schools.forEach(school => {
console.log(`- ${school.name} (Sort Order: ${school.sortOrder || 0}, City Code: ${school.cityCode || 'N/A'})`);
});
} else {
console.log('No schools found or error (check database columns).');
}
console.log('\n--- Test 2: searchSchools({}) (Default Sorting) ---');
console.log('This service method tests if the default sortBy is now "sort_order".');
const searchResult = await service.searchSchools({});
const searchSchools = searchResult.schools || searchResult.data?.schools || [];
if (searchSchools.length > 0) {
searchSchools.slice(0, 5).forEach(school => {
console.log(`- ${school.name} (Sort Order: ${school.sortOrder || 0})`);
});
} else {
console.log('No schools found or error (check database columns).');
}
console.log('\nVerification complete. Note: If columns do not exist yet, you will see database errors.');
} catch (error) {
console.error('Error during verification:', error);
}
}
testSorting();