40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
import axios from 'axios';
|
|
import { Client } from 'pg';
|
|
|
|
const API_URL = process.env.TEST_API_URL || 'http://localhost:3200/api/geocoding/search';
|
|
const API_KEY = process.env.TEST_API_KEY || 'zP9vL5mK2nQ8xR7jT4wS1yB6hG3fV0cX';
|
|
const DB_URL = process.env.DATABASE_URL || 'postgresql://mapuser:TestMapPass123!@localhost:5432/mapdb';
|
|
|
|
async function testFailedLogging() {
|
|
console.log(`🚀 Testing Failed Searches Logging`);
|
|
const fakeQuery = 'مكان_غير_موجود_في_العالم_ابدا';
|
|
|
|
// 1. Trigger the search (should return 0 results)
|
|
try {
|
|
const res = await axios.get(API_URL, {
|
|
headers: { 'x-api-key': API_KEY },
|
|
params: { q: fakeQuery, country: 'syria' }
|
|
});
|
|
console.log(`✅ Search triggered. Results count: ${res.data.results?.length}`);
|
|
} catch (e: any) {
|
|
console.log(`❌ Search failed:`, e.message);
|
|
}
|
|
|
|
// Wait a second for async DB insert
|
|
await new Promise(r => setTimeout(r, 1000));
|
|
|
|
// 2. Check the database directly
|
|
const client = new Client({ connectionString: DB_URL });
|
|
await client.connect();
|
|
const dbRes = await client.query('SELECT * FROM failed_searches WHERE query_text = $1', [fakeQuery]);
|
|
await client.end();
|
|
|
|
if (dbRes.rows.length > 0) {
|
|
console.log(`✅ SUCCESS! Log found in DB:`, dbRes.rows[0].query_text, `(Count: ${dbRes.rows[0].search_count})`);
|
|
} else {
|
|
console.log(`❌ FAILURE! No log found in DB for the query.`);
|
|
}
|
|
}
|
|
|
|
testFailedLogging().catch(console.error);
|