Files
Claro-cases/src/mocks/handlers.ts
T
bryan_garcia 8f044567c0 feat: migrar dashboard a React 19 + TypeScript + Vite + Tailwind v4
- Módulo HITL (/cases): 6 patrones de formularios dinámicos para 53 tipos de caso con validación Zod
- Módulo Monitor (/monitor): streaming token-a-token en tiempo real, auto-scroll y notas internas vía WebSocket
- Arquitectura híbrida: REST (canal autoritativo) + WebSocket (difusión/streaming)
- MSW para desarrollo sin backend, hooks de notificaciones/sonido/título preservados
- Backend legacy movido a legacy/, archivos residuales eliminados de raíz
2026-07-23 18:27:03 -05:00

277 lines
9.9 KiB
TypeScript

// @ts-nocheck
import { http, HttpResponse, delay } from 'msw';
// --- Mock Data ---
// NOTE: All tipoSolicitud values MUST match toolName entries in src/data/caseTypeDefinitions.ts
const mockCases = [
{
id: 1,
title: 'Validación de Proporcionales - Móvil',
description: 'Validar si el cliente tiene cobros proporcionales en su línea móvil.',
status: 'PENDING',
externalId: 'EXT-001',
cedula: '1020304050',
tipoSolicitud: 'Validar_Proporcionales_Movil',
applicative: 'AC+',
uiPattern: 'CONFIRMATION_WITH_VALUE',
payload: { nombre: 'Juan Pérez', telefono: '3101234567', linea: '3008001234' },
handlingTime: 0,
createdAt: new Date(Date.now() - 600000).toISOString(),
},
{
id: 2,
title: 'Plan de Pagos Equipo Financiado',
description: 'Cliente solicita plan de pagos para equipo financiado ASCARD.',
status: 'IN_PROGRESS',
externalId: 'EXT-002',
cedula: '1122334455',
tipoSolicitud: 'Plan_De_Pagos_EF',
applicative: 'ASCARD',
uiPattern: 'MULTI_FIELD_FORM',
payload: { equipo: 'iPhone 15', valor_restante: 1200000, linea: '3008005678' },
handlingTime: 45,
createdAt: new Date(Date.now() - 1800000).toISOString(),
},
{
id: 3,
title: 'Activación Ajuste Creer en el Cliente - DiMe',
description: 'Cliente solicita ajuste por cobro incorrecto en factura.',
status: 'PENDING',
externalId: 'EXT-003',
cedula: '9988776655',
tipoSolicitud: 'Activa_Creer_Cliente',
applicative: 'DiMe',
uiPattern: 'CONFIRMATION_WITH_VALUE',
payload: { linea: '3008009012', valor_reclamado: 45000, periodo: '2025-03' },
handlingTime: 0,
createdAt: new Date(Date.now() - 3600000).toISOString(),
},
{
id: 4,
title: 'Cambio de Ciclo de Facturación',
description: 'Solicitud de cambio de ciclo de facturación a día 15.',
status: 'RESOLVED',
externalId: 'EXT-004',
cedula: '5566778899',
tipoSolicitud: 'Cambio_Ciclos_Movil',
applicative: 'Formatos SGCS',
uiPattern: 'SIMPLE_CONFIRMATION',
payload: { linea: '3008003456', ciclo_actual: '10' },
handlingTime: 120,
createdAt: new Date(Date.now() - 7200000).toISOString(),
},
{
id: 5,
title: 'Escalamiento de Pago No Abonado - Hogar',
description: 'Escalamiento de pago para devolución por servicio no prestado.',
status: 'FAILED',
externalId: 'EXT-005',
cedula: '4433221100',
tipoSolicitud: 'Escalar_Pagos_No_Abonados',
applicative: 'Mi asistencia 360',
uiPattern: 'MULTI_FIELD_FORM',
payload: { linea: '3008007890', monto: 85000, motivo: 'Servicio no prestado en fecha 01/03' },
handlingTime: 300,
createdAt: new Date(Date.now() - 14400000).toISOString(),
},
{
id: 6,
title: 'Desbloqueo IMEI - Phone Protect',
description: 'Solicitud de desbloqueo de IMEI por cambio de equipo.',
status: 'PENDING',
externalId: 'EXT-006',
cedula: '6677889900',
tipoSolicitud: 'IMEI_EF',
applicative: 'ASCARD',
uiPattern: 'MULTI_FIELD_FORM',
payload: { linea: '3008002345', imei_actual: '356938123456789', imei_nuevo: '356938987654321' },
handlingTime: 0,
createdAt: new Date(Date.now() - 900000).toISOString(),
},
{
id: 7,
title: 'Validación OTT - Postventa Hogar',
description: 'Cliente reporta cobro en postventa hogar por deco adicional.',
status: 'PENDING',
externalId: 'EXT-007',
cedula: '1234567890',
tipoSolicitud: 'Validar_OTT_1',
applicative: 'RR',
uiPattern: 'MULTI_FIELD_FORM',
payload: { direccion: 'Calle 50 #20-30', ciudad: 'Bogotá', servicio: 'Internet 200MB' },
handlingTime: 0,
createdAt: new Date(Date.now() - 300000).toISOString(),
},
{
id: 8,
title: 'Validación de Identidad - Cliente',
description: 'Validar los datos del cliente para contraste de identidad.',
status: 'PENDING',
externalId: 'EXT-008',
cedula: '1357924680',
tipoSolicitud: 'Validar_Identidad_Movil',
applicative: 'AC+',
uiPattern: 'SIMPLE_CONFIRMATION',
payload: { nombre: 'María López', telefono: '3109876543', email: '[email protected]' },
handlingTime: 0,
createdAt: new Date(Date.now() - 480000).toISOString(),
},
{
id: 9,
title: 'Validación de Cambio de Plan - Móvil',
description: 'Cliente solicita validar si se ha cambiado el plan recientemente.',
status: 'IN_PROGRESS',
externalId: 'EXT-009',
cedula: '2468135790',
tipoSolicitud: 'Validar_Cambio_Plan_Movil',
applicative: 'AC+',
uiPattern: 'MULTI_FIELD_FORM',
payload: { linea: '6012345678', plan_actual: 'Internet 100MB', plan_deseado: 'Internet 300MB' },
handlingTime: 30,
createdAt: new Date(Date.now() - 2400000).toISOString(),
},
{
id: 10,
title: 'Validación de Moras - Móvil',
description: 'Cliente solicita validar información sobre moras en su línea.',
status: 'PENDING',
externalId: 'EXT-010',
cedula: '3692581470',
tipoSolicitud: 'Validar_Moras_Movil',
applicative: 'AC+',
uiPattern: 'SIMPLE_CONFIRMATION',
payload: { linea: '3008006543', valor_mora: 25000, periodo: '2025-02' },
handlingTime: 0,
createdAt: new Date(Date.now() - 1200000).toISOString(),
},
];
const mockConversations = [
{
id: 'conv-1',
clientId: 'CLI-001',
agentId: 'AGENT-01',
status: 'ACTIVE',
messages: [
{ id: 'm1', role: 'user', content: 'Hola, necesito ayuda con mi factura', timestamp: new Date(Date.now() - 300000).toISOString() },
{ id: 'm2', role: 'agent', content: 'Claro, con gusto le ayudo. ¿Podría indicarme su número de línea?', timestamp: new Date(Date.now() - 280000).toISOString() },
{ id: 'm3', role: 'user', content: '3008001234', timestamp: new Date(Date.now() - 260000).toISOString() },
{ id: 'm4', role: 'agent', content: 'Gracias. Veo que tiene un cobro de $45,000 en su factura de marzo que no corresponde. ¿Le parece si procedemos con el ajuste?', timestamp: new Date(Date.now() - 240000).toISOString() },
],
createdAt: new Date(Date.now() - 600000).toISOString(),
},
{
id: 'conv-2',
clientId: 'CLI-002',
agentId: 'AGENT-02',
status: 'ACTIVE',
messages: [
{ id: 'm5', role: 'user', content: 'Quiero saber el estado de mi solicitud de desbloqueo IMEI', timestamp: new Date(Date.now() - 180000).toISOString() },
{ id: 'm6', role: 'agent', content: 'Permítame verificar. Su solicitud está en proceso de revisión. El tiempo estimado es de 24 horas hábiles.', timestamp: new Date(Date.now() - 160000).toISOString() },
],
createdAt: new Date(Date.now() - 180000).toISOString(),
},
{
id: 'conv-3',
clientId: 'CLI-003',
agentId: 'AGENT-01',
status: 'WAITING_HITL',
messages: [
{ id: 'm7', role: 'user', content: 'Necesito un plan de pagos para mi equipo financiado', timestamp: new Date(Date.now() - 90000).toISOString() },
{ id: 'm8', role: 'agent', content: 'Entiendo. Voy a transferir su caso a un asesor especializado que podrá ayudarle con el plan de pagos.', timestamp: new Date(Date.now() - 70000).toISOString() },
{ id: 'm9', role: 'system', content: 'Caso transferido a HITL - Plan de Pagos', timestamp: new Date(Date.now() - 60000).toISOString() },
],
createdAt: new Date(Date.now() - 120000).toISOString(),
},
];
// --- REST Handlers ---
export const handlers = [
// GET /api/v1/cases
http.get('*/api/v1/cases', async ({ request }) => {
await delay(200);
const url = new URL(request.url);
const status = url.searchParams.get('status');
const applicative = url.searchParams.get('applicative');
const search = url.searchParams.get('search')?.toLowerCase();
const offset = parseInt(url.searchParams.get('offset') || '0');
const limit = parseInt(url.searchParams.get('limit') || '20');
let filtered = [...mockCases];
if (status && status !== 'ALL') {
filtered = filtered.filter((c) => c.status === status);
}
if (applicative) {
filtered = filtered.filter((c) => c.applicative === applicative);
}
if (search) {
filtered = filtered.filter(
(c) =>
c.title.toLowerCase().includes(search) ||
c.externalId.toLowerCase().includes(search) ||
c.cedula.includes(search) ||
c.tipoSolicitud.toLowerCase().includes(search),
);
}
const total = filtered.length;
const items = filtered.slice(offset, offset + limit);
return HttpResponse.json({ items, total });
}),
// GET /api/v1/cases/:id
http.get('*/api/v1/cases/:id', async ({ params }) => {
await delay(150);
const id = parseInt(params.id as string);
const caseItem = mockCases.find((c) => c.id === id);
if (!caseItem) {
return new HttpResponse(null, { status: 404 });
}
return HttpResponse.json(caseItem);
}),
// POST /api/v1/cases/:id/resolve
http.post('*/api/v1/cases/:id/resolve', async ({ params, request }) => {
await delay(300);
const id = parseInt(params.id as string);
const body = (await request.json()) as Record<string, unknown>;
const index = mockCases.findIndex((c) => c.id === id);
if (index === -1) {
return new HttpResponse(null, { status: 404 });
}
mockCases[index] = {
...mockCases[index],
status: 'RESOLVED',
handlingTime: (body.handlingTime as number) || mockCases[index].handlingTime,
payload: { ...mockCases[index].payload, ...(body.payload as Record<string, unknown>) },
};
return HttpResponse.json(mockCases[index]);
}),
// GET /api/v1/conversations/active
http.get('*/api/v1/conversations/active', async () => {
await delay(200);
return HttpResponse.json(mockConversations);
}),
// GET /api/v1/conversations/:id
http.get('*/api/v1/conversations/:id', async ({ params }) => {
await delay(150);
const conversation = mockConversations.find((c) => c.id === params.id);
if (!conversation) {
return new HttpResponse(null, { status: 404 });
}
return HttpResponse.json(conversation);
}),
];