完善本地质量门禁与资金链路测试

This commit is contained in:
yml2213
2026-09-02 13:50:19 +08:00
parent dd2b45bd2c
commit 208f12ddb4
80 changed files with 12245 additions and 11541 deletions
@@ -0,0 +1,42 @@
import { describe, expect, it } from 'vitest'
import {
estimateOrderEndAt,
paymentBizTypeLabel,
paymentPaidAt,
paymentStatusLabel,
paymentStatusType,
} from '../adminOrderPresentation'
describe('admin order presentation', () => {
it('prefers the server-provided estimated end time', () => {
expect(estimateOrderEndAt('2026-09-03T12:00:00Z', '2026-09-02T12:00:00Z', 2)).toBe(
'2026-09-03T12:00:00Z'
)
})
it('calculates the end time from rental start and duration', () => {
expect(estimateOrderEndAt(undefined, '2026-09-02T12:00:00Z', 2)).toBe(
'2026-09-02T14:00:00.000Z'
)
expect(estimateOrderEndAt(undefined, 'invalid', 2)).toBeUndefined()
})
it('maps known payment states and preserves unknown channel values', () => {
expect(paymentStatusLabel('refunded')).toBe('已退款')
expect(paymentStatusType('failed')).toBe('danger')
expect(paymentBizTypeLabel('order_pay')).toBe('订单支付')
expect(paymentBizTypeLabel('future_type')).toBe('future_type')
})
it('selects the most meaningful payment completion time', () => {
expect(
paymentPaidAt({
paid_at: 'paid',
updated_at: 'updated',
created_at: 'created',
})
).toBe('paid')
expect(paymentPaidAt({ updated_at: 'updated', created_at: 'created' })).toBe('updated')
})
})
@@ -0,0 +1,51 @@
import type { AdminPayment } from '@/features/admin/api/adminPayments'
export function estimateOrderEndAt(
estimatedEndAt?: string,
rentedAt?: string,
durationHours?: number
) {
if (estimatedEndAt) return estimatedEndAt
const hours = Number(durationHours || 0)
if (!rentedAt || hours <= 0) return undefined
const startedAt = new Date(rentedAt).getTime()
if (!Number.isFinite(startedAt)) return undefined
return new Date(startedAt + hours * 60 * 60 * 1000).toISOString()
}
export function paymentStatusLabel(status: string) {
const labels: Record<string, string> = {
created: '已创建',
paying: '支付中',
paid: '已支付',
refunding: '退款中',
refunded: '已退款',
failed: '失败',
}
return labels[status] || status
}
export function paymentStatusType(status: string) {
if (['paid', 'refunded'].includes(status)) return 'success' as const
if (status === 'failed') return 'danger' as const
if (['paying', 'refunding'].includes(status)) return 'warning' as const
return 'info' as const
}
export function paymentBizTypeLabel(type: string) {
const labels: Record<string, string> = {
order_pay: '订单支付',
checkout_refund: '结账退款',
arbitration_refund: '仲裁退款',
admin_refund: '人工退款',
cancel_refund: '取消退款',
admin_close_refund: '客服关闭退款',
admin_seal_refund: '封存退款',
deposit_refund: '暂扣押金归还',
}
return labels[type] || type
}
export function paymentPaidAt(record: Pick<AdminPayment, 'paid_at' | 'updated_at' | 'created_at'>) {
return record.paid_at || record.updated_at || record.created_at
}