feat(sat): reporte diario de errores SAT por proxy
- Agrega tabla sat_proxy_errors con proxy_usado, error_code, stage, message. - sat-client.service.ts expone proxyInfo usado en cada conexión SAT. - sat.service.ts registra errores de bloqueo/devolución del SAT en sat_proxy_errors y guarda proxyUsed en sat_sync_jobs. - Nuevo job sat-proxy-report.job.ts: cron 8 AM CDMX, envía email a ADMIN_EMAIL con errores de las últimas 24h agrupados por proxy/error_code. - Template de email sat-proxy-report.ts y método sendSatProxyReport. - Registra el cron en src/index.ts. - Actualiza docs/SAT-SYNC-IMPLEMENTATION.md.
This commit is contained in:
68
apps/api/scripts/test_e2e_ivan.ts
Normal file
68
apps/api/scripts/test_e2e_ivan.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { generateAccessToken } from '../src/auth/tokens';
|
||||
import axios from 'axios';
|
||||
|
||||
async function main() {
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { email: 'ivan@horuxfin.com' },
|
||||
include: { platformRoles: true }
|
||||
});
|
||||
|
||||
if (!user) { console.log('User not found'); return; }
|
||||
|
||||
// Simulate a FRESH login JWT (with platformRoles)
|
||||
const token = generateAccessToken({
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
role: 'contador',
|
||||
tenantId: 'c52c2f5d-b1ae-45c6-8cc8-b11c9611618a',
|
||||
platformRoles: user.platformRoles.map(r => r.role as any),
|
||||
tokenVersion: user.tokenVersion,
|
||||
});
|
||||
|
||||
const baseURL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000/api';
|
||||
|
||||
async function test(name: string, url: string, headers?: any) {
|
||||
try {
|
||||
const r = await axios.get(`${baseURL}${url}`, {
|
||||
headers: { Authorization: `Bearer ${token}`, ...headers },
|
||||
timeout: 10000,
|
||||
});
|
||||
console.log(`✅ ${name}: ${r.status}`);
|
||||
return r.data;
|
||||
} catch (e: any) {
|
||||
console.log(`❌ ${name}: ${e.response?.status} ${JSON.stringify(e.response?.data)}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=== Ivan loads /despachos/contribuyentes (HORUX 360 default) ===');
|
||||
await test('admin/dashboard/despachos', '/admin/dashboard/despachos');
|
||||
await test('contribuyentes-stats (HORUX)', '/despachos/contribuyentes-stats?año=2026&mes=5');
|
||||
await test('contribuyentes (HORUX)', '/contribuyentes');
|
||||
|
||||
console.log('');
|
||||
console.log('=== Ivan selects Husberto from dropdown ===');
|
||||
const husbertoHeaders = { 'X-View-Tenant': 'd75bf020-2008-4881-ab96-77467bf9e1fd' };
|
||||
await test('contribuyentes-stats (Husberto)', '/despachos/contribuyentes-stats?año=2026&mes=5', husbertoHeaders);
|
||||
await test('contribuyentes (Husberto)', '/contribuyentes', husbertoHeaders);
|
||||
|
||||
// Test other endpoints that might fire on the page
|
||||
await test('carteras (Husberto)', '/carteras', husbertoHeaders);
|
||||
await test('cfdi (Husberto)', '/cfdi', husbertoHeaders);
|
||||
await test('alertas (Husberto)', '/alertas', husbertoHeaders);
|
||||
await test('bancos (Husberto)', '/bancos', husbertoHeaders);
|
||||
await test('tareas (Husberto)', '/tareas?contribuyenteId=all', husbertoHeaders);
|
||||
|
||||
console.log('');
|
||||
console.log('=== Ivan selects AUZA from dropdown ===');
|
||||
const auzaHeaders = { 'X-View-Tenant': '81116985-03cd-4843-97ba-05e8be9917c6' };
|
||||
await test('contribuyentes-stats (AUZA)', '/despachos/contribuyentes-stats?año=2026&mes=5', auzaHeaders);
|
||||
await test('contribuyentes (AUZA)', '/contribuyentes', auzaHeaders);
|
||||
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
main().catch(e => { console.error(e); process.exit(1); });
|
||||
Reference in New Issue
Block a user