26 lines
1.2 KiB
JavaScript
26 lines
1.2 KiB
JavaScript
import http from 'http';
|
|
|
|
function req(method, path, body, token) {
|
|
return new Promise((resolve, reject) => {
|
|
const opts = { hostname: 'localhost', port: 3002, path, method, headers: { 'Content-Type': 'application/json' } };
|
|
if (token) opts.headers['Authorization'] = 'Bearer ' + token;
|
|
const r = http.request(opts, res => { let d = ''; res.on('data', c => d += c); res.on('end', () => resolve(JSON.parse(d))); });
|
|
r.on('error', reject);
|
|
if (body) r.end(JSON.stringify(body)); else r.end();
|
|
});
|
|
}
|
|
|
|
const login = await req('POST', '/api/auth/login', { password: 'admin123' });
|
|
console.log('Login:', login.token ? 'OK' : 'FAIL');
|
|
|
|
const proj = await req('POST', '/api/projects', { name: 'L2 Demo' }, login.token);
|
|
console.log('Project:', proj.name);
|
|
|
|
const std = await req('POST', `/api/projects/${proj.id}/standards`, {
|
|
name: 'L2标准',
|
|
content: '## 功能完整性(25分)\n评审要点:闭环完整\n## 设计文档(15分)\n评审要点:架构合理\n## 测试用例(10分)\n评审要点:覆盖核心逻辑'
|
|
}, login.token);
|
|
console.log('Standard:', std.name, 'Dims:', std.dimensions?.length, JSON.stringify(std.dimensions?.map(d => ({ name: d.name, maxScore: d.maxScore }))));
|
|
|
|
console.log('All tests passed!');
|