Set up PostgreSQL database configuration and enhance application structure
- Added .env.example with database connection details and JWT configuration. - Introduced docker-compose.yml for PostgreSQL service setup with health checks. - Created drizzle.config.ts for database schema and migration management. - Updated nest-cli.json to include Swagger plugin configuration for API documentation. - Enhanced package.json with new database-related scripts and dependencies. - Implemented initial database migrations for user and token management. - Configured application bootstrap process to load environment variables and set up Swagger. - Added shared application configuration in configure-app.ts for consistent setup. - Included unit tests for application configuration and Swagger setup.
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import request from 'supertest';
|
||||
import { App } from 'supertest/types';
|
||||
import { AppModule } from '../src/app.module';
|
||||
import { configureApp } from '../src/common/configure-app';
|
||||
|
||||
describe('Swagger (e2e)', () => {
|
||||
describe('when enabled', () => {
|
||||
let app: INestApplication<App>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
configureApp(app, {
|
||||
NODE_ENV: 'test',
|
||||
SWAGGER_ENABLED: 'true',
|
||||
});
|
||||
await app.init();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('GET /docs returns HTML UI', async () => {
|
||||
const res = await request(app.getHttpServer()).get('/docs').expect(200);
|
||||
expect(res.text).toContain('Swagger UI');
|
||||
});
|
||||
|
||||
it('GET /docs-json includes auth paths', async () => {
|
||||
const res = await request(app.getHttpServer())
|
||||
.get('/docs-json')
|
||||
.expect(200);
|
||||
|
||||
const body = res.body as {
|
||||
paths: Record<string, unknown>;
|
||||
components: { securitySchemes: Record<string, unknown> };
|
||||
};
|
||||
|
||||
expect(body.paths['/auth/login']).toBeDefined();
|
||||
expect(body.paths['/auth/me']).toBeDefined();
|
||||
expect(body.paths['/auth/register']).toBeDefined();
|
||||
expect(body.components.securitySchemes['access-token']).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when production and not explicitly enabled', () => {
|
||||
let app: INestApplication<App>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
configureApp(app, {
|
||||
NODE_ENV: 'production',
|
||||
});
|
||||
await app.init();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
it('GET /docs returns 404', () => {
|
||||
return request(app.getHttpServer()).get('/docs').expect(404);
|
||||
});
|
||||
|
||||
it('GET /docs-json returns 404', () => {
|
||||
return request(app.getHttpServer()).get('/docs-json').expect(404);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user