import { OfertasService } from './ofertas.service';

describe('OfertasService.evaluarOfertas', () => {
  const crear = (ofertas: any[] = []) => {
    const prisma: any = { productos: { findMany: jest.fn().mockResolvedValue([{ id: 'p1', categoria_id: null, marca_id: null }]) } };
    const service = new OfertasService(prisma, {} as any);
    jest.spyOn(service, 'getOfertasActivas').mockResolvedValue(ofertas as any);
    return service;
  };

  it('sin ofertas vigentes usa el precio de lista', async () => {
    const r = await crear().evaluarOfertas({ items: [{ producto_id: 'p1', cantidad: 1, precio_unitario: 25650, precio_lista: 20000 }] } as any, 'e1');
    expect(r.items[0].precio_final).toBe(20000);
  });

  it('sin ofertas ni lista usa el precio base', async () => {
    const r = await crear().evaluarOfertas({ items: [{ producto_id: 'p1', cantidad: 1, precio_unitario: 25650 }] } as any, 'e1');
    expect(r.items[0].precio_final).toBe(25650);
  });
});
