import { describe, expect, it } from 'vitest'
import { groupOrdersByStatus } from '../group-orders-by-status'

const STATUSES = ['PENDING', 'PAID', 'DONE'] as const

describe('groupOrdersByStatus', () => {
  it('groups and sorts orders by status', () => {
    const orders = [
      { status: 'PAID', createdAt: '2024-01-02T10:00:00Z' },
      { status: 'PENDING', createdAt: '2024-01-01T10:00:00Z' },
      { status: 'PAID', createdAt: '2024-01-03T10:00:00Z' },
    ]

    const result = groupOrdersByStatus(orders, STATUSES)

    expect(result).toHaveLength(2)
    expect(result[0].status).toBe('PENDING')
    expect(result[1].status).toBe('PAID')
    expect(result[1].items).toHaveLength(2)
    expect(result[1].items[0].createdAt).toBe('2024-01-03T10:00:00Z')
  })

  it('returns empty array for no matching orders', () => {
    const result = groupOrdersByStatus([], STATUSES)
    expect(result).toHaveLength(0)
  })

  it('ignores unknown statuses', () => {
    const orders = [{ status: 'UNKNOWN', createdAt: '2024-01-01T10:00:00Z' }]
    const result = groupOrdersByStatus(orders, STATUSES)
    expect(result).toHaveLength(0)
  })
})
