Files
maps-saas/apps/api/scripts/test_autocomplete.ts
T

37 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import axios from 'axios';
const API_URL = process.env.TEST_API_URL || 'http://localhost:3200/api/geocoding/autocomplete';
const API_KEY = process.env.TEST_API_KEY || 'zP9vL5mK2nQ8xR7jT4wS1yB6hG3fV0cX';
const testQueries = [
"مستش",
"شارع ال",
"جامعة",
"بنك ا",
"صيد"
];
async function testAutocomplete() {
console.log(`🚀 Testing Autocomplete Latency`);
for (const q of testQueries) {
const start = Date.now();
try {
const res = await axios.get(API_URL, {
headers: { 'x-api-key': API_KEY },
params: { q, country: 'syria' }
});
const time = Date.now() - start;
const count = res.data.results?.length || 0;
console.log(`✅ [${time}ms] Query: "${q}" -> ${count} results`);
if (count > 0) {
console.log(` First result: ${res.data.results[0].name} (${res.data.results[0].category})`);
}
} catch (e: any) {
console.log(`❌ Query: "${q}" failed:`, e.message);
}
}
}
testAutocomplete().catch(console.error);