process.env.NODE_ENV = 'test';
process.env.DB_PATH = ':memory:';

const { initDatabase } = await import('../api/database');
await initDatabase();

const { app } = await import('../api/server');

const server = app.listen(0);
const addr = server.address();
const baseUrl = `http://127.0.0.1:${addr.port}`;

try {
  const body = {
    mode: 'incremental',
    questions: [
      {
        content:
          '【文字描述题】请简述你对公司“只服务渠道客户，不直接做甲方项目（除深圳周边近的）”这一政策的理解。',
        type: 'text',
        category: '通用',
        score: 0,
        answer: '',
        analysis: '用于人工评阅，关注对渠道保护、资源倾斜、合作共赢等理念的理解。',
      },
    ],
  };

  const res = await fetch(`${baseUrl}/api/questions/import-text`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(body),
  });

  const text = await res.text();
  console.log('status:', res.status);
  console.log(text);
} finally {
  await new Promise((resolve) => server.close(resolve));
}
