| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { Test, TestingModule } from '@nestjs/testing';
- import { INestApplication } from '@nestjs/common';
- import * as request from 'supertest';
- import { AppModule } from '../../src/app.module';
- import { ValidationPipe } from '@nestjs/common';
- import { TransformInterceptor } from '../../src/presentation/interceptors/transform.interceptor';
- describe('Company Drivers Endpoint (e2e)', () => {
- let app: INestApplication;
- beforeEach(async () => {
- const moduleFixture: TestingModule = await Test.createTestingModule({
- imports: [AppModule],
- }).compile();
- app = moduleFixture.createNestApplication();
- // Appliquer les mêmes pipes et intercepteurs que dans l'application principale
- app.useGlobalPipes(
- new ValidationPipe({
- whitelist: true,
- transform: true,
- }),
- );
- app.useGlobalInterceptors(new TransformInterceptor());
- await app.init();
- });
- afterEach(async () => {
- await app.close();
- });
- it('/api/companies/:id/drivers (GET) - should return drivers for a company', () => {
- const companyId = 1; // Utiliser un ID de compagnie existant
- return request(app.getHttpServer())
- .get(`/api/companies/${companyId}/drivers`)
- .expect(200)
- .expect((res) => {
- expect(res.body).toHaveProperty('data');
- expect(res.body).toHaveProperty('total');
- expect(res.body).toHaveProperty('page');
- expect(res.body).toHaveProperty('limit');
- expect(Array.isArray(res.body.data)).toBe(true);
- });
- });
- it('/api/companies/:id/drivers (GET) - should return 404 for non-existent company', () => {
- const nonExistentCompanyId = 99999;
- return request(app.getHttpServer())
- .get(`/api/companies/${nonExistentCompanyId}/drivers`)
- .expect(404);
- });
- it('/api/companies/:id/drivers (GET) - should support pagination', () => {
- const companyId = 1;
- return request(app.getHttpServer())
- .get(`/api/companies/${companyId}/drivers?page=1&limit=5`)
- .expect(200)
- .expect((res) => {
- expect(res.body.page).toBe(1);
- expect(res.body.limit).toBe(5);
- });
- });
- });
|