001project_wildgrowth/backend/scripts/test-simple.sh

81 lines
2.1 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
# 简单的测试脚本 - 只测试创建课程和查询状态
BASE_URL="https://api.muststudy.xin"
EMAIL="test@example.com"
PASSWORD="test123456"
echo "🧪 简单测试:创建课程并查询状态"
echo ""
# 1. 登录
echo "1. 登录..."
TOKEN=$(curl -s -X POST "$BASE_URL/api/auth/login" \
-H "Content-Type: application/json" \
-d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}" | \
grep -o '"token":"[^"]*' | cut -d'"' -f4)
if [ -z "$TOKEN" ]; then
echo "注册新用户..."
curl -s -X POST "$BASE_URL/api/auth/register" \
-H "Content-Type: application/json" \
-d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\",\"username\":\"测试用户\"}" > /dev/null
TOKEN=$(curl -s -X POST "$BASE_URL/api/auth/login" \
-H "Content-Type: application/json" \
-d "{\"email\":\"$EMAIL\",\"password\":\"$PASSWORD\"}" | \
grep -o '"token":"[^"]*' | cut -d'"' -f4)
fi
if [ -z "$TOKEN" ]; then
echo "❌ 登录失败"
exit 1
fi
echo "✅ 登录成功"
echo ""
# 2. 创建课程
echo "2. 创建课程..."
RESPONSE=$(curl -s -X POST "$BASE_URL/api/ai/content/upload" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"content": "这是一个测试内容。社交是每个人都需要掌握的重要技能。",
"style": "essence"
}')
COURSE_ID=$(echo "$RESPONSE" | grep -o '"courseId":"[^"]*' | cut -d'"' -f4)
TASK_ID=$(echo "$RESPONSE" | grep -o '"taskId":"[^"]*' | cut -d'"' -f4)
if [ -z "$COURSE_ID" ]; then
echo "❌ 创建课程失败"
echo "$RESPONSE"
exit 1
fi
echo "✅ 课程创建成功"
echo " Course ID: $COURSE_ID"
echo " Task ID: $TASK_ID"
echo ""
# 3. 查询状态轮询5次
echo "3. 查询生成状态..."
for i in {1..5}; do
sleep 3
STATUS=$(curl -s -X GET "$BASE_URL/api/my-courses" \
-H "Authorization: Bearer $TOKEN" | \
grep -o "\"id\":\"$COURSE_ID\"[^}]*" | \
grep -o '"generation_progress":[0-9.]*' | cut -d':' -f2)
if [ -n "$STATUS" ]; then
PROGRESS=$(echo "$STATUS * 100" | bc)
echo " 进度: ${PROGRESS}%"
else
echo " 查询中..."
fi
done
echo ""
echo "✅ 测试完成!"