feat(admin): filter booking agents by carrier

This commit is contained in:
2026-08-27 10:33:43 +08:00
parent 3e3c7e237a
commit f7afcb6cdc
7 changed files with 118 additions and 34 deletions
@@ -1,15 +1,18 @@
import { describe, expect, it } from 'vitest'
import { isActiveBookingAgent } from './bookingAgents'
import { shouldClearBookingAgent } from './bookingAgents'
describe('ocean booking agent candidates', () => {
it('accepts an active booking supplier', () => {
expect(isActiveBookingAgent({ category: 'BOOKING', status: 'ACTIVE' })).toBe(true)
const options = [{ supplierId: '11', name: '代理A', carrierCodes: ['MATSON', 'COSCO'] as const }]
it('keeps an agent returned by the server-filtered carrier candidates', () => {
expect(shouldClearBookingAgent('11', options.map((item) => ({ ...item, carrierCodes: [...item.carrierCodes] })))).toBe(false)
})
it.each([
{ category: 'BOOKING', status: 'INACTIVE' },
{ category: 'TRUCKING', status: 'ACTIVE' },
])('rejects a non-eligible supplier: %o', (supplier) => {
expect(isActiveBookingAgent(supplier)).toBe(false)
it('clears an agent missing from the newly selected carrier candidates', () => {
expect(shouldClearBookingAgent('12', options.map((item) => ({ ...item, carrierCodes: [...item.carrierCodes] })))).toBe(true)
})
it('does not clear an empty selection', () => {
expect(shouldClearBookingAgent(null, [])).toBe(false)
})
})