import { describe, it, expect } from 'vitest';
import { groupByOrderType } from './group-by-order-type.helper';
import {
  RewardSelectionItem,
  ShoppingCartItem,
} from '@isa/checkout/data-access';

describe('groupByOrderType', () => {
  it('should group items by order type', () => {
    const items: RewardSelectionItem[] = [
      {
        item: {
          features: { orderType: 'Versand' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
      {
        item: {
          features: { orderType: 'Abholung' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
      {
        item: {
          features: { orderType: 'Versand' },
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 2,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
    ];

    const result = groupByOrderType(items);

    expect(result.size).toBe(2);
    expect(result.get('Versand')).toHaveLength(2);
    expect(result.get('Abholung')).toHaveLength(1);
  });

  it('should handle items without order type feature', () => {
    const items: RewardSelectionItem[] = [
      {
        item: {
          features: {},
          product: {},
        } as unknown as ShoppingCartItem,
        cartQuantity: 1,
        rewardCartQuantity: 0,
        catalogPrice: undefined,
        availabilityPrice: undefined,
        catalogRewardPoints: undefined,
      },
    ];

    const result = groupByOrderType(items);

    expect(result.size).toBe(1);
    expect(result.has('Unbekannt')).toBe(true);
  });

  it('should return empty map for empty items array', () => {
    const result = groupByOrderType([]);

    expect(result.size).toBe(0);
  });
});
