feat: tests adicionales data, UI funcional, build OK
This commit is contained in:
30
packages/data/src/__tests__/repositories.test.ts
Normal file
30
packages/data/src/__tests__/repositories.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { db } from '../db/schema';
|
||||
import { ProductorRepository } from '../repositories/ProductorRepository';
|
||||
import { ProductoRepository } from '../repositories/ProductoRepository';
|
||||
|
||||
describe('Repositories', () => {
|
||||
const prodRepo = new ProductorRepository();
|
||||
const prodRepoProd = new ProductoRepository();
|
||||
|
||||
beforeEach(async () => {
|
||||
await db.delete();
|
||||
await db.open();
|
||||
});
|
||||
|
||||
it('crea y obtiene productor', async () => {
|
||||
const p = { id: '1', nombre: 'Productor A', activo: true, createdAt: new Date() };
|
||||
await prodRepo.create(p);
|
||||
const all = await prodRepo.getAll();
|
||||
expect(all.length).toBe(1);
|
||||
expect(all[0].nombre).toBe('Productor A');
|
||||
});
|
||||
|
||||
it('crea producto por productor y previene duplicado mismo nombre', async () => {
|
||||
const prod = { id: 'p1', nombre: 'P1', activo: true, createdAt: new Date() };
|
||||
await prodRepo.create(prod);
|
||||
const producto = { id: 'pr1', productorId: 'p1', nombrePresentacion: 'Café 250gr', precioUnitario: 1000, activo: true, createdAt: new Date() };
|
||||
await prodRepoProd.create(producto);
|
||||
await expect(prodRepoProd.create({ ...producto, id: 'pr2' })).rejects.toThrow('Ya existe un producto con ese nombre para este productor');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user