42 lines
2.0 KiB
TypeScript
42 lines
2.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
||
import test from 'node:test';
|
||
import { parseProgramInput } from '../src/program-parser.js';
|
||
|
||
const input = `安排酒店变更
|
||
团号:LW-TEST-HOTEL
|
||
入住日期:2026-09-15
|
||
离店日期:2026-09-16
|
||
酒店搜索:测试酒店twn
|
||
间数:9`;
|
||
const receivedAt = '2026-09-11T08:50:12Z';
|
||
|
||
test('dated hotel replacement parses old dates separately from the new resource and count', async () => {
|
||
const result = await parseProgramInput({ rawText: input, receivedAt });
|
||
assert.equal(result.status, 'agent_parse_passed', JSON.stringify(result));
|
||
assert.equal(result.business_route_id, 'arrangement_hotel_update');
|
||
assert.deepEqual((result.operation?.data as any).arrangement, {
|
||
mode: 'update', selection: { start_date: '2026-09-15', end_date: '2026-09-16' },
|
||
changes: { resource: { name: '测试酒店twn', keyword: '测试酒店twn' }, room_count: 9 }
|
||
});
|
||
});
|
||
|
||
test('hotel replacement rejects missing dates, invalid count, reversed dates and mixed update styles', async () => {
|
||
for (const rawText of [
|
||
input.replace('入住日期:2026-09-15\n', ''),
|
||
input.replace('离店日期:2026-09-16\n', ''),
|
||
input.replace('间数:9', '间数:0'),
|
||
input.replace('离店日期:2026-09-16', '离店日期:2026-09-14'),
|
||
`${input}\n目标变更:离店日期改为2026-09-18`
|
||
]) {
|
||
const result = await parseProgramInput({ rawText, receivedAt });
|
||
assert.notEqual(result.status, 'agent_parse_passed', JSON.stringify(result));
|
||
assert.equal(result.operation, null);
|
||
}
|
||
});
|
||
|
||
test('legacy hotel departure and count changes remain supported', async () => {
|
||
const result = await parseProgramInput({ rawText: '安排变更\n团号:LW-TEST-HOTEL\n目标变更:离店日期改为2026-09-18;房间数改为9\n安排类型:酒店', receivedAt });
|
||
assert.equal(result.status, 'agent_parse_passed', JSON.stringify(result));
|
||
assert.deepEqual((result.operation?.data as any).arrangement, { mode: 'update', changes: { end_date: '2026-09-18', room_count: 9 } });
|
||
});
|