Files
chat/tests/simple_test.sh
Andrew K. Choi 64171196b6
All checks were successful
continuous-integration/drone/push Build is passing
calendar features
2025-09-26 14:45:00 +09:00

108 lines
4.1 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Простой тест Emergency Service API
# Тестирование только работающих endpoints
# Цвета для вывода
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
success() { echo -e "${GREEN}$1${NC}"; }
error() { echo -e "${RED}$1${NC}"; }
info() { echo -e "${BLUE} $1${NC}"; }
BASE_URL="http://127.0.0.1:8002"
USER_URL="http://127.0.0.1:8001"
# Получение токена
info "1. Получение токена авторизации..."
LOGIN_RESPONSE=$(curl -s -X POST "${USER_URL}/api/v1/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"apitestuser","password":"testpass123"}')
TOKEN=$(echo "$LOGIN_RESPONSE" | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['access_token'])" 2>/dev/null)
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
error "Ошибка получения токена"
echo "$LOGIN_RESPONSE"
exit 1
fi
success "Токен получен: ${TOKEN:0:20}..."
# Тест 1: Health Check
info "2. Проверка работы сервиса..."
HEALTH_RESPONSE=$(curl -s "${BASE_URL}/health")
if echo "$HEALTH_RESPONSE" | grep -q "healthy"; then
success "Health Check прошел"
else
error "Health Check не прошел: $HEALTH_RESPONSE"
fi
# Тест 2: Создание оповещения
info "3. Создание экстренного оповещения..."
ALERT_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/v1/alert" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"latitude": 55.7558,
"longitude": 37.6176,
"alert_type": "general",
"message": "API тест - экстренное оповещение"
}')
ALERT_ID=$(echo "$ALERT_RESPONSE" | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['id'])" 2>/dev/null)
if [ -n "$ALERT_ID" ] && [ "$ALERT_ID" != "null" ]; then
success "Оповещение создано с ID: $ALERT_ID"
else
error "Ошибка создания оповещения: $ALERT_RESPONSE"
fi
# Тест 3: Получение статистики
info "4. Получение статистики..."
STATS_RESPONSE=$(curl -s -X GET "${BASE_URL}/api/v1/stats" \
-H "Authorization: Bearer $TOKEN")
if echo "$STATS_RESPONSE" | grep -q "total_alerts"; then
success "Статистика получена"
echo "$STATS_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$STATS_RESPONSE"
else
error "Ошибка получения статистики: $STATS_RESPONSE"
fi
# Тест 4: Поиск ближайших оповещений
info "5. Поиск ближайших оповещений..."
NEARBY_RESPONSE=$(curl -s -X GET "${BASE_URL}/api/v1/alerts/nearby?latitude=55.7558&longitude=37.6176&radius_km=10" \
-H "Authorization: Bearer $TOKEN")
if echo "$NEARBY_RESPONSE" | grep -q "distance_km"; then
success "Ближайшие оповещения найдены"
echo "$NEARBY_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$NEARBY_RESPONSE"
else
error "Ошибка поиска ближайших оповещений: $NEARBY_RESPONSE"
fi
# Тест 5: Отклик на оповещение (если есть ID)
if [ -n "$ALERT_ID" ] && [ "$ALERT_ID" != "null" ]; then
info "6. Создание отклика на оповещение..."
RESPONSE_DATA=$(curl -s -X POST "${BASE_URL}/api/v1/alert/${ALERT_ID}/respond" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"response_type": "help_on_way",
"message": "Еду на помощь!",
"eta_minutes": 10
}')
if echo "$RESPONSE_DATA" | grep -q "response_type"; then
success "Отклик на оповещение создан"
echo "$RESPONSE_DATA" | python3 -m json.tool 2>/dev/null || echo "$RESPONSE_DATA"
else
error "Ошибка создания отклика: $RESPONSE_DATA"
fi
fi
info "Тестирование завершено!"