feat(api): permisos de menú en SQLite con API de administración

- 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>
This commit is contained in:
GeorgeandClaude Sonnet 5.5 committed 2026-10-13 18:47:51 -05:00
1 parent 079cedbaed
commit 73fffee2f7
19 files changed
+1104 -55

No files matched your search

+3 -27
View File
@@ -1,36 +1,12 @@
import { Test } from '@nestjs/testing';
import type { INestApplication } from '@nestjs/common';
import request from 'supertest';
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';
const EMPLOYEES = [
{ EmployeeID: 7, FirstName: 'Ana', LastName: 'Pérez', Active: 'tYES', U_WEB_USER: 'ana', U_WEB_PASS: 'secreto' },
];
import { createTestApp, employee } from './support/create-test-app.js';
describe('Auth (e2e, SAP simulado)', () => {
let app: INestApplication;
beforeEach(async () => {
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: q.$filter === "U_WEB_USER eq 'ana'" ? EMPLOYEES : [] },
}),
})
.overrideProvider(SapSessionService)
.useValue({ getSession: async () => ({}), status: () => ({ connected: true }), onModuleDestroy: () => undefined })
.compile();
app = moduleRef.createNestApplication();
app.setGlobalPrefix('api');
await app.init();
app = await createTestApp([employee('ana', 7)]);
});
afterEach(async () => {
@@ -47,7 +23,7 @@ describe('Auth (e2e, SAP simulado)', () => {
it('flujo completo: login -> me -> ruta protegida -> logout -> 401', async () => {
const res = await login('ana', 'secreto').expect(200);
expect(res.body.user).toMatchObject({ webUser: 'ana', empId: 7, firstName: 'Ana' });
expect(res.body.user).toMatchObject({ webUser: 'ana', empId: 7, firstName: 'ana' });
expect(JSON.stringify(res.body)).not.toContain('secreto');
const auth = { Authorization: `Bearer ${res.body.token}` };