feat(purga): Monday eliminado completamente del sistema
14 servicios eliminados, 7 controllers local-only, crons locales, config sin MONDAY_*, frontend sin banners/avisos Monday. 552 tests API + 7 apps construidas.
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { construirResumen, ReportesService, type DatosResumen } from './reportes.service.js'
|
||||
import type { LeadMonday, OportunidadMonday, Unidad } from './monday.service.js'
|
||||
import type { LeadFila, OportunidadFila, Unidad } from './reportes.service.js'
|
||||
import type { PlanPago } from './cobranza.service.js'
|
||||
|
||||
// ---------- Fixtures ----------
|
||||
|
||||
/** Lead del tablero Leads (captura ligera; fuente de la sección leads) */
|
||||
function lead(id: string, overrides: Partial<LeadMonday> = {}): LeadMonday {
|
||||
function lead(id: string, overrides: Partial<LeadFila> = {}): LeadFila {
|
||||
return {
|
||||
id,
|
||||
nombre: `Lead ${id}`,
|
||||
@@ -22,7 +22,7 @@ function lead(id: string, overrides: Partial<LeadMonday> = {}): LeadMonday {
|
||||
}
|
||||
|
||||
/** Afluencia del board Oportunidades (fuente del perfilamiento de afluencia) */
|
||||
function afluencia(id: string, overrides: Partial<OportunidadMonday> = {}): OportunidadMonday {
|
||||
function afluencia(id: string, overrides: Partial<OportunidadFila> = {}): OportunidadFila {
|
||||
return {
|
||||
id,
|
||||
nombre: `Lead ${id}`,
|
||||
@@ -39,7 +39,7 @@ function afluencia(id: string, overrides: Partial<OportunidadMonday> = {}): Opor
|
||||
}
|
||||
}
|
||||
|
||||
function op(id: string, etapa: string): OportunidadMonday {
|
||||
function op(id: string, etapa: string): OportunidadFila {
|
||||
return afluencia(id, { nombre: `Cliente ${id}`, createdAt: '2026-08-01T09:00:00Z', etapa, unidadCodigo: 'U-101' })
|
||||
}
|
||||
|
||||
@@ -311,61 +311,51 @@ describe('construirResumen', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// ---------- ReportesService (cache en memoria) ----------
|
||||
// ---------- ReportesService (resumen desde tablas locales, cache en memoria) ----------
|
||||
|
||||
describe('ReportesService', () => {
|
||||
function mondayMock() {
|
||||
function datosLocales() {
|
||||
return {
|
||||
llamadas: { leads: 0, oportunidades: 0, unidades: 0, actividades: 0 },
|
||||
async getLeads(): Promise<LeadMonday[]> {
|
||||
this.llamadas.leads++
|
||||
return [lead('1')]
|
||||
},
|
||||
async getOportunidades(): Promise<OportunidadMonday[]> {
|
||||
this.llamadas.oportunidades++
|
||||
return [afluencia('1')]
|
||||
},
|
||||
async getUnidades(): Promise<Unidad[]> {
|
||||
this.llamadas.unidades++
|
||||
return [unidad('U-101', 'ATELIER', 'DISPONIBLE')]
|
||||
},
|
||||
async getActividadesAbiertas(): Promise<number> {
|
||||
this.llamadas.actividades++
|
||||
return 7
|
||||
},
|
||||
leads: [lead('1')],
|
||||
oportunidades: [afluencia('1')],
|
||||
unidades: [unidad('U-101', 'ATELIER', 'DISPONIBLE')],
|
||||
actividadesAbiertas: 7,
|
||||
}
|
||||
}
|
||||
|
||||
it('agrega todas las fuentes en una sola respuesta', async () => {
|
||||
const monday = mondayMock()
|
||||
const svc = new ReportesService(monday, async () => [plan('a', { pagos: [pago('p1', '2026-09-01', 50000)] })])
|
||||
it('agrega todas las fuentes (tablas locales) en una sola respuesta', async () => {
|
||||
const cargarDatos = vi.fn(async () => datosLocales())
|
||||
const svc = new ReportesService(
|
||||
async () => [plan('a', { pagos: [pago('p1', '2026-09-01', 50000)] })],
|
||||
{ cargarDatosLocales: cargarDatos },
|
||||
)
|
||||
const r = await svc.resumen()
|
||||
expect(r.leads.total).toBe(1) // la sección leads se alimenta del tablero Leads
|
||||
expect(r.leads.total).toBe(1) // la sección leads se alimenta de LeadCaptura board LEADS
|
||||
expect(r.oportunidades.total).toBe(1)
|
||||
expect(r.unidades.total).toBe(1)
|
||||
expect(r.cobranza.planes.activos).toBe(1)
|
||||
expect(r.actividadesAbiertas).toBe(7)
|
||||
expect(monday.llamadas.leads).toBe(1)
|
||||
expect(monday.llamadas.oportunidades).toBe(1)
|
||||
expect(r.parcial).toBe(false) // los datos locales son completos
|
||||
expect(cargarDatos).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('cachea 60 s: la segunda llamada no vuelve a Monday ni a Prisma', async () => {
|
||||
it('cachea 60 s: la segunda llamada no vuelve a leer las tablas locales', async () => {
|
||||
vi.useFakeTimers()
|
||||
try {
|
||||
vi.setSystemTime(new Date('2026-08-22T12:00:00'))
|
||||
const monday = mondayMock()
|
||||
const cargarDatos = vi.fn(async () => datosLocales())
|
||||
const cargarPlanes = vi.fn(async () => [plan('a', { pagos: [pago('p1', '2026-09-01', 50000)] })])
|
||||
const svc = new ReportesService(monday, cargarPlanes)
|
||||
const svc = new ReportesService(cargarPlanes, { cargarDatosLocales: cargarDatos })
|
||||
|
||||
await svc.resumen()
|
||||
await svc.resumen()
|
||||
expect(monday.llamadas.oportunidades).toBe(1)
|
||||
expect(cargarDatos).toHaveBeenCalledTimes(1)
|
||||
expect(cargarPlanes).toHaveBeenCalledTimes(1)
|
||||
|
||||
// 61 s después el cache expira y se vuelve a consultar
|
||||
vi.setSystemTime(new Date('2026-08-22T12:01:01'))
|
||||
await svc.resumen()
|
||||
expect(monday.llamadas.oportunidades).toBe(2)
|
||||
expect(cargarDatos).toHaveBeenCalledTimes(2)
|
||||
expect(cargarPlanes).toHaveBeenCalledTimes(2)
|
||||
} finally {
|
||||
vi.useRealTimers()
|
||||
|
||||
Reference in New Issue
Block a user