2026-10-13 18:29:13 -05:00
|
|
|
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';
|
2026-10-13 19:04:52 -05:00
|
|
|
import { SL_RESOURCES } from '../src/sl/sl-resources.js';
|
2026-10-13 18:29:13 -05:00
|
|
|
|
|
|
|
|
// 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);
|
2026-10-13 19:04:52 -05:00
|
|
|
|
|
|
|
|
// 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);
|
2026-10-13 18:29:13 -05:00
|
|
|
});
|