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>
38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
import { Test } from '@nestjs/testing';
|
|
import type { INestApplication } from '@nestjs/common';
|
|
import { AppModule } from '../src/app.module.js';
|
|
import { SapClientService } from '../src/sap/sap-client.service.js';
|
|
import { SL_RESOURCES } from '../src/sl/sl-resources.js';
|
|
|
|
// Prueba contra un Service Layer real (usa apps/api/.env). Solo con SAP_LIVE=1:
|
|
// SAP_LIVE=1 npm run test:e2e
|
|
describe.skipIf(!process.env.SAP_LIVE)('SAP Service Layer (live)', () => {
|
|
let app: INestApplication;
|
|
let sap: SapClientService;
|
|
|
|
beforeAll(async () => {
|
|
const moduleRef = await Test.createTestingModule({ imports: [AppModule] }).compile();
|
|
app = moduleRef.createNestApplication();
|
|
await app.init();
|
|
sap = app.get(SapClientService);
|
|
}, 30000);
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
it('10 peticiones concurrentes se encolan y no agotan el timeout', async () => {
|
|
const res = await Promise.all(
|
|
Array.from({ length: 10 }, () => sap.get<{ value: unknown[] }>('Items', { $top: 1, $select: 'ItemCode' })),
|
|
);
|
|
expect(res.every((r) => r.status === 200 && Array.isArray(r.data.value))).toBe(true);
|
|
}, 30000);
|
|
|
|
// Detecta nombres de entidad mal escritos o no disponibles en este Service Layer.
|
|
it.each(SL_RESOURCES.map((r) => r.name))('el recurso registrado %s existe en el Service Layer', async (name) => {
|
|
const res = await sap.get<{ value: unknown[] }>(name, { $top: 1 });
|
|
expect(res.status).toBe(200);
|
|
expect(Array.isArray(res.data.value)).toBe(true);
|
|
}, 30000);
|
|
});
|