import { Test, TestingModule } from '@nestjs/testing'; import * as request from 'supertest'; import { INestApplication } from '@nestjs/common'; import { AppModule } from '../src/app.module'; describe('AuthController (e2e)', () => { let app: INestApplication; beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); await app.init(); }); afterAll(async () => { await app.close(); }); it('/auth/login (POST) - success', () => { return request(app.getHttpServer()) .post('/auth/login') .send({ username: 'test', password: 'test' }) .expect(201) .expect({ userId: 1, username: 'test' }); }); it('/auth/login (POST) - failure', () => { return request(app.getHttpServer()) .post('/auth/login') .send({ username: 'wrong', password: 'wrong' }) .expect(401); }); });