import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication } from '@nestjs/common'; import * as request from 'supertest'; import { AppModule } from '../../src/app.module'; import { MockAuthService } from '../../src/infrastructure/services/mocks/auth.service.mock'; describe('AuthController (e2e)', () => { let app: INestApplication; beforeEach(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }) .overrideProvider('IAuthService') .useClass(MockAuthService) .compile(); app = moduleFixture.createNestApplication(); await app.init(); }); afterEach(async () => { await app.close(); }); it('/api/auth/login (POST)', () => { return request(app.getHttpServer()) .post('/api/auth/login') .send({ email: 'test@example.com', password: 'password' }) .expect(200) .expect((res) => { expect(res.body.token).toBe('mock-jwt-token-for-testing-purposes'); }); }); });