Files
martial-mini/test/quick-test.js
2025-12-12 01:44:41 +08:00

114 lines
3.4 KiB
JavaScript
Raw 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.
/**
* 快速测试脚本 - 只测试核心接口
* 运行方式npm run test:quick
*/
const axios = require('axios');
// 配置
const config = {
baseURL: 'http://your-api-domain.com', // ⚠️ 修改为你的API地址
testUser: {
username: 'test_user', // ⚠️ 修改为测试账号
password: 'test_password' // ⚠️ 修改为测试密码
}
};
let passCount = 0;
let failCount = 0;
function log(emoji, message) {
console.log(`${emoji} ${message}`);
}
async function quickTest() {
console.log('\n🚀 武术比赛报名系统 - 快速测试\n');
console.log(`📍 API地址: ${config.baseURL}\n`);
const api = axios.create({
baseURL: config.baseURL,
timeout: 10000,
headers: { 'Content-Type': 'application/json' }
});
try {
// 测试1登录
log('🔐', '测试登录...');
const loginRes = await api.post('/martial/auth/login', config.testUser);
if (loginRes.data.code === 200 && loginRes.data.data.token) {
log('✅', '登录成功');
passCount++;
const token = loginRes.data.data.token;
api.defaults.headers['Blade-Auth'] = `Bearer ${token}`;
} else {
log('❌', '登录失败');
failCount++;
return;
}
// 测试2赛事列表
log('📋', '测试赛事列表...');
const compRes = await api.get('/martial/competition/list?current=1&size=10');
if (compRes.data.code === 200) {
const count = compRes.data.data.records?.length || compRes.data.data?.length || 0;
log('✅', `赛事列表获取成功 (${count}条数据)`);
passCount++;
} else {
log('❌', '赛事列表获取失败');
failCount++;
}
// 测试3选手列表
log('👥', '测试选手列表...');
const athleteRes = await api.get('/martial/athlete/list?current=1&size=10');
if (athleteRes.data.code === 200) {
const count = athleteRes.data.data.records?.length || athleteRes.data.data?.length || 0;
log('✅', `选手列表获取成功 (${count}条数据)`);
passCount++;
} else {
log('❌', '选手列表获取失败');
failCount++;
}
// 测试4用户信息
log('👤', '测试用户信息...');
const userRes = await api.get('/martial/user/info');
if (userRes.data.code === 200) {
log('✅', `用户信息获取成功 (${userRes.data.data.name || '未知'})`);
passCount++;
} else {
log('❌', '用户信息获取失败');
failCount++;
}
// 测试5报名列表
log('📝', '测试报名列表...');
const regRes = await api.get('/martial/registration/list?current=1&size=10');
if (regRes.data.code === 200) {
const count = regRes.data.data.records?.length || regRes.data.data?.length || 0;
log('✅', `报名列表获取成功 (${count}条数据)`);
passCount++;
} else {
log('❌', '报名列表获取失败');
failCount++;
}
} catch (error) {
log('❌', `请求失败: ${error.message}`);
failCount++;
}
// 输出结果
console.log('\n' + '='.repeat(50));
console.log(`📊 测试结果: ${passCount}个通过, ${failCount}个失败`);
console.log(`✨ 成功率: ${((passCount / (passCount + failCount)) * 100).toFixed(1)}%`);
console.log('='.repeat(50) + '\n');
process.exit(failCount > 0 ? 1 : 0);
}
quickTest().catch(err => {
console.error('❌ 测试执行失败:', err.message);
process.exit(1);
});