#!/bin/bash
# =====================================================================
# test-csv-tool.sh - Test the CSV tool functionality
# =====================================================================
# This script checks if the CSV tool page loads without CSP errors
# =====================================================================

echo "=== Testing CSV Tool ==="

# Create a test CSV file
echo "Name,Age,City
John,30,New York
Jane,25,San Francisco
Bob,40,Chicago" > test.csv

# Check if the page loads properly
echo "Checking if the CSV tool page loads properly..."
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080/one-pager-tools/csv-tool.html)

if [ "$RESPONSE" -eq 200 ]; then
    echo "✅ CSV tool page loads successfully (HTTP $RESPONSE)"
else
    echo "❌ CSV tool page failed to load (HTTP $RESPONSE)"
    exit 1
fi

# Check for CSP errors in the response headers
echo "Checking for CSP errors in response headers..."
CSP_HEADER=$(curl -s -I http://localhost:8080/one-pager-tools/csv-tool.html | grep -i "Content-Security-Policy")

if [ -n "$CSP_HEADER" ]; then
    echo "✅ CSP header found in response"
else
    echo "❌ CSP header not found in response"
    exit 1
fi

# Clean up
rm -f test.csv

echo "=== CSV Tool Test Completed Successfully ==="
echo "The CSV tool appears to be working correctly."
echo "You can manually test it by visiting: http://localhost:8080/one-pager-tools/csv-tool.html"
echo "and pasting CSV data into the textarea." 