#!/bin/sh

echo "Testing DNS-over-HTTPS JSON API"
echo "================================"

# Test A record query
printf "Testing A record for example.com: "
curl -s -H "Accept: application/dns-json" "http://127.0.0.1:3000/dns-query?name=example.com&type=1" | jq -r '.Answer[0].data' 2>/dev/null || echo "Failed"

# Test with type parameter omitted (should default to A)
printf "Testing default type (A) for example.com: "
curl -s -H "Accept: application/dns-json" "http://127.0.0.1:3000/dns-query?name=example.com" | jq -r '.Answer[0].data' 2>/dev/null || echo "Failed"

# Test AAAA record
printf "Testing AAAA record for example.com: "
curl -s -H "Accept: application/dns-json" "http://127.0.0.1:3000/dns-query?name=example.com&type=28" | jq -r '.Answer[0].data' 2>/dev/null || echo "Failed"

# Test with CD flag
printf "Testing with CD flag: "
curl -s -H "Accept: application/dns-json" "http://127.0.0.1:3000/dns-query?name=example.com&cd=1" | jq -r '.CD' 2>/dev/null || echo "Failed"

# Test error case - missing name parameter
printf "Testing error case (missing name): "
curl -s -H "Accept: application/dns-json" "http://127.0.0.1:3000/dns-query?type=1" | jq -r '.Comment' 2>/dev/null || echo "Failed"

echo ""
echo "Full response example:"
curl -s -H "Accept: application/dns-json" "http://127.0.0.1:3000/dns-query?name=example.com&type=1" | jq . 2>/dev/null || echo "Failed to get response"