refactor(platform): centralize vehicle lookup rules
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import type { QualityIssueRow } from '../api/types';
|
||||
import { qualityIssueVehicleLookup } from './vehicleLookup';
|
||||
|
||||
function issue(row: Partial<QualityIssueRow>): QualityIssueRow {
|
||||
return {
|
||||
vin: '',
|
||||
plate: '',
|
||||
phone: '',
|
||||
sourceEndpoint: '',
|
||||
protocol: 'JT808',
|
||||
issueType: 'VIN_MISSING',
|
||||
severity: 'warning',
|
||||
lastSeen: '',
|
||||
detail: '',
|
||||
...row
|
||||
};
|
||||
}
|
||||
|
||||
describe('qualityIssueVehicleLookup', () => {
|
||||
test('prefers a valid VIN', () => {
|
||||
expect(qualityIssueVehicleLookup(issue({ vin: 'VIN001', plate: '粤A12345', phone: '13300000001' }))).toEqual({
|
||||
key: 'VIN001',
|
||||
label: '车辆服务'
|
||||
});
|
||||
});
|
||||
|
||||
test('uses plate when VIN is missing', () => {
|
||||
expect(qualityIssueVehicleLookup(issue({ vin: 'unknown', plate: '粤A12345', phone: '13300000001' }))).toEqual({
|
||||
key: '粤A12345',
|
||||
label: '按车牌查车'
|
||||
});
|
||||
});
|
||||
|
||||
test('uses phone when VIN and plate are missing', () => {
|
||||
expect(qualityIssueVehicleLookup(issue({ vin: 'unknown', phone: '13300000001' }))).toEqual({
|
||||
key: '13300000001',
|
||||
label: '按手机号查车'
|
||||
});
|
||||
});
|
||||
});
|
||||
22
vehicle-data-platform/apps/web/src/domain/vehicleLookup.ts
Normal file
22
vehicle-data-platform/apps/web/src/domain/vehicleLookup.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import type { QualityIssueRow } from '../api/types';
|
||||
|
||||
export type VehicleLookup = {
|
||||
key: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
export function qualityIssueVehicleLookup(row: QualityIssueRow): VehicleLookup {
|
||||
const vin = row.vin?.trim();
|
||||
if (vin && vin !== 'unknown') {
|
||||
return { key: vin, label: '车辆服务' };
|
||||
}
|
||||
const plate = row.plate?.trim();
|
||||
if (plate) {
|
||||
return { key: plate, label: '按车牌查车' };
|
||||
}
|
||||
const phone = row.phone?.trim();
|
||||
if (phone) {
|
||||
return { key: phone, label: '按手机号查车' };
|
||||
}
|
||||
return { key: '', label: '车辆服务' };
|
||||
}
|
||||
Reference in New Issue
Block a user