import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import request from 'supertest'; import { setupApp, resetDb, teardown } from './setup.js'; import { makePayload } from './fixtures.js'; let app: any; beforeAll(async () => { ({ app } = await setupApp()); }, 90000); afterAll(async () => { await teardown(); }); async function login() { return ( await request(app) .post('/api/auth/login') .send({ username: 'admin', password: 'admin-password-1234' }) ).body.token; } async function pushInquiry(p: any) { await request(app) .post('/api/ingest') .set('Authorization', 'Bearer dev-ingest-token-1234') .send(p); } describe('export', () => { it('list CSV has header + row, no chat content', async () => { await resetDb(); await pushInquiry(makePayload()); // inquiryId 13776617920, messages hello/hi const token = await login(); const res = await request(app).get('/api/export').set('Authorization', 'Bearer ' + token); expect(res.status).toBe(200); expect(res.headers['content-type']).toContain('text/csv'); const text = res.text; expect(text).toContain('询价单号'); // 表头 expect(text).toContain('13776617920'); // 数据行 expect(text).not.toContain('hello'); // 列表导出不含聊天原文 }); it('single-inquiry chat CSV contains message content', async () => { await resetDb(); await pushInquiry(makePayload()); const token = await login(); const res = await request(app) .get('/api/inquiries/13776617920/messages/export') .set('Authorization', 'Bearer ' + token); expect(res.status).toBe(200); expect(res.text).toContain('时间'); expect(res.text).toContain('hello'); // 含聊天原文 }); });