43 lines
2.1 KiB
TypeScript
43 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { addFeeTier, removeFeeTier, validateFeeTiers } from './overseasStorageFeeTiers'
|
|
import type { OverseasFeeType, OverseasStorageFeeTier } from './overseasStorageFee'
|
|
|
|
function tier(id: string, feeType: OverseasFeeType, startDay: number, endDay: number | null): OverseasStorageFeeTier {
|
|
return { id, feeType, billingUnit: feeType === 'STORAGE' ? 'CBM' : 'PALLET', startDay, endDay, unitPrice: 1, sortNo: 1 }
|
|
}
|
|
|
|
describe('overseas storage fee tier editing', () => {
|
|
it('adds a new open-ended tier and closes the previous tail', () => {
|
|
const tiers = [
|
|
tier('s1', 'STORAGE', 1, 7), tier('s2', 'STORAGE', 8, 30), tier('s3', 'STORAGE', 31, 60),
|
|
tier('s4', 'STORAGE', 61, 90), tier('s5', 'STORAGE', 91, null),
|
|
tier('r1', 'RETURN_STORAGE', 1, null),
|
|
]
|
|
expect(addFeeTier(tiers, 'STORAGE')).toBeNull()
|
|
const storageTiers = tiers.filter((item) => item.feeType === 'STORAGE')
|
|
expect(storageTiers).toHaveLength(6)
|
|
expect(storageTiers.slice(-2).map(({ startDay, endDay }) => ({ startDay, endDay })))
|
|
.toEqual([{ startDay: 91, endDay: 91 }, { startDay: 92, endDay: null }])
|
|
expect(validateFeeTiers(tiers)).toBeNull()
|
|
})
|
|
|
|
it('removes a middle tier and extends the previous range', () => {
|
|
const tiers = [
|
|
tier('s1', 'STORAGE', 1, 7), tier('s2', 'STORAGE', 8, 30), tier('s3', 'STORAGE', 31, 60),
|
|
tier('s4', 'STORAGE', 61, 90), tier('s5', 'STORAGE', 91, null),
|
|
tier('r1', 'RETURN_STORAGE', 1, null),
|
|
]
|
|
expect(removeFeeTier(tiers, tiers[2]!)).toBeNull()
|
|
const storageTiers = tiers.filter((item) => item.feeType === 'STORAGE')
|
|
expect(storageTiers).toHaveLength(4)
|
|
expect(storageTiers.slice(1, 3).map(({ startDay, endDay }) => ({ startDay, endDay })))
|
|
.toEqual([{ startDay: 8, endDay: 60 }, { startDay: 61, endDay: 90 }])
|
|
expect(validateFeeTiers(tiers)).toBeNull()
|
|
})
|
|
|
|
it('does not delete the only tier of a fee type', () => {
|
|
const tiers = [tier('s1', 'STORAGE', 1, null), tier('r1', 'RETURN_STORAGE', 1, null)]
|
|
expect(removeFeeTier(tiers, tiers[0]!)).toBe('每种费用至少需要保留1档')
|
|
})
|
|
})
|