import { describe, it, expect } from 'vitest';
import { calculateLoyaltyPointsValue } from './calculate-loyalty-points-value.helper';
import { RewardSelectionItem } from '@isa/checkout/data-access';

describe('calculateLoyaltyPointsValue', () => {
  it('should return item loyalty points when available', () => {
    const item: RewardSelectionItem = {
      item: {
        loyalty: { value: 100 },
      },
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: undefined,
      availabilityPrice: undefined,
      catalogRewardPoints: 50,
    } as RewardSelectionItem;

    const result = calculateLoyaltyPointsValue(item);

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

  it('should return catalog loyalty points when item points not available', () => {
    const item: RewardSelectionItem = {
      item: {},
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: undefined,
      availabilityPrice: undefined,
      catalogRewardPoints: 50,
    } as RewardSelectionItem;

    const result = calculateLoyaltyPointsValue(item);

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

  it('should return 0 when no loyalty points available', () => {
    const item: RewardSelectionItem = {
      item: {},
      cartQuantity: 1,
      rewardCartQuantity: 0,
      catalogPrice: undefined,
      availabilityPrice: undefined,
      catalogRewardPoints: undefined,
    } as RewardSelectionItem;

    const result = calculateLoyaltyPointsValue(item);

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