-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-search-api.js
More file actions
executable file
·79 lines (66 loc) · 2.28 KB
/
Copy pathtest-search-api.js
File metadata and controls
executable file
·79 lines (66 loc) · 2.28 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env node
/**
* Test script for Skatehive Search API endpoint
*
* Usage:
* node test-search-api.js <query> [type] [time] [community]
*
* Examples:
* node test-search-api.js skate
* node test-search-api.js skate snaps 1m
* node test-search-api.js "skate hive" users
*/
const API_URL = process.env.API_URL || 'http://localhost:3000';
const query = process.argv[2];
const type = process.argv[3] || 'all';
const time = process.argv[4] || '1y';
const community = process.argv[5] || 'hive-173115';
if (!query) {
console.log(`
Usage: node test-search-api.js <query> [type] [time] [community]
Arguments:
query Search term (required)
type all | users | snaps (default: all)
time 1m | 3m | 1y | all (default: 1y)
community Community ID (default: hive-173115)
Example:
node test-search-api.js skate snaps 1m
`);
process.exit(1);
}
async function testSearch() {
const url = new URL(`${API_URL}/api/v2/search`);
url.searchParams.append('q', query);
url.searchParams.append('type', type);
url.searchParams.append('time', time);
url.searchParams.append('community', community);
console.log(`🧪 Testing GET ${url.toString()}`);
try {
const response = await fetch(url);
const result = await response.json();
if (response.ok) {
console.log('✅ Success!');
if (result.data.users) {
console.log(`\n👤 Users (${result.data.users.length}):`);
result.data.users.slice(0, 5).forEach(u => console.log(` - @${u.name} (Followers: ${u.followers})`));
if (result.data.users.length > 5) console.log(' ...');
} else {
console.log('\n👤 No users found.');
}
if (result.data.snaps) {
console.log(`\n🛹 Snaps (${result.data.snaps.length}):`);
result.data.snaps.slice(0, 5).forEach(s => console.log(` - By @${s.author} on ${s.created}: ${s.body.substring(0, 50).replace(/\n/g, ' ')}...`));
if (result.data.snaps.length > 5) console.log(' ...');
} else {
console.log('\n🛹 No snaps found.');
}
console.log('\n📊 Pagination:', result.pagination);
} else {
console.log('❌ Failed');
console.log('Error:', result.error);
}
} catch (error) {
console.error('❌ Request failed:', error.message);
}
}
testSearch();