// Simple API test without authentication
async function testAPI() {
  console.log('🧪 TESTING API WITHOUT AUTHENTICATION');
  console.log('====================================');
  console.log('');

  try {
    // Test 1: Health check
    console.log('1. Testing health endpoint...');
    const healthResponse = await fetch('http://localhost:5000/api/health');
    if (healthResponse.ok) {
      const healthData = await healthResponse.json();
      console.log('   ✅ Server is running:', healthData.message);
    } else {
      console.log('   ❌ Health check failed:', healthResponse.status);
    }
    console.log('');

    // Test 2: Users endpoint without auth
    console.log('2. Testing users endpoint without authentication...');
    const usersResponse = await fetch('http://localhost:5000/api/users');
    console.log('   📊 Response status:', usersResponse.status);
    
    if (usersResponse.status === 401) {
      console.log('   ✅ Authentication required (expected)');
    } else {
      const responseText = await usersResponse.text();
      console.log('   ⚠️ Unexpected response:', responseText);
    }
    console.log('');

    // Test 3: Try with mock token
    console.log('3. Testing with mock token...');
    const mockResponse = await fetch('http://localhost:5000/api/users', {
      headers: {
        'Authorization': 'Bearer mock-token',
        'Content-Type': 'application/json'
      }
    });
    console.log('   📊 Mock token response status:', mockResponse.status);
    
    if (mockResponse.status === 401) {
      console.log('   ✅ Invalid token rejected (expected)');
    } else {
      const mockText = await mockResponse.text();
      console.log('   ⚠️ Unexpected response:', mockText);
    }
    console.log('');

    console.log('====================================');
    console.log('✅ API TEST COMPLETE');
    console.log('');
    console.log('💡 NEXT STEPS:');
    console.log('   1. Login through frontend to get valid token');
    console.log('   2. Check browser console for detailed logs');
    console.log('   3. Verify token is being sent in requests');

  } catch (error) {
    console.error('❌ Error testing API:', error.message);
    console.log('');
    console.log('💡 POSSIBLE ISSUES:');
    console.log('   - Backend server not running on port 5000');
    console.log('   - Network connection problem');
    console.log('   - CORS issue');
  }
}

testAPI();
