import { describe, it, expect } from 'vitest';
import { itemSelectionChanged } from './item-selection-changed.helper';
import { RewardSelectionItem } from '@isa/checkout/data-access';

describe('itemSelectionChanged', () => {
  it('should return true when result items are undefined', () => {
    const inputItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 1,
        rewardCartQuantity: 0,
      } as RewardSelectionItem,
    ];

    const result = itemSelectionChanged(inputItems, undefined);

    expect(result).toBe(true);
  });

  it('should return false when quantities are unchanged', () => {
    const inputItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 1,
        rewardCartQuantity: 0,
      } as RewardSelectionItem,
    ];

    const resultItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 1,
        rewardCartQuantity: 0,
      } as RewardSelectionItem,
    ];

    const result = itemSelectionChanged(inputItems, resultItems);

    expect(result).toBe(false);
  });

  it('should return true when cart quantity changed', () => {
    const inputItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 1,
        rewardCartQuantity: 0,
      } as RewardSelectionItem,
    ];

    const resultItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 2,
        rewardCartQuantity: 0,
      } as RewardSelectionItem,
    ];

    const result = itemSelectionChanged(inputItems, resultItems);

    expect(result).toBe(true);
  });

  it('should return true when reward cart quantity changed', () => {
    const inputItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 1,
        rewardCartQuantity: 0,
      } as RewardSelectionItem,
    ];

    const resultItems: RewardSelectionItem[] = [
      {
        item: { product: { ean: '123' } },
        cartQuantity: 1,
        rewardCartQuantity: 1,
      } as RewardSelectionItem,
    ];

    const result = itemSelectionChanged(inputItems, resultItems);

    expect(result).toBe(true);
  });
});
