|
| 1 | +// Comprehensive System Test Script |
| 2 | +const BASE_URL = 'http://localhost:3000' |
| 3 | + |
| 4 | +async function testAPI(endpoint, method = 'GET', body = null, timeout = 15000) { |
| 5 | + try { |
| 6 | + const controller = new AbortController() |
| 7 | + const timeoutId = setTimeout(() => controller.abort(), timeout) |
| 8 | + |
| 9 | + const options = { |
| 10 | + method, |
| 11 | + headers: { 'Content-Type': 'application/json' }, |
| 12 | + signal: controller.signal |
| 13 | + } |
| 14 | + if (body) options.body = JSON.stringify(body) |
| 15 | + |
| 16 | + const response = await fetch(`${BASE_URL}${endpoint}`, options) |
| 17 | + clearTimeout(timeoutId) |
| 18 | + const data = await response.json() |
| 19 | + return { success: response.ok, status: response.status, data } |
| 20 | + } catch (error) { |
| 21 | + return { success: false, error: error.message } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +async function runTests() { |
| 26 | + console.log('\n🧪 TESTING ANTI-SCAM SYSTEM\n') |
| 27 | + console.log('=' .repeat(50)) |
| 28 | + |
| 29 | + // Test 1: Stats API |
| 30 | + console.log('\n📊 Test 1: Stats API') |
| 31 | + const stats = await testAPI('/api/stats') |
| 32 | + console.log(stats.success ? '✅ PASS' : '❌ FAIL', JSON.stringify(stats.data, null, 2)) |
| 33 | + |
| 34 | + // Test 2: Model Info |
| 35 | + console.log('\n🤖 Test 2: Model Info API') |
| 36 | + const modelInfo = await testAPI('/api/model/info') |
| 37 | + console.log(modelInfo.success ? '✅ PASS' : '❌ FAIL', JSON.stringify(modelInfo.data, null, 2)) |
| 38 | + |
| 39 | + // Test 3: Anonymous Scan (NO AUTH) |
| 40 | + console.log('\n🔍 Test 3: Anonymous Scan (facebook.com)') |
| 41 | + const anonScan = await testAPI('/api/scan-v2', 'POST', { url: 'https://facebook.com' }) |
| 42 | + console.log(anonScan.success ? '✅ PASS' : '❌ FAIL') |
| 43 | + if (anonScan.data) { |
| 44 | + console.log(' - Score:', anonScan.data.data?.score) |
| 45 | + console.log(' - Label:', anonScan.data.data?.label) |
| 46 | + console.log(' - ShareToken:', anonScan.data.data?.shareToken || 'N/A (anonymous)') |
| 47 | + } |
| 48 | + |
| 49 | + // Test 4: Blocklist Check |
| 50 | + console.log('\n🚫 Test 4: Blocklist API') |
| 51 | + const blocklist = await testAPI('/api/blocklist?domain=facebook.com') |
| 52 | + console.log(blocklist.success ? '✅ PASS' : '❌ FAIL', JSON.stringify(blocklist.data, null, 2)) |
| 53 | + |
| 54 | + // Test 5: Guides API |
| 55 | + console.log('\n📚 Test 5: Guides API') |
| 56 | + const guides = await testAPI('/api/guides?page=1&limit=3') |
| 57 | + console.log(guides.success ? '✅ PASS' : '❌ FAIL') |
| 58 | + if (guides.data?.data) { |
| 59 | + console.log(' - Total:', guides.data.data.pagination?.total || 0) |
| 60 | + console.log(' - Categories:', guides.data.data.categories?.length || 0) |
| 61 | + } |
| 62 | + |
| 63 | + // Test 6: Invalid/Suspicious URL Scan |
| 64 | + console.log('\n⚠️ Test 6: Invalid Domain Scan') |
| 65 | + const invalidScan = await testAPI('/api/scan-v2', 'POST', { url: 'not-a-valid-url' }) |
| 66 | + console.log(invalidScan.success ? '✅ PASS' : '❌ FAIL') |
| 67 | + if (invalidScan.data?.data) { |
| 68 | + console.log(' - Score:', invalidScan.data.data.score) |
| 69 | + console.log(' - Label:', invalidScan.data.data.label, '(AI correctly identifies invalid domain)') |
| 70 | + } |
| 71 | + |
| 72 | + // Test 7: Dangerous URL Scan (with longer timeout) |
| 73 | + console.log('\n🚨 Test 7: Suspicious URL Scan') |
| 74 | + const dangerScan = await testAPI('/api/scan-v2', 'POST', { url: 'http://suspicious-link.tk/login' }, 30000) |
| 75 | + console.log(dangerScan.success ? '✅ PASS' : '❌ FAIL') |
| 76 | + if (dangerScan.success && dangerScan.data?.data) { |
| 77 | + console.log(' - Score:', dangerScan.data.data.score) |
| 78 | + console.log(' - Label:', dangerScan.data.data.label) |
| 79 | + console.log(' - Reasons:', dangerScan.data.data.reasons?.slice(0, 2)) |
| 80 | + } else if (dangerScan.error) { |
| 81 | + console.log(' - Error:', dangerScan.error) |
| 82 | + } |
| 83 | + |
| 84 | + console.log('\n' + '='.repeat(50)) |
| 85 | + console.log('✨ TEST COMPLETED\n') |
| 86 | +} |
| 87 | + |
| 88 | +// Run tests |
| 89 | +runTests().catch(console.error) |
0 commit comments