ываыв
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { canTransitionOrderStatus, getAdminNextOrderStatuses } from '../order'
|
||||
|
||||
describe('client order status helpers', () => {
|
||||
it('returns delivery-specific next statuses', () => {
|
||||
expect(getAdminNextOrderStatuses('IN_PROGRESS', 'delivery')).toEqual(['SHIPPED', 'CANCELLED'])
|
||||
})
|
||||
|
||||
it('returns pickup-specific next statuses', () => {
|
||||
expect(getAdminNextOrderStatuses('IN_PROGRESS', 'pickup')).toEqual(['READY_FOR_PICKUP', 'CANCELLED'])
|
||||
})
|
||||
|
||||
it('checks pickup transition without falling back to delivery rules', () => {
|
||||
expect(canTransitionOrderStatus('IN_PROGRESS', 'READY_FOR_PICKUP', 'pickup')).toBe(true)
|
||||
expect(canTransitionOrderStatus('IN_PROGRESS', 'SHIPPED', 'pickup')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -11,7 +11,7 @@ export function getAdminNextOrderStatuses(status: string, deliveryType: 'deliver
|
||||
return sharedGetNextAdminStatuses(status, deliveryType) as OrderStatus[]
|
||||
}
|
||||
|
||||
export function canTransitionOrderStatus(from: string, to: string): boolean {
|
||||
export function canTransitionOrderStatus(from: string, to: string, deliveryType: 'delivery' | 'pickup'): boolean {
|
||||
if (from === to) return true
|
||||
return getAdminNextOrderStatuses(from, 'delivery').includes(to as OrderStatus)
|
||||
return getAdminNextOrderStatuses(from, deliveryType).includes(to as OrderStatus)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user