import { describe, it, expect } from 'vitest';
import { ProductModel } from '../../src/schemas/product.schema.js';

describe(ProductModel.name, () => {
  it('is a valid mongoose model', () => {
    expect(ProductModel.modelName).toBe('Product');
  });

  it('has expected schema paths', () => {
    const paths = Object.keys(ProductModel.schema.paths);
    expect(paths).toContain('householdId');
    expect(paths).toContain('name');
    expect(paths).toContain('category');
    expect(paths).toContain('servingSize');
    expect(paths).toContain('servingUnit');
    expect(paths).toContain('nutrition');
    expect(paths).toContain('tags');
    expect(paths).toContain('source');
    expect(paths).toContain('createdBy');
    expect(paths).toContain('deletedAt');
    expect(paths).toContain('createdAt');
    expect(paths).toContain('updatedAt');
  });

  it('has expected indexes defined', () => {
    const indexes = ProductModel.schema.indexes();
    const indexKeys = indexes.map(([key]) => Object.keys(key).join(','));
    expect(indexKeys).toContain('householdId,name,brand,tags');
    expect(indexKeys).toContain('householdId,deletedAt,category');
    expect(indexKeys).toContain('householdId,barcode');
  });
});
