- SQLite (better-sqlite3 + TypeORM, WAL) con tabla menu_permissions (usuario web, patrón de ruta); archivo fuera del repo. - GET /api/user/menu para el frontend; GET/PUT/DELETE /api/permissions solo para administradores (acceso "*"). - ADMIN_WEB_USERS garantiza el acceso total al arrancar; no se puede quitar el "*" al último administrador (409, dentro de una transacción). - Patrones validados (`*`, `/modulo/ruta`, `/modulo/*`). A diferencia del frontend anterior, `/inventario/*` ya no habilita `/inventario-x`. - Helper de e2e compartido (SAP simulado, SQLite en memoria). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { Test } from '@nestjs/testing';
|
|
import type { INestApplication } from '@nestjs/common';
|
|
|
|
// 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';
|
|
process.env.SAPB1_SL_COMPANYDB ??= 'DB';
|
|
process.env.SAPB1_SL_USER ??= 'u';
|
|
process.env.SAPB1_SL_PASSWORD ??= 'p';
|
|
process.env.SQLITE_PATH = ':memory:';
|
|
|
|
export interface FakeEmployee {
|
|
EmployeeID: number;
|
|
FirstName: string;
|
|
LastName: string;
|
|
Active: string;
|
|
U_WEB_USER: string;
|
|
U_WEB_PASS: string;
|
|
}
|
|
|
|
export const employee = (webUser: string, id = 1, pass = 'secreto'): FakeEmployee => ({
|
|
EmployeeID: id,
|
|
FirstName: webUser,
|
|
LastName: 'Test',
|
|
Active: 'tYES',
|
|
U_WEB_USER: webUser,
|
|
U_WEB_PASS: pass,
|
|
});
|
|
|
|
/** App completa con EmployeesInfo y la sesión SAP simulados. */
|
|
export async function createTestApp(employees: FakeEmployee[], adminWebUsers = ''): Promise<INestApplication> {
|
|
process.env.ADMIN_WEB_USERS = adminWebUsers;
|
|
const { AppModule } = await import('../../src/app.module.js');
|
|
const { SapClientService } = await import('../../src/sap/sap-client.service.js');
|
|
const { SapSessionService } = await import('../../src/sap/sap-session.service.js');
|
|
|
|
const moduleRef = await Test.createTestingModule({ imports: [AppModule] })
|
|
.overrideProvider(SapClientService)
|
|
.useValue({
|
|
get: async (_path: string, q: { $filter: string }) => ({
|
|
data: { value: employees.filter((e) => q.$filter === `U_WEB_USER eq '${e.U_WEB_USER}'`) },
|
|
}),
|
|
})
|
|
.overrideProvider(SapSessionService)
|
|
.useValue({ getSession: async () => ({}), status: () => ({ connected: true }), onModuleDestroy: () => undefined })
|
|
.compile();
|
|
|
|
const app = moduleRef.createNestApplication();
|
|
app.setGlobalPrefix('api');
|
|
await app.init();
|
|
return app;
|
|
}
|