#!/bin/bash # Test script for newsletter API endpoints echo "==========================================" echo "Newsletter API Test" echo "==========================================" echo "" BASE_URL="http://localhost:5001" # Test 1: Get stats echo "Test 1: Get system stats" echo "GET $BASE_URL/api/admin/stats" curl -s $BASE_URL/api/admin/stats | python3 -m json.tool | grep -A 3 "subscribers" echo "" # Test 2: Send test email echo "Test 2: Send test email" read -p "Enter your email address for test: " TEST_EMAIL if [ -n "$TEST_EMAIL" ]; then echo "POST $BASE_URL/api/admin/send-test-email" curl -s -X POST $BASE_URL/api/admin/send-test-email \ -H "Content-Type: application/json" \ -d "{\"email\": \"$TEST_EMAIL\", \"max_articles\": 2}" | python3 -m json.tool echo "" else echo "Skipped (no email provided)" echo "" fi # Test 3: Send newsletter to all subscribers echo "Test 3: Send newsletter to all subscribers" read -p "Send newsletter to all active subscribers? (y/N): " CONFIRM if [ "$CONFIRM" = "y" ] || [ "$CONFIRM" = "Y" ]; then echo "POST $BASE_URL/api/admin/send-newsletter" curl -s -X POST $BASE_URL/api/admin/send-newsletter \ -H "Content-Type: application/json" \ -d '{"max_articles": 5}' | python3 -m json.tool echo "" else echo "Skipped" echo "" fi echo "==========================================" echo "Test Complete" echo "=========================================="