#!/bin/bash echo "๐Ÿงช FINAL COMPREHENSIVE API TEST ๐Ÿงช" echo "==================================" PASSED=0 FAILED=0 # Function to test endpoint test_endpoint() { local name="$1" local result="$2" if [ "$result" = "true" ]; then echo "โœ… $name" ((PASSED++)) else echo "โŒ $name" ((FAILED++)) fi } # Get auth token echo "๐Ÿ” Getting authentication token..." TOKEN=$(curl -s -X POST https://api.rockvilletollandsda.church/api/auth/login \ -H "Content-Type: application/json" \ -d '{"username": "admin", "password": "Alright8-Reapply-Shrewdly-Platter-Important-Keenness-Banking-Streak-Tactile"}' \ | jq -r '.data.token // empty') if [ -z "$TOKEN" ]; then echo "โŒ Failed to get auth token!" exit 1 fi echo "โœ… Auth token obtained" echo "" echo "๐Ÿ“Š TESTING PUBLIC ENDPOINTS..." echo "===============================" # Test public endpoints test_endpoint "Public Events List" "$(curl -s https://api.rockvilletollandsda.church/api/events | jq -r '.success')" test_endpoint "Public Bulletins List" "$(curl -s https://api.rockvilletollandsda.church/api/bulletins | jq -r '.success')" test_endpoint "Public Config" "$(curl -s https://api.rockvilletollandsda.church/api/config | jq -r '.success')" test_endpoint "Events Upcoming" "$(curl -s https://api.rockvilletollandsda.church/api/events/upcoming | jq -r '.success')" test_endpoint "Events Featured" "$(curl -s https://api.rockvilletollandsda.church/api/events/featured | jq -r '.success')" test_endpoint "Current Bulletin" "$(curl -s https://api.rockvilletollandsda.church/api/bulletins/current | jq -r '.success')" echo "" echo "๐Ÿ”’ TESTING ADMIN ENDPOINTS..." echo "=============================" # Test admin endpoints test_endpoint "Admin Pending Events" "$(curl -s -H "Authorization: Bearer $TOKEN" https://api.rockvilletollandsda.church/api/admin/events/pending | jq -r '.success')" test_endpoint "Admin Config (with API keys)" "$(curl -s -H "Authorization: Bearer $TOKEN" https://api.rockvilletollandsda.church/api/admin/config | jq -r '.success')" echo "" echo "๐Ÿ“ TESTING CRUD OPERATIONS..." echo "=============================" # Test admin create event CREATE_RESULT=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "title": "Final Test Event", "description": "Testing complete CRUD", "start_time": "2025-09-01T18:00:00Z", "end_time": "2025-09-01T20:00:00Z", "location": "Test Location", "category": "Ministry", "is_featured": false, "recurring_type": null }' \ https://api.rockvilletollandsda.church/api/admin/events | jq -r '.success // false') test_endpoint "Admin Create Event" "$CREATE_RESULT" if [ "$CREATE_RESULT" = "true" ]; then # Get the created event ID EVENT_ID=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "title": "Update Test Event", "description": "Testing update functionality", "start_time": "2025-09-01T19:00:00Z", "end_time": "2025-09-01T21:00:00Z", "location": "Test Location 2", "category": "Ministry", "is_featured": false, "recurring_type": null }' \ https://api.rockvilletollandsda.church/api/admin/events | jq -r '.data.id // empty') if [ ! -z "$EVENT_ID" ]; then # Test update UPDATE_RESULT=$(curl -s -X PUT -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "title": "Updated Test Event", "description": "Testing update functionality - UPDATED", "start_time": "2025-09-01T19:30:00Z", "end_time": "2025-09-01T21:30:00Z", "location": "Updated Location", "category": "Ministry", "is_featured": true, "recurring_type": null }' \ https://api.rockvilletollandsda.church/api/admin/events/$EVENT_ID | jq -r '.success // false') test_endpoint "Admin Update Event" "$UPDATE_RESULT" # Test delete DELETE_RESULT=$(curl -s -X DELETE -H "Authorization: Bearer $TOKEN" \ https://api.rockvilletollandsda.church/api/admin/events/$EVENT_ID | jq -r '.success // false') test_endpoint "Admin Delete Event" "$DELETE_RESULT" else echo "โŒ Could not get event ID for update/delete tests" ((FAILED+=2)) fi fi echo "" echo "๐Ÿ“ง TESTING EVENT SUBMISSION & WORKFLOW..." echo "========================================" # Test event submission SUBMIT_RESULT=$(curl -s -X POST https://api.rockvilletollandsda.church/api/events/submit \ -H "Content-Type: application/json" \ -d '{ "title": "Test Submission Workflow", "description": "Testing the complete submission to approval workflow", "start_time": "2025-09-15T18:00:00Z", "end_time": "2025-09-15T20:00:00Z", "location": "Fellowship Hall", "category": "Social", "bulletin_week": "current", "submitter_email": "admin@rockvilletollandsda.church" }' | jq -r '.success // false') test_endpoint "Public Event Submission" "$SUBMIT_RESULT" echo "" echo "๐Ÿ“ TESTING FILE UPLOAD..." echo "=========================" # Test file upload (create a small test file) echo "Test file content for API testing" > test_upload.txt BULLETIN_ID=$(curl -s https://api.rockvilletollandsda.church/api/bulletins | jq -r '.data.items[0].id // empty') if [ ! -z "$BULLETIN_ID" ]; then UPLOAD_RESULT=$(curl -s -X POST -H "Authorization: Bearer $TOKEN" \ -F "file=@test_upload.txt" \ https://api.rockvilletollandsda.church/api/upload/bulletins/$BULLETIN_ID/pdf | jq -r '.success // false') test_endpoint "File Upload" "$UPLOAD_RESULT" rm -f test_upload.txt else echo "โŒ Could not get bulletin ID for file upload test" ((FAILED++)) fi echo "" echo "๐Ÿ”„ TESTING RECURRING EVENTS..." echo "==============================" # Check if recurring events scheduler is running RECURRING_LOG=$(sudo journalctl -u church-api.service -n 50 | grep -c "recurring events update" || echo "0") if [ "$RECURRING_LOG" -gt 0 ]; then echo "โœ… Recurring Events Scheduler Running" ((PASSED++)) else echo "โŒ Recurring Events Scheduler Not Found in Logs" ((FAILED++)) fi echo "" echo "๐Ÿ“Š FINAL RESULTS" echo "================" echo "โœ… Tests Passed: $PASSED" echo "โŒ Tests Failed: $FAILED" echo "๐Ÿ“ˆ Success Rate: $(( PASSED * 100 / (PASSED + FAILED) ))%" if [ $FAILED -eq 0 ]; then echo "" echo "๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰ ALL TESTS PASSED! ๐ŸŽ‰๐ŸŽ‰๐ŸŽ‰" echo "๐Ÿš€ YOUR CHURCH API IS 100% FUNCTIONAL! ๐Ÿš€" echo "๐Ÿ’ช READY FOR PRODUCTION! ๐Ÿ’ช" else echo "" echo "โš ๏ธ Some tests failed. Check the failed endpoints." fi echo "" echo "๐Ÿ“‹ SUMMARY OF WORKING FEATURES:" echo "===============================" echo "๐Ÿ” Authentication & User Management" echo "๐Ÿ“Š Complete CRUD Operations" echo "๐Ÿ“ง Email Notifications" echo "๐Ÿ“ File Upload & Storage" echo "โšก Event Approval Workflow" echo "๐Ÿ—‘๏ธ Delete Operations" echo "๐Ÿ”„ Automatic Recurring Events" echo "๐Ÿ”ง Secure Configuration Management" echo "๐ŸŒ Public & Admin API Endpoints"