Files
telegram-management-system/backend/test/testAccountPoolAPI.js
你的用户名 237c7802e5
Some checks failed
Deploy / deploy (push) Has been cancelled
Initial commit: Telegram Management System
Full-stack web application for Telegram management
- Frontend: Vue 3 + Vben Admin
- Backend: NestJS
- Features: User management, group broadcast, statistics

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 15:37:50 +08:00

107 lines
4.0 KiB
JavaScript
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.

// 测试账号池管理API
const axios = require('axios');
const API_BASE = 'http://localhost:3333';
const TOKEN = 'your-auth-token-here'; // 需要替换为实际的token
const api = axios.create({
baseURL: API_BASE,
headers: {
'token': TOKEN,
'Content-Type': 'application/json'
}
});
async function testAPIs() {
try {
console.log('开始测试账号池API...\n');
// 1. 测试获取账号池列表
console.log('=== 测试获取账号池列表 ===');
try {
const listResponse = await api.get('/accountpool/list', {
params: {
page: 1,
pageSize: 10,
sortBy: 'createdAt',
sortOrder: 'DESC'
}
});
console.log('✅ 获取列表成功:', {
total: listResponse.data.data.pagination.total,
count: listResponse.data.data.list.length
});
} catch (error) {
console.log('❌ 获取列表失败:', error.response?.data || error.message);
}
// 2. 测试获取统计数据
console.log('\n=== 测试获取统计数据 ===');
try {
const statsResponse = await api.get('/accountpool/statistics');
console.log('✅ 获取统计成功:', statsResponse.data.data.summary);
} catch (error) {
console.log('❌ 获取统计失败:', error.response?.data || error.message);
}
// 3. 测试批量评估健康度
console.log('\n=== 测试批量评估健康度 ===');
try {
const evaluateResponse = await api.post('/accountpool/evaluate/batch');
console.log('✅ 批量评估成功:', evaluateResponse.data.data.result);
} catch (error) {
console.log('❌ 批量评估失败:', error.response?.data || error.message);
}
// 4. 如果有账号,测试单个账号的详情
console.log('\n=== 测试获取账号详情 ===');
try {
const listResponse = await api.get('/accountpool/list?pageSize=1');
if (listResponse.data.data.list.length > 0) {
const accountId = listResponse.data.data.list[0].id;
const detailResponse = await api.get(`/accountpool/detail/${accountId}`);
console.log('✅ 获取详情成功:', {
id: detailResponse.data.data.account.id,
phone: detailResponse.data.data.account.phone,
status: detailResponse.data.data.account.status,
healthScore: detailResponse.data.data.account.healthRecords?.[0]?.healthScore
});
// 5. 测试健康度报告
console.log('\n=== 测试健康度报告 ===');
const reportResponse = await api.get(`/accountpool/health/report/${accountId}?days=7`);
if (reportResponse.data.success && reportResponse.data.data.report) {
console.log('✅ 获取报告成功:', {
currentScore: reportResponse.data.data.report.currentScore,
trend: reportResponse.data.data.report.trend
});
}
} else {
console.log('⚠️ 没有账号可供测试详情');
}
} catch (error) {
console.log('❌ 测试详情失败:', error.response?.data || error.message);
}
console.log('\n✅ API测试完成');
} catch (error) {
console.error('❌ 测试失败:', error.message);
}
}
// 获取token的函数
async function getAuthToken() {
try {
// 这里应该调用登录API获取token
// 临时使用硬编码的token进行测试
console.log('请先获取有效的token并更新脚本中的TOKEN变量');
return null;
} catch (error) {
console.error('获取token失败:', error);
return null;
}
}
// 运行测试
testAPIs();