auth.e2e-spec.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { Test, TestingModule } from '@nestjs/testing';
  2. import { INestApplication } from '@nestjs/common';
  3. import * as request from 'supertest';
  4. import { AppModule } from '../../src/app.module';
  5. import { MockAuthService } from '../../src/infrastructure/services/mocks/auth.service.mock';
  6. describe('AuthController (e2e)', () => {
  7. let app: INestApplication;
  8. beforeEach(async () => {
  9. const moduleFixture: TestingModule = await Test.createTestingModule({
  10. imports: [AppModule],
  11. })
  12. .overrideProvider('IAuthService')
  13. .useClass(MockAuthService)
  14. .compile();
  15. app = moduleFixture.createNestApplication();
  16. await app.init();
  17. });
  18. afterEach(async () => {
  19. await app.close();
  20. });
  21. it('/api/auth/login (POST)', () => {
  22. return request(app.getHttpServer())
  23. .post('/api/auth/login')
  24. .send({ email: 'test@example.com', password: 'password' })
  25. .expect(200)
  26. .expect((res) => {
  27. expect(res.body.token).toBe('mock-jwt-token-for-testing-purposes');
  28. });
  29. });
  30. });