import { getReceiptItemProductCategory } from './get-receipt-item-product-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('getReceiptItemProductCategory', () => {
  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 ProductCategory.Unknown if features property is missing', () => {
    const item = { ...baseItem };
    delete (item as { features?: unknown }).features;
    expect(getReceiptItemProductCategory(item as ReceiptItem)).toBe(
      ProductCategory.Unknown,
    );
  });

  it('should return ProductCategory.Unknown if category is not set', () => {
    const item = { ...baseItem, features: {} };
    expect(getReceiptItemProductCategory(item)).toBe(ProductCategory.Unknown);
  });

  it('should return the category if set in features', () => {
    const item = {
      ...baseItem,
      features: { category: ProductCategory.BookCalendar },
    };
    expect(getReceiptItemProductCategory(item)).toBe(
      ProductCategory.BookCalendar,
    );
  });

  it('should return ProductCategory.Unknown if category is set to a falsy value', () => {
    const item = { ...baseItem, features: { category: '' } };
    expect(getReceiptItemProductCategory(item)).toBe(ProductCategory.Unknown);
  });
});
