33 lines
2.4 KiB
TypeScript
33 lines
2.4 KiB
TypeScript
// Synthetic fixtures imported only by tests and the explicitly isolated QA harness.
|
|
import type { Vehicle, VehicleRow } from '../../types.js';
|
|
import { counts, freezeLive, type HistoryBatch, type HistorySettings, type HistoryVehicle } from './model.js';
|
|
import { monthCutoff, shanghaiTimestamp } from '../../../shared/assets/history.js';
|
|
import type { HistoryReader } from './store.js';
|
|
|
|
export function testVehicle(id: string, overrides: Partial<Vehicle> = {}): Vehicle {
|
|
return { id, plateNumber: `测试-${id}`, vin: `TESTVIN${id}`, type: '18T', model: '测试18T厢货', color: '白色',
|
|
location: '嘉兴', region: '嘉兴', province: '浙江省', city: '嘉兴市', status: 'Operating', operationStatus: '1', vehicleStatus: '5',
|
|
ownership: 'Self', rentCompany: '', contractNo: '测试合同', customerName: '测试客户公司', orgName: '业务公司',
|
|
departmentName: '部门甲', subjectOrg: '公司甲', projectName: '测试项目', customerManager: '负责人甲', managerId: 'manager-a', brandLabel: '测试品牌', ...overrides };
|
|
}
|
|
export function testRow(id: string, operation = '1'): VehicleRow {
|
|
return { id, 车牌号: `测试-${id}`, vin: `TESTVIN${id}`, 车辆租赁状态: '5', 车辆租赁状态Label: operation,
|
|
主体: '公司甲', 合同归属部门: '部门甲', 经理ID: 'manager-a', 车辆型号Label: '18吨厢式货车' } as VehicleRow;
|
|
}
|
|
export function testBatch(month: string, vehicles: Vehicle[] = [], overrides: Partial<HistoryBatch> = {}): HistoryBatch {
|
|
return { id: `batch-${month}`, month, status: 'COMPLETE', source: 'AUTO', scheduledFor: shanghaiTimestamp(monthCutoff(month)),
|
|
capturedAt: shanghaiTimestamp(monthCutoff(month)), counts: counts(vehicles), ...overrides };
|
|
}
|
|
export class MemoryHistoryReader implements HistoryReader {
|
|
settingsValue: HistorySettings | null = { enabledAt: '2026-08-01T00:00:00+08:00' };
|
|
catalog: HistoryBatch[] = [];
|
|
rows = new Map<string, HistoryVehicle[]>();
|
|
calls: string[] = [];
|
|
async settings() { this.calls.push('settings'); return this.settingsValue; }
|
|
async batches() { this.calls.push('batches'); return this.catalog; }
|
|
async vehicles(ids: string[]) { this.calls.push('vehicles'); return new Map(ids.map(id => [id, this.rows.get(id) || []])); }
|
|
add(month: string, vehicles: Vehicle[], overrides: Partial<HistoryBatch> = {}) {
|
|
const batch = testBatch(month, vehicles, overrides); this.catalog.push(batch); this.rows.set(batch.id, freezeLive(vehicles)); return batch;
|
|
}
|
|
}
|