77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import assert from 'node:assert/strict'
|
|
import type { BorrowRecord, HrSyncBorrowedAssetPreview } from '../src/types.ts'
|
|
import {
|
|
buildNotificationQuickReturnAssetKey,
|
|
findNotificationQuickReturnRecord
|
|
} from '../src/views/notifications/notificationQuickReturn.ts'
|
|
|
|
const assetWithBorrowRecord: HrSyncBorrowedAssetPreview = {
|
|
equipmentCode: 'JS-PC-3001',
|
|
equipmentName: '主机',
|
|
borrowRecordId: 901
|
|
}
|
|
|
|
const assetWithoutBorrowRecord: HrSyncBorrowedAssetPreview = {
|
|
equipmentCode: 'JS-MON-2001',
|
|
equipmentName: '显示器'
|
|
}
|
|
|
|
const borrowRecords: BorrowRecord[] = [
|
|
{
|
|
id: 901,
|
|
equipment_id: 3001,
|
|
equipment_code: 'JS-PC-3001',
|
|
person_id: 11,
|
|
person_name: '张亮',
|
|
person_nickname: '三藏',
|
|
borrow_time: '2026-03-26T09:00:00.000Z',
|
|
status: '已借出',
|
|
created_at: '2026-03-26T09:00:00.000Z',
|
|
updated_at: '2026-03-26T09:00:00.000Z'
|
|
},
|
|
{
|
|
id: 902,
|
|
equipment_id: 3001,
|
|
equipment_code: 'JS-PC-3001',
|
|
person_id: 12,
|
|
person_name: '李想',
|
|
person_nickname: '小李',
|
|
borrow_time: '2026-03-26T10:00:00.000Z',
|
|
status: '已借出',
|
|
created_at: '2026-03-26T10:00:00.000Z',
|
|
updated_at: '2026-03-26T10:00:00.000Z'
|
|
}
|
|
]
|
|
|
|
assert.equal(
|
|
buildNotificationQuickReturnAssetKey(assetWithBorrowRecord),
|
|
'borrow-record:901',
|
|
'带借用记录编号的资产应优先用借用记录生成稳定 key'
|
|
)
|
|
|
|
assert.equal(
|
|
buildNotificationQuickReturnAssetKey(assetWithoutBorrowRecord),
|
|
'equipment:JS-MON-2001',
|
|
'没有借用记录编号时应回退到资产编码'
|
|
)
|
|
|
|
assert.equal(
|
|
findNotificationQuickReturnRecord(borrowRecords, assetWithBorrowRecord)?.id,
|
|
901,
|
|
'带借用记录编号时应优先命中对应借用记录'
|
|
)
|
|
|
|
assert.equal(
|
|
findNotificationQuickReturnRecord(borrowRecords, assetWithoutBorrowRecord),
|
|
null,
|
|
'存在多条借用记录且没有指定借用记录编号时,不应擅自自动选中'
|
|
)
|
|
|
|
assert.equal(
|
|
findNotificationQuickReturnRecord([borrowRecords[0]], assetWithoutBorrowRecord)?.id,
|
|
901,
|
|
'只有一条借用记录时,应允许自动选中'
|
|
)
|
|
|
|
console.log('notification quick return tests: ok')
|