feat(round-robin): reparto solo con el equipo 'vendedores' de Monday

- obtenerVendedores ahora lee el team de Monday (MONDAY_RR_TEAM,
  default 'vendedores') con cache de 1 h; MONDAY_RR_USER_IDS queda como
  override manual.
- Escrituras a columnas status resuelven el label real sin importar
  mayusculas: si renombran labels en la UI de Monday (paso con
  NUEVO→Nuevo) el API sigue escribiendo en vez de tronar con 502.
- mapearLead: un status nunca escrito (value null) se lee como vacio;
  Monday regresaba el label default del tablero como texto y el
  round-robin creia que el lead estaba descartado.
This commit is contained in:
2026-09-04 02:39:37 +00:00
parent f382987fbf
commit d4fc9ee892
5 changed files with 127 additions and 15 deletions

View File

@@ -110,7 +110,7 @@ function mondayMock(leads: LeadMonday[], oportunidades: OportunidadMonday[] = []
this.ventas.push(datos)
return `vta-${this.ventas.length}`
},
async getUsuariosWorkspace() {
async getUsuariosEquipo(_nombre: string) {
return VENDEDORES
},
}
@@ -244,9 +244,9 @@ describe('AutomatizacionesService.runRoundRobin', () => {
expect(monday.asignaciones).toEqual([{ itemId: '2', userId: 101 }])
})
it('cachea los vendedores del workspace en el estado (una sola llamada)', async () => {
it('cachea los vendedores del equipo en el estado (una sola llamada dentro del TTL)', async () => {
const monday = mondayMock([])
const spy = vi.spyOn(monday, 'getUsuariosWorkspace')
const spy = vi.spyOn(monday, 'getUsuariosEquipo')
const state = stateEnMemoria()
const svc = crearServicio(monday, state)
const v1 = await svc.obtenerVendedores()
@@ -254,6 +254,18 @@ describe('AutomatizacionesService.runRoundRobin', () => {
expect(v1.map((v) => v.id)).toEqual([101, 102, 103])
expect(v2).toEqual(v1)
expect(spy).toHaveBeenCalledTimes(1)
expect(spy.mock.calls[0]?.[0]).toBe('vendedores') // equipo por default
})
it('cache con formato viejo (arreglo sin ts) se descarta y re-consulta', async () => {
const monday = mondayMock([])
const spy = vi.spyOn(monday, 'getUsuariosEquipo')
const state = stateEnMemoria()
state.mapa.set('rr:vendedores', JSON.stringify([{ id: 999, nombre: 'Viejo', email: '' }]))
const svc = crearServicio(monday, state)
const v = await svc.obtenerVendedores()
expect(v.map((x) => x.id)).toEqual([101, 102, 103])
expect(spy).toHaveBeenCalledTimes(1)
})
})