#!/bin/bash # RFCP Backend Smoke Test # Usage: ./rfcp-backend-smoke-test.sh [base_url] BASE_URL="${1:-https://api.rfcp.eliah.one}" PASSED=0 FAILED=0 # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo " RFCP Backend Smoke Test" echo " Target: $BASE_URL" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "" test_endpoint() { local name="$1" local method="$2" local endpoint="$3" local expected="$4" local data="$5" if [ "$method" == "GET" ]; then response=$(curl -s "$BASE_URL$endpoint") else response=$(curl -s -X "$method" "$BASE_URL$endpoint" \ -H "Content-Type: application/json" \ -d "$data") fi if echo "$response" | grep -q "$expected"; then echo -e "${GREEN}✓${NC} $name" ((PASSED++)) else echo -e "${RED}✗${NC} $name" echo " Expected: $expected" echo " Got: $response" ((FAILED++)) fi } # 1. Root test_endpoint "Root endpoint" "GET" "/" "RFCP Backend API" # 2. Health test_endpoint "Health check" "GET" "/api/health/" '"status":"ok"' # 3. Database test_endpoint "Database connection" "GET" "/api/health/db" '"database":"connected"' # 4. Get project (auto-creates) test_endpoint "Get global project" "GET" "/api/projects/current" '"name":"global"' # 5. Get settings test_endpoint "Get coverage settings" "GET" "/api/projects/current/settings" '"radius"' # 6. PUT sites test_endpoint "Update sites" "PUT" "/api/projects/current/sites" '"updated"' \ '[{"id":"smoke-test","name":"Smoke Test Site","lat":48.5,"lon":35.0,"height":30,"power":43}]' # 7. GET sites (verify write) test_endpoint "Verify sites saved" "GET" "/api/projects/current/sites" "Smoke Test Site" # 8. PUT settings test_endpoint "Update settings" "PUT" "/api/projects/current/settings" '"radius":15000' \ '{"radius":15000,"resolution":200,"min_signal":-105,"max_signal":-65}' # 9. Swagger docs swagger_response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/docs") if [ "$swagger_response" == "200" ]; then echo -e "${GREEN}✓${NC} Swagger UI accessible" ((PASSED++)) else echo -e "${RED}✗${NC} Swagger UI (HTTP $swagger_response)" ((FAILED++)) fi # 10. OpenAPI schema test_endpoint "OpenAPI schema" "GET" "/openapi.json" '"openapi"' # Cleanup - restore default settings curl -s -X PUT "$BASE_URL/api/projects/current/settings" \ -H "Content-Type: application/json" \ -d '{"radius":10000,"resolution":200,"min_signal":-105,"max_signal":-65}' > /dev/null echo "" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" if [ $FAILED -eq 0 ]; then echo -e " ${GREEN}All tests passed!${NC} ($PASSED/$((PASSED+FAILED)))" else echo -e " ${YELLOW}Results:${NC} ${GREEN}$PASSED passed${NC}, ${RED}$FAILED failed${NC}" fi echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" exit $FAILED