castad-pre-v0.3/castad-data/test_api.sh

191 lines
7.0 KiB
Bash

#!/bin/bash
BASE_URL="http://localhost:3001"
PASSED=0
FAILED=0
TOTAL=0
echo "================================================"
echo " CaStAD API 종합 테스트 v3.0.0"
echo " (TikTok + Statistics 포함)"
echo "================================================"
echo ""
test_endpoint() {
local name="$1"
local method="$2"
local endpoint="$3"
local expected_code="$4"
local data="$5"
local token="$6"
TOTAL=$((TOTAL + 1))
if [ "$method" = "GET" ]; then
response=$(curl -s -w "\n%{http_code}" ${BASE_URL}${endpoint} -H "Authorization: Bearer $token" 2>/dev/null)
elif [ "$method" = "POST" ]; then
response=$(curl -s -w "\n%{http_code}" -X POST ${BASE_URL}${endpoint} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$data" 2>/dev/null)
elif [ "$method" = "PUT" ]; then
response=$(curl -s -w "\n%{http_code}" -X PUT ${BASE_URL}${endpoint} \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $token" \
-d "$data" 2>/dev/null)
elif [ "$method" = "DELETE" ]; then
response=$(curl -s -w "\n%{http_code}" -X DELETE ${BASE_URL}${endpoint} \
-H "Authorization: Bearer $token" 2>/dev/null)
fi
status_code=$(echo "$response" | tail -n 1)
if [ "$status_code" = "$expected_code" ]; then
echo "✓ PASS: $name"
PASSED=$((PASSED + 1))
else
echo "✗ FAIL: $name (Expected: $expected_code, Got: $status_code)"
FAILED=$((FAILED + 1))
fi
}
echo "=== 1. 인증 모듈 테스트 ==="
echo ""
# Admin 로그인 테스트
response=$(curl -s -w "\n%{http_code}" -X POST ${BASE_URL}/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}' 2>/dev/null)
status=$(echo "$response" | tail -n 1)
body=$(echo "$response" | sed '$d')
ADMIN_TOKEN=$(echo "$body" | grep -o '"token":"[^"]*"' | sed 's/"token":"//;s/"$//')
if [ "$status" = "200" ] && [ -n "$ADMIN_TOKEN" ]; then
echo "✓ PASS: Admin Login"
PASSED=$((PASSED + 1))
else
echo "✗ FAIL: Admin Login (HTTP $status)"
FAILED=$((FAILED + 1))
fi
TOTAL=$((TOTAL + 1))
# 잘못된 로그인
test_endpoint "Invalid Login" "POST" "/api/auth/login" "401" '{"username":"wrong","password":"wrong"}'
echo ""
echo "=== 2. 사용자 관리 API 테스트 ==="
echo ""
test_endpoint "Get User Profile" "GET" "/api/profile" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get All Users (Admin)" "GET" "/api/admin/users" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get Admin Stats" "GET" "/api/admin/stats" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get System Health" "GET" "/api/admin/system-health" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 3. 펜션 관리 API 테스트 ==="
echo ""
test_endpoint "Get User Pensions" "GET" "/api/pensions" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get Pension Limit" "GET" "/api/pensions/limit" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 4. 히스토리 API 테스트 ==="
echo ""
test_endpoint "Get User History" "GET" "/api/history" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get Admin History" "GET" "/api/admin/history" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 5. 크레딧 시스템 API 테스트 ==="
echo ""
test_endpoint "Get Credit Stats (Admin)" "GET" "/api/admin/credits/stats" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get Credit Requests (Admin)" "GET" "/api/admin/credits/requests" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 6. YouTube 연동 API 테스트 ==="
echo ""
test_endpoint "Get YouTube Status" "GET" "/api/youtube/status" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get YouTube Settings" "GET" "/api/youtube/settings" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get YouTube Playlists" "GET" "/api/youtube/playlists" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 7. 에셋 관리 API 테스트 ==="
echo ""
test_endpoint "Get Asset Stats" "GET" "/api/user-assets/stats" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get User Assets" "GET" "/api/user-assets" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 8. 활동 로그 API 테스트 ==="
echo ""
test_endpoint "Get Activity Logs (Admin)" "GET" "/api/admin/logs" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get Upload Logs (Admin)" "GET" "/api/admin/uploads" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 9. 권한 체크 테스트 ==="
echo ""
test_endpoint "Unauthorized Access (No Token)" "GET" "/api/profile" "401"
test_endpoint "Admin Only Endpoint (No Token)" "GET" "/api/admin/users" "401"
echo ""
echo "=== 10. 플랜 관리 API 테스트 ==="
echo ""
test_endpoint "Update User Plan (Admin)" "PUT" "/api/admin/users/1/plan" "200" '{"plan_type":"free","credits":10}' "$ADMIN_TOKEN"
echo ""
echo "=== 11. Instagram 연동 API 테스트 ==="
echo ""
test_endpoint "Get Instagram Status" "GET" "/api/instagram/status" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 12. TikTok 연동 API 테스트 (NEW) ==="
echo ""
test_endpoint "Get TikTok Status" "GET" "/api/tiktok/status" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get TikTok Settings" "GET" "/api/tiktok/settings" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get TikTok History" "GET" "/api/tiktok/history" "200" "" "$ADMIN_TOKEN"
test_endpoint "Get TikTok Stats" "GET" "/api/tiktok/stats" "200" "" "$ADMIN_TOKEN"
echo ""
echo "=== 13. 고급 통계 API 테스트 (NEW) ==="
echo ""
test_endpoint "Analytics Summary" "GET" "/api/admin/analytics/summary" "200" "" "$ADMIN_TOKEN"
test_endpoint "User Growth Trend" "GET" "/api/admin/analytics/user-growth?days=30" "200" "" "$ADMIN_TOKEN"
test_endpoint "Video Generation Trend" "GET" "/api/admin/analytics/video-trend?days=30" "200" "" "$ADMIN_TOKEN"
test_endpoint "Platform Upload Stats" "GET" "/api/admin/analytics/platform-uploads?days=30" "200" "" "$ADMIN_TOKEN"
test_endpoint "Credit Usage Stats" "GET" "/api/admin/analytics/credit-usage?days=30" "200" "" "$ADMIN_TOKEN"
test_endpoint "Plan Distribution" "GET" "/api/admin/analytics/plan-distribution" "200" "" "$ADMIN_TOKEN"
test_endpoint "Top Users" "GET" "/api/admin/analytics/top-users?limit=10" "200" "" "$ADMIN_TOKEN"
test_endpoint "Usage Pattern" "GET" "/api/admin/analytics/usage-pattern" "200" "" "$ADMIN_TOKEN"
test_endpoint "Regional Distribution" "GET" "/api/admin/analytics/regional" "200" "" "$ADMIN_TOKEN"
test_endpoint "Revenue Projection" "GET" "/api/admin/analytics/revenue" "200" "" "$ADMIN_TOKEN"
test_endpoint "System Health (Extended)" "GET" "/api/admin/analytics/system-health" "200" "" "$ADMIN_TOKEN"
test_endpoint "Full Analytics Report" "GET" "/api/admin/analytics/full-report?days=30" "200" "" "$ADMIN_TOKEN"
echo ""
echo "================================================"
echo " 테스트 결과 요약"
echo "================================================"
echo ""
echo " 총 테스트: $TOTAL"
echo " 성공: $PASSED"
echo " 실패: $FAILED"
RATE=$((PASSED * 100 / TOTAL))
echo " 성공률: ${RATE}%"
echo ""
echo "================================================"
if [ $FAILED -eq 0 ]; then
echo " ✓ 모든 테스트 통과!"
else
echo " ✗ 일부 테스트 실패"
fi
echo "================================================"