Created
February 20, 2025 14:50
Revisions
-
Klerith created this gist
Feb 20, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,82 @@ import { Test, TestingModule } from '@nestjs/testing'; import { INestApplication, ValidationPipe } from '@nestjs/common'; import { getRepositoryToken } from '@nestjs/typeorm'; import * as request from 'supertest'; import { Repository } from 'typeorm'; import { AppModule } from '../../../src/app.module'; import { User } from '../../../src/auth/entities/user.entity'; import { validate } from 'uuid'; const testingUser = { email: 'testing.user@google.com', password: 'Abc12345', fullName: 'Testing user', }; const testingAdminUser = { email: 'testing.admin@google.com', password: 'Abc12345', fullName: 'Testing admin', }; describe('AuthModule Private (e2e)', () => { let app: INestApplication; let userRepository: Repository<User>; let token: string; let adminToken: string; beforeAll(async () => { const moduleFixture: TestingModule = await Test.createTestingModule({ imports: [AppModule], }).compile(); app = moduleFixture.createNestApplication(); app.useGlobalPipes( new ValidationPipe({ whitelist: true, forbidNonWhitelisted: true, }), ); await app.init(); userRepository = app.get<Repository<User>>(getRepositoryToken(User)); await userRepository.delete({ email: testingUser.email }); await userRepository.delete({ email: testingAdminUser.email }); }); afterAll(async () => { await app.close(); }); it('should return 401 if no token is provided', async () => { const response = await request(app.getHttpServer()) .get('/auth/private') .send(); }); it('should return new token and user if token is provided', async () => { // Validar que el id es un uuid válido }); it('should return custom object if token is valid', async () => { // Validar la respuesta }); it('should return 401 if admin token is provided', async () => { const response = await request(app.getHttpServer()) .get('/auth/private3') }); it('should return user if admin token is provided', async () => { const response = await request(app.getHttpServer()) .get('/auth/private3') }); });