#!/bin/bash
# Quick API Test for Normogen Backend
# Updated for port 6500

echo "🧪 Quick API Test - Normogen Backend"
echo "===================================="
echo ""

echo "1. Health Check..."
curl -s http://10.0.10.30:6500/health | jq .
echo ""

echo "2. Login Test..."
RESPONSE=$(curl -s -X POST http://10.0.10.30:6500/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email": "recoverytest@example.com", "password": "NewSecurePassword456!"}')
echo "$RESPONSE" | jq .

# Extract token
TOKEN=$(echo "$RESPONSE" | jq -r '.access_token // .access_token // empty')
echo ""

if [ -n "$TOKEN" ] && [ "$TOKEN" != "null" ]; then
    echo "3. Protected Endpoint (with token)..."
    curl -s -X GET http://10.0.10.30:6500/api/users/me \
      -H "Authorization: Bearer $TOKEN" | jq .
else
    echo "3. Protected Endpoint (no token - should fail)..."
    curl -s -X GET http://10.0.10.30:6500/api/users/me | jq .
fi

echo ""
echo "✅ Test complete!"
