Fase 1 - UI: dark mode, skeletons, toasts Fase 2 - Filtros: avanzados Mi día, búsqueda global Ctrl+K Fase 3 - Datos: export Excel, notas apartados, auditoría Fase 4 - Dashboard: gráficas vendedor + métricas uso Fase 5 - Responsive: tablets optimizadas Fase 6 - PWA: IndexedDB offline, push notifications Backend: 3 tablas nuevas, 6 services, 6 endpoints nuevos 721 API tests + fronts verdes.
55 lines
1.8 KiB
TypeScript
55 lines
1.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
// ---------- Prisma mockeado ----------
|
|
|
|
const prismaMock = vi.hoisted(() => ({
|
|
notaApartado: {
|
|
create: vi.fn(),
|
|
findMany: vi.fn(),
|
|
},
|
|
}))
|
|
|
|
vi.mock('./prisma.js', () => ({ prisma: prismaMock }))
|
|
|
|
import { crearNota, listarNotas } from './nota-apartado.service.js'
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('crearNota', () => {
|
|
it('crea una nota con los datos correctos', async () => {
|
|
const notaFake = { id: 'nota-1', apartadoId: 'apt-1', usuarioId: 'u1', contenido: 'Hola', createdAt: new Date() }
|
|
prismaMock.notaApartado.create.mockResolvedValue(notaFake)
|
|
|
|
const resultado = await crearNota('apt-1', 'u1', 'Hola')
|
|
expect(prismaMock.notaApartado.create).toHaveBeenCalledWith({
|
|
data: { apartadoId: 'apt-1', usuarioId: 'u1', contenido: 'Hola' },
|
|
})
|
|
expect(resultado).toEqual(notaFake)
|
|
})
|
|
})
|
|
|
|
describe('listarNotas', () => {
|
|
it('retorna notas ordenadas por createdAt desc', async () => {
|
|
const notasFake = [
|
|
{ id: 'nota-2', apartadoId: 'apt-1', usuarioId: 'u1', contenido: 'B', createdAt: new Date('2026-09-02') },
|
|
{ id: 'nota-1', apartadoId: 'apt-1', usuarioId: 'u1', contenido: 'A', createdAt: new Date('2026-09-01') },
|
|
]
|
|
prismaMock.notaApartado.findMany.mockResolvedValue(notasFake)
|
|
|
|
const resultado = await listarNotas('apt-1')
|
|
expect(prismaMock.notaApartado.findMany).toHaveBeenCalledWith({
|
|
where: { apartadoId: 'apt-1' },
|
|
orderBy: { createdAt: 'desc' },
|
|
})
|
|
expect(resultado).toEqual(notasFake)
|
|
})
|
|
|
|
it('retorna array vacío si no hay notas', async () => {
|
|
prismaMock.notaApartado.findMany.mockResolvedValue([])
|
|
const resultado = await listarNotas('apt-inexistente')
|
|
expect(resultado).toEqual([])
|
|
})
|
|
})
|