Files
devolucion_proveedores/apps/api/test/app.e2e-spec.ts
T

50 lines
1.5 KiB
TypeScript

import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import cookieParser from 'cookie-parser';
import request from 'supertest';
import { App } from 'supertest/types.js';
import { AppModule } from './../src/app.module.js';
describe('API (e2e)', () => {
let app: INestApplication<App>;
beforeAll(() => {
process.env.SL_URL = 'https://localhost:50000/b1s/v1';
process.env.SL_COMPANY_DB = 'TEST';
process.env.DB_TYPE = 'MSSQL';
});
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleFixture.createNestApplication();
app.setGlobalPrefix('api');
app.use(cookieParser());
await app.init();
});
it('/api/health es público', () => {
return request(app.getHttpServer()).get('/api/health').expect(200).expect({ status: 'ok' });
});
it('/api/auth/info devuelve la sociedad configurada', () => {
return request(app.getHttpServer())
.get('/api/auth/info')
.expect(200)
.expect((res) => {
expect(res.body).toMatchObject({ companyDb: 'TEST', dbType: 'MSSQL', app: { publicado: null } });
expect(res.body.app.version).toMatch(/^\d+\.\d+\.\d+/);
});
});
it('/api/metadata/status exige sesión', () => {
return request(app.getHttpServer()).get('/api/metadata/status').expect(401);
});
afterEach(async () => {
await app.close();
});
});