This commit is contained in:
2026-08-11 18:48:17 +08:00
parent 6622815d6c
commit 886c7d3529
@@ -8,21 +8,30 @@ function tier(id: string, feeType: OverseasFeeType, startDay: number, endDay: nu
describe('overseas storage fee tier editing', () => {
it('adds a new open-ended tier and closes the previous tail', () => {
const tiers = [tier('s1', 'STORAGE', 1, null), tier('r1', 'RETURN_STORAGE', 1, null)]
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()
expect(tiers.filter((item) => item.feeType === 'STORAGE').map(({ startDay, endDay }) => ({ startDay, endDay })))
.toEqual([{ startDay: 1, endDay: 1 }, { startDay: 2, endDay: null }])
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, null),
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[1]!)).toBeNull()
expect(tiers.slice(0, 2).map(({ startDay, endDay }) => ({ startDay, endDay })))
.toEqual([{ startDay: 1, endDay: 30 }, { startDay: 31, endDay: 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()
})