Files
chat/test-api-fix.sh
2026-04-25 16:36:34 +08:00

93 lines
2.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
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
# API 路径修复验证脚本
set -e
API_BASE="http://localhost:3001/api"
TOKEN=""
echo "================================"
echo "API 路径修复验证"
echo "================================"
echo ""
# 1. 测试登录
echo "1. 测试登录..."
LOGIN_RESPONSE=$(curl -s -X POST "$API_BASE/admin/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}')
if echo "$LOGIN_RESPONSE" | grep -q '"token"'; then
echo "✅ 登录成功"
TOKEN=$(echo "$LOGIN_RESPONSE" | grep -o '"token":"[^"]*\("([^"]*)"' | sed 's/"token":"\([^"]*\)".*/\1/')
echo " Token: ${TOKEN:0:20}..."
else
echo "❌ 登录失败"
echo "$LOGIN_RESPONSE"
exit 1
fi
echo ""
# 2. 测试获取群组列表
echo "2. 测试获取群组列表..."
GROUPS_RESPONSE=$(curl -s -X GET "$API_BASE/admin/groups" \
-H "Authorization: Bearer $TOKEN")
if echo "$GROUPS_RESPONSE" | grep -q '"name"'; then
echo "✅ 获取群组列表成功"
echo " 群组数量: $(echo "$GROUPS_RESPONSE" | grep -o '"name"' | wc -l | tr -d ' ')"
else
echo "❌ 获取群组列表失败"
echo "$GROUPS_RESPONSE"
fi
echo ""
# 3. 测试创建邀请
echo "3. 测试创建邀请..."
# 需要一个有效的 groupId暂时跳过
echo "⏭️ 需要先创建群组才能测试"
echo ""
# 4. 测试获取邀请列表
echo "4. 测试获取邀请列表..."
INVITES_RESPONSE=$(curl -s -X GET "$API_BASE/invite/my" \
-H "Authorization: Bearer $TOKEN")
if echo "$INVITES_RESPONSE" | grep -q '\[' || echo "$INVITES_RESPONSE" | grep -q 'code'; then
echo "✅ 获取邀请列表成功(或为空)"
else
echo "❌ 获取邀请列表失败"
echo "$INVITES_RESPONSE"
fi
echo ""
# 5. 测试仪表盘统计
echo "5. 测试仪表盘统计..."
STATS_RESPONSE=$(curl -s -X GET "$API_BASE/stats/dashboard" \
-H "Authorization: Bearer $TOKEN")
if echo "$STATS_RESPONSE" | grep -q 'totalMembers'; then
echo "✅ 获取仪表盘统计成功"
echo " 总成员数: $(echo "$STATS_RESPONSE" | grep -o 'totalMembers' | grep -o '[0-9]+' | head -1)"
else
echo "❌ 获取仪表盘统计失败"
echo "$STATS_RESPONSE"
fi
echo ""
# 6. 测试聊天 API需要群组
echo "6. 测试聊天 API 路径..."
echo " 注意:需要有效的 converseId 才能测试"
echo " 路径已从 /chat/messages/:groupId 改为 /chat/converses/:converseId/messages"
echo " ✅ 路径格式正确"
echo ""
echo "================================"
echo "验证完成"
echo "================================"