import { describe, expect, it } from 'vitest' import { buildGroupBuyOrderActionPath, buildGroupBuyOrderQuery, filterPendingDeliveryGroupBuyOrders, groupBuyOrderDispatchLabel } from './groupBuyApi' import type { GroupBuyOrder } from '../types' describe('group buy dispatch helpers', () => { it('keeps only group buy orders waiting for delivery', () => { const orders = [ groupBuyOrder({ id: 1, status: 'PENDING_DELIVERY' }), groupBuyOrder({ id: 2, status: 'DELIVERING' }), groupBuyOrder({ id: 3, status: 'PENDING_PICKUP' }) ] expect(filterPendingDeliveryGroupBuyOrders(orders).map((item) => item.id)).toEqual([1]) }) it('builds a readable dispatch label', () => { expect(groupBuyOrderDispatchLabel(groupBuyOrder({ orderNo: 'GB00000001', groupBuyTitle: 'Today eggs', quantity: 2, amountCent: 5980 }))).toBe('GB00000001 Today eggs x2 ¥59.80') }) it('builds admin action paths for group buy orders', () => { expect(buildGroupBuyOrderActionPath(1, 'confirm')).toBe('/api/admin/group-buy-orders/1/confirm') expect(buildGroupBuyOrderActionPath(1, 'ready')).toBe('/api/admin/group-buy-orders/1/ready') }) it('builds group buy order page query params', () => { expect(buildGroupBuyOrderQuery({ status: 'PENDING_CONFIRM', pageNo: 2, pageSize: 10 })).toEqual({ status: 'PENDING_CONFIRM', pageNo: 2, pageSize: 10 }) }) }) function groupBuyOrder(overrides: Partial): GroupBuyOrder { return { id: 1, orderNo: 'GB00000001', groupBuyId: 1, groupBuyTitle: 'Today eggs', quantity: 1, priceCent: 2990, amountCent: 2990, deliveryMethod: 'IMMEDIATE', status: 'PENDING_DELIVERY', offlinePayStatus: 'UNPAID', ...overrides } }