44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
const axios = require('axios');
|
|
|
|
// Test script to simulate frontend author search behavior
|
|
async function testAuthorSearch() {
|
|
const BASE_URL = 'http://localhost:6925';
|
|
|
|
try {
|
|
// First, try to login to get a token
|
|
console.log('Attempting to login...');
|
|
const loginResponse = await axios.post(`${BASE_URL}/api/auth/login`, {
|
|
password: 'kLJq8QJx-@.eCk.uZJwPdbQ!JyJ6Yy_8'
|
|
});
|
|
|
|
console.log('Login response:', loginResponse.data);
|
|
|
|
// Extract token from response
|
|
const token = loginResponse.data.token;
|
|
|
|
if (token) {
|
|
console.log('Token received, testing author search...');
|
|
|
|
// Test author search with "shop" query
|
|
const searchResponse = await axios.get(`${BASE_URL}/api/authors/search-typesense`, {
|
|
params: {
|
|
q: 'shop',
|
|
page: 0,
|
|
size: 20
|
|
},
|
|
headers: {
|
|
'Authorization': `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
console.log('Search results for "shop":');
|
|
console.log('Total hits:', searchResponse.data.totalHits);
|
|
console.log('Results:', searchResponse.data.results.map(r => r.name));
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('Error:', error.response?.data || error.message);
|
|
}
|
|
}
|
|
|
|
testAuthorSearch(); |