144 lines
3.6 KiB
Bash
Executable File
144 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
# Smoke tests for Moyos Wedding App
|
|
# Usage: ./smoke-tests.sh [--base-url URL]
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
log() {
|
|
echo -e "${GREEN}[PASS]${NC} $1"
|
|
}
|
|
|
|
error() {
|
|
echo -e "${RED}[FAIL]${NC} $1" >&2
|
|
}
|
|
|
|
warn() {
|
|
echo -e "${YELLOW}[WARN]${NC} $1"
|
|
}
|
|
|
|
info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
# Configuration
|
|
BASE_URL="${1:-${BASE_URL:-http://localhost:3000}}"
|
|
if [ "$1" = "--base-url" ] && [ -n "$2" ]; then
|
|
BASE_URL="$2"
|
|
fi
|
|
|
|
# Track failures
|
|
FAILURES=0
|
|
TESTS=0
|
|
|
|
test_endpoint() {
|
|
TESTS=$((TESTS + 1))
|
|
local endpoint="$1"
|
|
local expected_status="${2:-200}"
|
|
local description="${3:-$endpoint}"
|
|
|
|
info "Testing: $description"
|
|
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$BASE_URL$endpoint" 2>/dev/null || echo "000")
|
|
|
|
if [ "$HTTP_CODE" = "$expected_status" ]; then
|
|
log "$description (HTTP $HTTP_CODE)"
|
|
return 0
|
|
else
|
|
error "$description (HTTP $HTTP_CODE, expected $expected_status)"
|
|
FAILURES=$((FAILURES + 1))
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
echo "Running smoke tests for Moyos Wedding App..."
|
|
echo "Base URL: $BASE_URL"
|
|
echo ""
|
|
|
|
# Test 1: Health endpoint
|
|
test_endpoint "/api/health" "200" "Health check endpoint"
|
|
|
|
# Test 2: Landing page
|
|
test_endpoint "/" "200" "Landing page"
|
|
|
|
# Test 3: Wedding page
|
|
test_endpoint "/wedding" "200" "Wedding page"
|
|
|
|
# Test 4: RSVP page (may require auth)
|
|
test_endpoint "/rsvp" "200" "RSVP page"
|
|
|
|
# Test 5: Admin login page
|
|
test_endpoint "/admin/login" "200" "Admin login page"
|
|
|
|
# Test 6: API health
|
|
test_endpoint "/api/health" "200" "API health endpoint"
|
|
|
|
# Test 7: Metrics endpoint (may be restricted)
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$BASE_URL/api/metrics" 2>/dev/null || echo "000")
|
|
if [ "$HTTP_CODE" = "200" ] || [ "$HTTP_CODE" = "403" ] || [ "$HTTP_CODE" = "401" ]; then
|
|
log "Metrics endpoint accessible (HTTP $HTTP_CODE)"
|
|
else
|
|
warn "Metrics endpoint returned HTTP $HTTP_CODE"
|
|
fi
|
|
|
|
# Test 8: Static assets
|
|
test_endpoint "/favicon.ico" "200" "Favicon"
|
|
|
|
# Test 9: API routes (should not return 500)
|
|
info "Testing API routes..."
|
|
API_ENDPOINTS=(
|
|
"/api/health"
|
|
"/api/music"
|
|
"/api/guestbook"
|
|
)
|
|
|
|
for endpoint in "${API_ENDPOINTS[@]}"; do
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$BASE_URL$endpoint" 2>/dev/null || echo "000")
|
|
if [ "$HTTP_CODE" -ge 500 ]; then
|
|
error "$endpoint returned server error (HTTP $HTTP_CODE)"
|
|
FAILURES=$((FAILURES + 1))
|
|
elif [ "$HTTP_CODE" -ge 400 ] && [ "$HTTP_CODE" -lt 500 ]; then
|
|
# 4xx errors are acceptable (auth required, etc.)
|
|
log "$endpoint (HTTP $HTTP_CODE - client error, acceptable)"
|
|
else
|
|
log "$endpoint (HTTP $HTTP_CODE)"
|
|
fi
|
|
done
|
|
|
|
# Test 10: Response time check
|
|
info "Checking response times..."
|
|
RESPONSE_TIME=$(curl -s -o /dev/null -w "%{time_total}" --max-time 10 "$BASE_URL/api/health" 2>/dev/null || echo "999")
|
|
RESPONSE_TIME_MS=$(echo "$RESPONSE_TIME * 1000" | bc | cut -d. -f1)
|
|
|
|
if [ "$RESPONSE_TIME_MS" -lt 1000 ]; then
|
|
log "Response time: ${RESPONSE_TIME_MS}ms (good)"
|
|
elif [ "$RESPONSE_TIME_MS" -lt 3000 ]; then
|
|
warn "Response time: ${RESPONSE_TIME_MS}ms (acceptable)"
|
|
else
|
|
error "Response time: ${RESPONSE_TIME_MS}ms (slow)"
|
|
FAILURES=$((FAILURES + 1))
|
|
fi
|
|
|
|
# Summary
|
|
echo ""
|
|
echo "Smoke Test Summary:"
|
|
echo " Total tests: $TESTS"
|
|
echo " Passed: $((TESTS - FAILURES))"
|
|
echo " Failed: $FAILURES"
|
|
|
|
if [ $FAILURES -eq 0 ]; then
|
|
echo ""
|
|
log "All smoke tests passed! ✅"
|
|
exit 0
|
|
else
|
|
echo ""
|
|
error "Some smoke tests failed. Please review the errors above."
|
|
exit 1
|
|
fi
|