#!/bin/bash

# Simple Blog API Test - No authentication required first
# Tests public endpoints and basic connectivity

set -e

API_BASE="http://localhost:8000/api"

echo "Testing Blog API Connectivity..."
echo "================================"

# Test 1: Get public blog categories (if available)
echo -e "\n1. Testing blog categories endpoint..."
response=$(curl -s "${API_BASE}/admin/blog-categories" 2>&1 || echo "FAILED")

if [[ "$response" == *"Unauthenticated"* ]] || [[ "$response" == *"unauthorized"* ]]; then
    echo "✓ Endpoint exists (requires authentication)"
elif [[ "$response" == *"success"* ]]; then
    echo "✓ Categories endpoint works"
    echo "Response: $response" | head -c 200
else
    echo "✗ Unexpected response: $response" | head -c 200
fi

# Test 2: Check public blogs listing
echo -e "\n\n2. Testing public blogs endpoint..."
response=$(curl -s "${API_BASE}/blogs")

if echo "$response" | grep -q "success"; then
    echo "✓ Public blogs endpoint works"
    echo "Response: $response" | head -c 200
else
    echo "Response: $response" | head -c 200
fi

echo -e "\n\n================================"
echo "Basic connectivity tests complete"
