perf(files): 优化私有文件鉴权与高成本查询隔离
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import {
|
||||
accountSourceLabel,
|
||||
estimateOrderEndAt,
|
||||
formatHandoffRecordType,
|
||||
handoffModeLabel,
|
||||
orderPlatformFeeBreakdown,
|
||||
paymentBizTypeLabel,
|
||||
paymentPaidAt,
|
||||
paymentStatusLabel,
|
||||
paymentStatusType,
|
||||
settlementModeLabel,
|
||||
} from '../adminOrderPresentation'
|
||||
|
||||
describe('admin order presentation', () => {
|
||||
@@ -25,11 +29,27 @@ describe('admin order presentation', () => {
|
||||
|
||||
it('maps known payment states and preserves unknown channel values', () => {
|
||||
expect(paymentStatusLabel('refunded')).toBe('已退款')
|
||||
expect(paymentStatusType('paid')).toBe('success')
|
||||
expect(paymentStatusType('failed')).toBe('danger')
|
||||
expect(paymentStatusType('refunding')).toBe('warning')
|
||||
expect(paymentStatusType('created')).toBe('info')
|
||||
expect(paymentBizTypeLabel('order_pay')).toBe('订单支付')
|
||||
expect(paymentBizTypeLabel('future_type')).toBe('future_type')
|
||||
})
|
||||
|
||||
it('maps handoff, settlement, and account source labels with safe fallbacks', () => {
|
||||
expect(formatHandoffRecordType('owner_handoff')).toBe('卖家交接')
|
||||
expect(formatHandoffRecordType('future_type')).toBe('future_type')
|
||||
expect(handoffModeLabel()).toBe('号主交接')
|
||||
expect(handoffModeLabel('platform')).toBe('平台代管')
|
||||
expect(handoffModeLabel('future')).toBe('future')
|
||||
expect(settlementModeLabel()).toBe('号主钱包')
|
||||
expect(settlementModeLabel('platform_managed')).toBe('线下结算')
|
||||
expect(settlementModeLabel('future')).toBe('future')
|
||||
expect(accountSourceLabel('external')).toBe('外部上传')
|
||||
expect(accountSourceLabel('internal')).toBe('站内上传')
|
||||
})
|
||||
|
||||
it('selects the most meaningful payment completion time', () => {
|
||||
expect(
|
||||
paymentPaidAt({
|
||||
@@ -81,4 +101,32 @@ describe('admin order presentation', () => {
|
||||
totalFeeCent: 4000,
|
||||
})
|
||||
})
|
||||
|
||||
it('normalizes missing and invalid fee snapshots', () => {
|
||||
expect(orderPlatformFeeBreakdown(null)).toEqual({
|
||||
baseFeeCent: 0,
|
||||
insuranceFeeCent: 0,
|
||||
insuranceFeeBps: 0,
|
||||
totalFeeCent: 0,
|
||||
})
|
||||
expect(
|
||||
orderPlatformFeeBreakdown({
|
||||
status: 'completed',
|
||||
platform_fee_cent: -1,
|
||||
insurance_fee_cent: Number.NaN,
|
||||
insurance_fee_bps: 500,
|
||||
checkout: {
|
||||
platform_fee_cent: 1200,
|
||||
insurance_fee_cent: 200,
|
||||
insurance_fee_bps: 800,
|
||||
},
|
||||
})
|
||||
).toEqual({
|
||||
baseFeeCent: 1000,
|
||||
insuranceFeeCent: 200,
|
||||
insuranceFeeBps: 800,
|
||||
totalFeeCent: 1200,
|
||||
})
|
||||
expect(estimateOrderEndAt(undefined, '2026-09-02T12:00:00Z', 0)).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user