fix(alta): error 400 del servidor ya no se reporta como 'sin conexión'

- API: viviendaCredito.ubicacion ahora opcional (la app web no la exigía;
  el desfase causaba 400 que la app mostraba como fallo de red)
- App: crearAltaCliente distingue conexion/validacion; el 400 muestra
  banner rojo con el detalle de los issues en vez del banner ámbar
- Tests: api 160, alta-clientes 66
This commit is contained in:
2026-08-27 18:51:51 +00:00
parent 5d4293888b
commit 04de7d703f
5 changed files with 95 additions and 22 deletions

View File

@@ -73,3 +73,22 @@ describe('actividadEconomicaLabel', () => {
expect(actividadEconomicaLabel(undefined)).toBeUndefined()
})
})
describe('crearClienteSchema', () => {
const base = {
datosGenerales: { nombreCompleto: 'Cliente Demo', curp: 'CURP123', rfc: 'RFC123' },
viviendaCredito: { proyecto: 'SENDA' },
}
it('acepta un alta sin ubicación (opcional en el formato web)', async () => {
const { crearClienteSchema } = await import('./clientes.controller.js')
expect(() => crearClienteSchema.parse(base)).not.toThrow()
})
it('sigue exigiendo nombre, curp, rfc y proyecto', async () => {
const { crearClienteSchema } = await import('./clientes.controller.js')
expect(() =>
crearClienteSchema.parse({ datosGenerales: { nombreCompleto: '', curp: '', rfc: '' }, viviendaCredito: {} }),
).toThrow()
})
})

View File

@@ -11,7 +11,7 @@ import { NotFoundError, BadRequestError } from '../utils/errors.js'
// ---------- Alta de clientes ----------
const crearClienteSchema = z
export const crearClienteSchema = z
.object({
datosGenerales: z
.object({
@@ -32,7 +32,7 @@ const crearClienteSchema = z
viviendaCredito: z
.object({
proyecto: z.string().min(1),
ubicacion: z.string().min(1),
ubicacion: z.string().optional(),
valorVenta: z.union([z.string(), z.number()]).optional(),
enganche: z.union([z.string(), z.number()]).optional(),
})
@@ -169,7 +169,7 @@ export async function crearCliente(req: Request, res: Response): Promise<void> {
email: dg.email ?? null,
celular: dg.celular ?? null,
proyecto: vc.proyecto,
unidadCodigo: vc.ubicacion, // la "ubicación" del formato es el código de unidad (U-101, etc.)
unidadCodigo: vc.ubicacion ?? '', // la "ubicación" del formato es el código de unidad (U-101, etc.)
payloadJson: JSON.stringify(body),
firmaPng: body.firma?.firmaDataUrl ?? null,
},
@@ -199,7 +199,7 @@ export async function crearCliente(req: Request, res: Response): Promise<void> {
const enganche = aNumero(vc.enganche)
mondayApartadoId = await mondayService.crearApartado({
clienteNombre: dg.nombreCompleto,
unidadCodigo: vc.ubicacion,
unidadCodigo: vc.ubicacion ?? '',
...(enganche > 0 ? { montoApartado: enganche } : {}),
fechaApartado: hoyMas(0),
fechaLimite: hoyMas(15),