27 lines
1.1 KiB
JavaScript
27 lines
1.1 KiB
JavaScript
// 模拟插件推送:用 push/payload.js 组装 payload,POST 到后端 /api/ingest
|
|
// 用法: node scripts/e2e-push.mjs (可选 SERVER/TOKEN 环境变量)
|
|
import { buildIngestPayload } from '../push/payload.js';
|
|
|
|
const record = {
|
|
inquiryId: 'E2E-TEST2', manager: 'tester',
|
|
createTimeFromApi: '2026-07-14T10:00:00Z', updateTimeFromApi: '2026-07-14T10:00:00Z',
|
|
status: 'new', customerId: 'c-e2e', detailCountry: 'US', detailBuyerName: 'Test Buyer',
|
|
behavior: { validRfq: '5' },
|
|
};
|
|
const messages = [{
|
|
messageId: 'e2e-test-m1', sendTime: '2026-07-14T10:00:00Z',
|
|
sender: 'tester', original: 'hello e2e', direction: 'outgoing',
|
|
}];
|
|
|
|
const payload = buildIngestPayload(record, messages);
|
|
const SERVER = process.env.SERVER || 'http://localhost:8080';
|
|
const TOKEN = process.env.TOKEN || 'dev-ingest-token-1234';
|
|
|
|
const res = await fetch(`${SERVER}/api/ingest`, {
|
|
method: 'POST',
|
|
headers: { Authorization: `Bearer ${TOKEN}`, 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload),
|
|
});
|
|
console.log('ingest status:', res.status);
|
|
console.log('ingest body:', JSON.stringify(await res.json()));
|