const http = require('http');

function testConnectEndpoint() {
  console.log('测试/connect端点...');
  
  const options = {
    hostname: 'localhost',
    port: 8001,
    path: '/api/connect',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(JSON.stringify({ username: '', password: '' }))
    }
  };
  
  const req = http.request(options, (res) => {
    console.log(`状态码: ${res.statusCode}`);
    res.setEncoding('utf8');
    let data = '';
    res.on('data', (chunk) => {
      data += chunk;
    });
    res.on('end', () => {
      console.log('响应数据:', data);
      testContractsEndpoint();
    });
  });
  
  req.on('error', (e) => {
    console.error(`请求失败: ${e.message}`);
  });
  
  req.write(JSON.stringify({ username: '', password: '' }));
  req.end();
}

function testContractsEndpoint() {
  console.log('测试/contracts端点...');
  
  const options = {
    hostname: 'localhost',
    port: 8001,
    path: '/api/contracts',
    method: 'GET'
  };
  
  const req = http.request(options, (res) => {
    console.log(`状态码: ${res.statusCode}`);
    res.setEncoding('utf8');
    let data = '';
    res.on('data', (chunk) => {
      data += chunk;
    });
    res.on('end', () => {
      console.log('响应数据:', data);
    });
  });
  
  req.on('error', (e) => {
    console.error(`请求失败: ${e.message}`);
  });
  
  req.end();
}

testConnectEndpoint();