feat(api): proxy del Service Layer con registro de recursos
El frontend envía parámetros OData y cuerpo; el backend valida y ejecuta. - GET lista/por clave, POST y PATCH sobre /api/sl/:recurso, solo para recursos registrados (ventas, compras, inventario y maestros estándar); EmployeesInfo no se registra nunca (contiene U_WEB_PASS). - Permisos de menú por recurso (lectura/escritura); catálogos de consulta abiertos a cualquier sesión. Evaluador de patrones compartible (/inventario/* ya no habilita /inventario-x). - Parámetros OData validados con lista cerrada, $top máx. 500, $expand solo si el recurso lo declara, claves validadas y escapadas por tipo, cabeceras B1S-* con lista blanca. $inlinecount y B1S-PageSize automáticos. - configureApp() compartido entre main.ts y e2e (prefijo y límite de 5 mb). - Verificado contra SAP real: los 27 recursos existen; listado con total, filtro, paginación y claves. InventoryRequests no existe en el SL: se registra InventoryTransferRequests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
73fffee2f7
commit
c0990ca83e
15 files changed
+683
-6
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { Test } from '@nestjs/testing';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
import type { NestExpressApplication } from '@nestjs/platform-express';
|
||||
|
||||
// Valores ficticios: los e2e no se conectan a SAP ni a un archivo SQLite.
|
||||
process.env.SAPB1_SL_URL ??= 'https://sap.invalid:50000/b1s/v1';
|
||||
@@ -26,8 +27,24 @@ export const employee = (webUser: string, id = 1, pass = 'secreto'): FakeEmploye
|
||||
U_WEB_PASS: pass,
|
||||
});
|
||||
|
||||
export interface FakeSapRequest {
|
||||
method: string;
|
||||
path: string;
|
||||
query?: Record<string, unknown>;
|
||||
body?: unknown;
|
||||
headers?: Record<string, string>;
|
||||
}
|
||||
|
||||
/** Llamadas que llegaron al "Service Layer" simulado (se vacía en cada createTestApp). */
|
||||
export const sapCalls: FakeSapRequest[] = [];
|
||||
|
||||
/** App completa con EmployeesInfo y la sesión SAP simulados. */
|
||||
export async function createTestApp(employees: FakeEmployee[], adminWebUsers = ''): Promise<INestApplication> {
|
||||
export async function createTestApp(
|
||||
employees: FakeEmployee[],
|
||||
adminWebUsers = '',
|
||||
onSapRequest: (req: FakeSapRequest) => unknown = () => ({}),
|
||||
): Promise<INestApplication> {
|
||||
sapCalls.length = 0;
|
||||
process.env.ADMIN_WEB_USERS = adminWebUsers;
|
||||
const { AppModule } = await import('../../src/app.module.js');
|
||||
const { SapClientService } = await import('../../src/sap/sap-client.service.js');
|
||||
@@ -39,13 +56,18 @@ export async function createTestApp(employees: FakeEmployee[], adminWebUsers = '
|
||||
get: async (_path: string, q: { $filter: string }) => ({
|
||||
data: { value: employees.filter((e) => q.$filter === `U_WEB_USER eq '${e.U_WEB_USER}'`) },
|
||||
}),
|
||||
request: async (req: FakeSapRequest) => {
|
||||
sapCalls.push(req);
|
||||
return { status: 200, headers: {}, data: onSapRequest(req) };
|
||||
},
|
||||
})
|
||||
.overrideProvider(SapSessionService)
|
||||
.useValue({ getSession: async () => ({}), status: () => ({ connected: true }), onModuleDestroy: () => undefined })
|
||||
.compile();
|
||||
|
||||
const app = moduleRef.createNestApplication();
|
||||
app.setGlobalPrefix('api');
|
||||
const { configureApp } = await import('../../src/app.setup.js');
|
||||
const app = moduleRef.createNestApplication<NestExpressApplication>();
|
||||
configureApp(app);
|
||||
await app.init();
|
||||
return app;
|
||||
}
|
||||
Reference in new issue
Block a user