51 lines
1.8 KiB
TypeScript
51 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;
|
||
|
|
}
|