48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
const fetch = require('node-fetch');
|
|
|
|
// 测试友情链接API
|
|
async function testLinksAPI() {
|
|
const baseURL = 'http://localhost:3001';
|
|
|
|
console.log('开始测试友情链接API...\n');
|
|
|
|
try {
|
|
// 测试添加友情链接
|
|
console.log('1. 测试添加友情链接...');
|
|
const addResponse = await fetch(`${baseURL}/admin/links`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
name: '测试链接',
|
|
url: 'https://example.com',
|
|
description: '这是一个测试链接',
|
|
order: 1
|
|
})
|
|
});
|
|
|
|
if (addResponse.ok) {
|
|
const addResult = await addResponse.json();
|
|
console.log('✅ 添加成功:', addResult);
|
|
} else {
|
|
console.log('❌ 添加失败:', addResponse.status, addResponse.statusText);
|
|
}
|
|
|
|
// 测试获取友情链接列表
|
|
console.log('\n2. 测试获取友情链接列表...');
|
|
const getResponse = await fetch(`${baseURL}/admin/links`);
|
|
|
|
if (getResponse.ok) {
|
|
console.log('✅ 获取成功');
|
|
} else {
|
|
console.log('❌ 获取失败:', getResponse.status, getResponse.statusText);
|
|
}
|
|
|
|
} catch (error) {
|
|
console.error('❌ 测试失败:', error.message);
|
|
}
|
|
}
|
|
|
|
// 运行测试
|
|
testLinksAPI();
|