import test from 'node:test'; import assert from 'node:assert/strict'; import { transformRow } from './model.js'; import type { VehicleRow } from '../../types.js'; const row = { id: 'vehicle-1', 车辆租赁状态: '14', 客户经理: '合同经理', 合同归属部门: '合同部门' } as VehicleRow; test('movement details use source timestamps and preserve work without borrowing lease ownership', () => { const vehicle = transformRow({ ...row, abnormal_move_id: '1234567890123456789', abnormal_move_type: 1, abnormal_move_status: 3, abnormal_move_work: '更换制动部件;道路验证', abnormal_move_target_time: '2026-09-23 18:00', abnormal_move_actual_time: null }); assert.equal(vehicle.abnormalMove?.id, '1234567890123456789'); assert.equal(vehicle.abnormalMove?.type, '维修'); assert.equal(vehicle.abnormalMove?.work, '更换制动部件;道路验证'); assert.equal(vehicle.abnormalMove?.targetCompletionTime, '2026-09-23 18:00'); assert.equal(vehicle.abnormalMove?.actualCompletionTime, null); for (const key of ['responsiblePerson', 'initiatingDepartment', 'executingDepartment', 'driver'] as const) { assert.equal(vehicle.abnormalMove?.[key], null); } }); test('completed movement retains its actual time and missing records stay distinct', () => { const completed = transformRow({ ...row, abnormal_move_id: '2', abnormal_move_type: 4, abnormal_move_status: 5, abnormal_move_work: ' ', abnormal_move_actual_time: '2026-09-22 12:30' }); assert.equal(completed.abnormalMove?.status, '已完成'); assert.equal(completed.abnormalMove?.actualCompletionTime, '2026-09-22 12:30'); assert.equal(completed.abnormalMove?.work, null); assert.equal(transformRow(row).abnormalMove, null); }); test('applicant comes from the movement creator name and never falls back to contract manager', () => { const base = { ...row, abnormal_move_id: 'move-1' }; assert.equal(transformRow({ ...base, abnormal_move_applicant: ' 测试申请人 ' }).abnormalMove?.applicant, '测试申请人'); assert.equal(transformRow({ ...base, abnormal_move_applicant: ' ' }).abnormalMove?.applicant, null); assert.equal(transformRow(base).abnormalMove?.applicant, null); });