-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-api.js
More file actions
78 lines (67 loc) · 2.64 KB
/
test-api.js
File metadata and controls
78 lines (67 loc) · 2.64 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
// Simple API test script
const BASE_URL = 'http://localhost:3000';
async function testAPI() {
console.log('🧪 Testing Albert Heijn Scraper API\n');
try {
// Test 1: Root endpoint
console.log('📋 Test 1: Getting API info...');
const rootResponse = await fetch(BASE_URL);
const rootData = await rootResponse.json();
console.log('✅ API Info:', rootData.name);
console.log('Available endpoints:', Object.keys(rootData.endpoints));
console.log('');
// Test 2: Search products
console.log('🔍 Test 2: Searching for "melk"...');
const searchResponse = await fetch(`${BASE_URL}/api/products/search?q=melk&limit=5`);
const searchData = await searchResponse.json();
if (searchData.success) {
console.log(`✅ Found ${searchData.count} products`);
if (searchData.data.length > 0) {
console.log('First product:', {
name: searchData.data[0].name,
price: searchData.data[0].price,
id: searchData.data[0].id
});
}
} else {
console.log('❌ Search failed:', searchData.error);
}
console.log('');
// Test 3: Get product details (if we have a product)
if (searchData.success && searchData.data.length > 0) {
const productId = searchData.data[0].id;
console.log(`📝 Test 3: Getting details for product ${productId}...`);
const detailsResponse = await fetch(`${BASE_URL}/api/products/${productId}`);
const detailsData = await detailsResponse.json();
if (detailsData.success) {
console.log('✅ Product details retrieved');
console.log('Product:', {
name: detailsData.data.name,
brand: detailsData.data.brand,
price: detailsData.data.price,
hasIngredients: !!detailsData.data.ingredients
});
} else {
console.log('❌ Details failed:', detailsData.error);
}
console.log('');
}
// Test 4: Get categories
console.log('📂 Test 4: Getting categories...');
const categoriesResponse = await fetch(`${BASE_URL}/api/products/categories/list`);
const categoriesData = await categoriesResponse.json();
if (categoriesData.success) {
console.log(`✅ Found ${categoriesData.count} categories`);
if (categoriesData.data.length > 0) {
console.log('First 3 categories:', categoriesData.data.slice(0, 3).map(c => c.name));
}
} else {
console.log('❌ Categories failed:', categoriesData.error);
}
console.log('');
console.log('✨ All API tests completed!');
} catch (error) {
console.error('❌ Test failed:', error.message);
}
}
testAPI();