import { receiptItemHasCategory } from './receipt-item-has-category.helper';
import { ReceiptItem } from '../../models/receipt-item';
import { Product } from '../../schemas/product.schema';
import { Quantity } from '../../models/quantity';
import { ProductCategory } from '../../questions/constants';

describe('receiptItemHasCategory', () => {
  const product: Product = {
    name: 'Test Product',
    contributors: 'Author',
    catalogProductNumber: '123',
    ean: '1234567890123',
    format: 'Hardcover',
    formatDetail: 'Detail',
    volume: '1',
    manufacturer: 'Test Publisher',
  };
  const quantity: Quantity = { quantity: 1 };

  const baseItem: ReceiptItem = {
    id: 1,
    product,
    quantity,
    receiptNumber: 'R-001',
    features: {},
  };

  it('should return false if features property is missing', () => {
    const item = { ...baseItem };
    delete (item as { features?: unknown }).features;
    expect(
      receiptItemHasCategory(item as ReceiptItem, ProductCategory.BookCalendar),
    ).toBe(false);
  });

  it('should return false if category does not match', () => {
    const item = {
      ...baseItem,
      features: { category: ProductCategory.Tolino },
    };
    expect(receiptItemHasCategory(item, ProductCategory.BookCalendar)).toBe(
      false,
    );
  });

  it('should return true if category matches', () => {
    const item = {
      ...baseItem,
      features: { category: ProductCategory.BookCalendar },
    };
    expect(receiptItemHasCategory(item, ProductCategory.BookCalendar)).toBe(
      true,
    );
  });

  it('should return false if category is missing in features', () => {
    const item = { ...baseItem, features: {} };
    expect(receiptItemHasCategory(item, ProductCategory.BookCalendar)).toBe(
      false,
    );
  });
});
