Files
finance_bot/test_api.sh

94 lines
2.4 KiB
Bash
Executable File
Raw Permalink 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.

#!/bin/bash
# Test Bot API Endpoints
API_BASE_URL="http://localhost:8000"
CHAT_ID=556399210
echo "🧪 Finance Bot API Tests"
echo "========================"
echo ""
# Test 1: Register new email user
echo "1⃣ Register with Email"
echo "Request: POST /api/v1/auth/register"
curl -s -X POST "$API_BASE_URL/api/v1/auth/register" \
-H "Content-Type: application/json" \
-d '{
"email": "test.user@example.com",
"password": "TestPassword123",
"first_name": "Test",
"last_name": "User"
}' | jq '.' || echo "Failed"
echo ""
echo "---"
echo ""
# Test 2: Get token for Telegram user
echo "2⃣ Get Token for Telegram User"
echo "Request: POST /api/v1/auth/token/get"
TOKEN_RESPONSE=$(curl -s -X POST "$API_BASE_URL/api/v1/auth/token/get" \
-H "Content-Type: application/json" \
-d "{\"chat_id\": $CHAT_ID}")
echo "$TOKEN_RESPONSE" | jq '.' || echo "Failed"
# Extract token for next test
TOKEN=$(echo "$TOKEN_RESPONSE" | jq -r '.access_token // empty')
echo ""
echo "---"
echo ""
# Test 3: Quick Telegram registration
echo "3⃣ Quick Telegram Registration"
echo "Request: POST /api/v1/auth/telegram/register"
REG_RESPONSE=$(curl -s -X POST "$API_BASE_URL/api/v1/auth/telegram/register" \
-H "Content-Type: application/json" \
-d "" \
-G \
--data-urlencode "chat_id=$CHAT_ID" \
--data-urlencode "username=john_doe" \
--data-urlencode "first_name=John")
echo "$REG_RESPONSE" | jq '.' || echo "Failed"
# Extract JWT token if registration successful
JWT_TOKEN=$(echo "$REG_RESPONSE" | jq -r '.jwt_token // empty')
echo ""
echo "---"
echo ""
# Test 4: Health check
echo "4⃣ Health Check"
echo "Request: GET /health"
curl -s -X GET "$API_BASE_URL/health" | jq '.' || echo "Failed"
echo ""
echo "---"
echo ""
# Test 5: Make authenticated request (if we have a token)
if [ ! -z "$TOKEN" ]; then
echo "5⃣ Authenticated Request (with token)"
echo "Request: GET /api/v1/accounts"
echo "Authorization: Bearer $TOKEN"
curl -s -X GET "$API_BASE_URL/api/v1/accounts" \
-H "Authorization: Bearer $TOKEN" | jq '.' || echo "Failed"
echo ""
else
echo "5⃣ Authenticated Request - Skipped (no token)"
fi
echo ""
echo "---"
echo ""
echo "✅ Tests Complete"
echo ""
echo "📝 Notes:"
echo "- Replace http://localhost:8000 with your API URL"
echo "- You need jq installed: sudo apt install jq"
echo "- Check logs: docker logs finance_bot_web"
echo "- Check Redis: redis-cli get \"chat_id:$CHAT_ID:jwt\""