#!/bin/bash

# Mock Server 测试脚本
# 用于验证 Mock Server 是否正常运行并返回预期的响应

echo "========================================"
echo "Mock Server 连接测试"
echo "========================================"
echo ""

MOCK_SERVER="http://localhost:8000"

echo "[1/6] 测试 Mock Server 连接..."
if curl -s --connect-timeout 5 "$MOCK_SERVER" > /dev/null 2>&1; then
    echo "✅ Mock Server 运行正常"
else
    echo "❌ Mock Server 未运行或无法访问"
    echo "请先启动 Mock Server："
    echo "  cd lsfx-mock-server"
    echo "  python app.py"
    exit 1
fi
echo ""

echo "[2/6] 测试获取Token接口..."
curl -X POST "$MOCK_SERVER/account/common/getToken" \
  -H "Content-Type: multipart/form-data" \
  -F "projectNo=902000_202603021400" \
  -F "entityName=902000_202603021400" \
  -F "userId=testuser"
echo ""
echo ""

echo "[3/6] 测试上传文件接口..."
curl -X POST "$MOCK_SERVER/watson/api/project/remoteUploadSplitFile" \
  -H "Content-Type: multipart/form-data" \
  -F "groupId=456" \
  -F "file=@test-data.xlsx"
echo ""
echo ""

echo "[4/6] 测试拉取行内流水接口..."
curl -X POST "$MOCK_SERVER/watson/api/project/getJZFileOrZjrcuFile" \
  -H "Content-Type: multipart/form-data" \
  -F "groupId=456" \
  -F "customerNo=CUST001"
echo ""
echo ""

echo "[5/6] 测试检查解析状态接口..."
curl -X POST "$MOCK_SERVER/watson/api/project/upload/getpendings" \
  -H "Content-Type: multipart/form-data" \
  -F "groupId=456" \
  -F "inprogressList=789,790"
echo ""
echo ""

echo "[6/6] 测试获取银行流水接口..."
curl -X POST "$MOCK_SERVER/watson/api/project/getBSByLogId" \
  -H "Content-Type: multipart/form-data" \
  -F "groupId=456" \
  -F "logId=789" \
  -F "pageNow=1" \
  -F "pageSize=20"
echo ""
echo ""

echo "========================================"
echo "Mock Server 测试完成！"
echo "========================================"
