const test = require('node:test'); const assert = require('node:assert/strict'); const { resolveCustomerKeyword } = require('../erp_customer_resolver'); const teamBatchOps = require('../erp_team_batch_browser_operations'); const splitChildOps = require('../erp_split_child_browser_operations'); const customers = { 'LW云南七彩金桥国旅(昆明景腾)': { id: '778', erpName: 'LW云南七彩金桥国旅(昆明景腾)', contact: '罗胜青 15925104087', origin: '云南', }, 'LW云南七彩假期': { id: '779', erpName: 'LW云南七彩假期', }, }; test('resolveCustomerKeyword uniquely matches partial customer keywords', () => { const result = resolveCustomerKeyword(customers, '昆明景腾', 'booking customer'); assert.equal(result.status, 'matched'); assert.equal(result.value.id, '778'); assert.equal(result.value.erpName, 'LW云南七彩金桥国旅(昆明景腾)'); }); test('resolveCustomerKeyword returns candidates for ambiguous keywords', () => { const result = resolveCustomerKeyword(customers, '云南七彩', 'booking customer'); assert.equal(result.status, 'ambiguous'); assert.deepEqual(result.candidates.map((candidate) => candidate.id), ['778', '779']); }); test('resolveCustomerKeyword reports not_found for missing keywords', () => { const result = resolveCustomerKeyword(customers, '金桥国旅海外部', 'booking customer'); assert.equal(result.status, 'not_found'); assert.match(result.customerMessage, /没有匹配到|未匹配/); }); test('team batch buildSubmitPayload accepts a unique booking customer keyword', () => { const payload = teamBatchOps.buildSubmitPayload({ bookingCustomer: '昆明景腾', productName: 'product-a', dateRange: { start: '2026-07-13', end: '2026-07-13' }, departureDates: ['2026-07-13'], defaultPax: { adult: 1, childBed: 0, childNoBed: 0, infant: 0, leader: 0 }, defaultRooms: { DBL: 1 }, defaultPrices: { adult: 500 }, op: 'op', salesperson: 'sales', }, { erpMappings: { bookingCustomers: customers, teamBatchProducts: { 'product-a': { cpid: '403', searchName: 'ERP product', groupPrefix: 'LW', groupSuffix: 'A' }, }, }, }); assert.equal(payload.customer.id, '778'); assert.equal(payload.customer.name, 'LW云南七彩金桥国旅(昆明景腾)'); }); test('split child buildSubmitPayload blocks ambiguous channel customer keywords', () => { assert.throws( () => splitChildOps.buildSubmitPayload({ parentGroupNo: 'LW-260701A-A', productRoute: 'route-a', departureDate: '2026-07-01', channelCustomer: '云南七彩', pax: { adult: 1 }, prices: { adult: 500 }, op: 'op', salesperson: 'sales', }, { erpMappings: { splitChildCustomers: customers, splitParentProducts: { 'route-a': { cpid: '412', searchName: 'route-a' }, }, }, }), /customer keyword ambiguous/ ); });