✅ FASE 7 COMPLETADA: Testing y Lanzamiento - PROYECTO FINALIZADO
Some checks failed
CI/CD Pipeline / 🧪 Tests (push) Has been cancelled
CI/CD Pipeline / 🏗️ Build (push) Has been cancelled
CI/CD Pipeline / 🚀 Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / 🚀 Deploy to Production (push) Has been cancelled
CI/CD Pipeline / 🏷️ Create Release (push) Has been cancelled
CI/CD Pipeline / 🧹 Cleanup (push) Has been cancelled
Some checks failed
CI/CD Pipeline / 🧪 Tests (push) Has been cancelled
CI/CD Pipeline / 🏗️ Build (push) Has been cancelled
CI/CD Pipeline / 🚀 Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / 🚀 Deploy to Production (push) Has been cancelled
CI/CD Pipeline / 🏷️ Create Release (push) Has been cancelled
CI/CD Pipeline / 🧹 Cleanup (push) Has been cancelled
Implementados 4 módulos con agent swarm: 1. TESTING FUNCIONAL (Jest) - Configuración Jest + ts-jest - Tests unitarios: auth, booking, court (55 tests) - Tests integración: routes (56 tests) - Factories y utilidades de testing - Coverage configurado (70% servicios) - Scripts: test, test:watch, test:coverage 2. TESTING DE USUARIO (Beta) - Sistema de beta testers - Feedback con categorías y severidad - Beta issues tracking - 8 testers de prueba creados - API completa para gestión de feedback 3. DOCUMENTACIÓN COMPLETA - API.md - 150+ endpoints documentados - SETUP.md - Guía de instalación - DEPLOY.md - Deploy en VPS - ARCHITECTURE.md - Arquitectura del sistema - APP_STORE.md - Material para stores - Postman Collection completa - PM2 ecosystem config - Nginx config con SSL 4. GO LIVE Y PRODUCCIÓN - Sistema de monitoreo (logs, health checks) - Servicio de alertas multi-canal - Pre-deploy check script - Docker + docker-compose producción - Backup automatizado - CI/CD GitHub Actions - Launch checklist completo ESTADÍSTICAS FINALES: - Fases completadas: 7/7 - Archivos creados: 250+ - Líneas de código: 60,000+ - Endpoints API: 150+ - Tests: 110+ - Documentación: 5,000+ líneas PROYECTO COMPLETO Y LISTO PARA PRODUCCIÓN
This commit is contained in:
146
backend/tests/utils/auth.ts
Normal file
146
backend/tests/utils/auth.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { User } from '@prisma/client';
|
||||
import { createUser, createAdminUser, CreateUserInput } from './factories';
|
||||
import { UserRole } from '../../src/utils/constants';
|
||||
|
||||
// Test JWT secrets
|
||||
const JWT_SECRET = process.env.JWT_SECRET || 'test-jwt-secret-key-for-testing-only';
|
||||
const JWT_REFRESH_SECRET = process.env.JWT_REFRESH_SECRET || 'test-jwt-refresh-secret-key-for-testing-only';
|
||||
|
||||
export interface TokenPayload {
|
||||
userId: string;
|
||||
email: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
export interface AuthTokens {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
}
|
||||
|
||||
export interface AuthenticatedUser {
|
||||
user: User;
|
||||
tokens: AuthTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate access token for testing
|
||||
*/
|
||||
export function generateAccessToken(payload: TokenPayload): string {
|
||||
return jwt.sign(payload, JWT_SECRET, { expiresIn: '1h' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate refresh token for testing
|
||||
*/
|
||||
export function generateRefreshToken(payload: TokenPayload): string {
|
||||
return jwt.sign(payload, JWT_REFRESH_SECRET, { expiresIn: '7d' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate both tokens for a user
|
||||
*/
|
||||
export function generateTokens(payload: TokenPayload): AuthTokens {
|
||||
return {
|
||||
accessToken: generateAccessToken(payload),
|
||||
refreshToken: generateRefreshToken(payload),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get auth token for a specific user ID and role
|
||||
*/
|
||||
export function getAuthToken(userId: string, email: string, role: string = UserRole.PLAYER): string {
|
||||
return generateAccessToken({ userId, email, role });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get full auth headers for HTTP requests
|
||||
*/
|
||||
export function getAuthHeaders(userId: string, email: string, role: string = UserRole.PLAYER): { Authorization: string } {
|
||||
const token = getAuthToken(userId, email, role);
|
||||
return { Authorization: `Bearer ${token}` };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user with authentication tokens
|
||||
*/
|
||||
export async function createAuthenticatedUser(overrides: CreateUserInput = {}): Promise<AuthenticatedUser> {
|
||||
const user = await createUser(overrides);
|
||||
|
||||
const tokens = generateTokens({
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
});
|
||||
|
||||
return { user, tokens };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an admin user with authentication tokens
|
||||
*/
|
||||
export async function createAuthenticatedAdmin(overrides: CreateUserInput = {}): Promise<AuthenticatedUser> {
|
||||
const user = await createAdminUser(overrides);
|
||||
|
||||
const tokens = generateTokens({
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
});
|
||||
|
||||
return { user, tokens };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a superadmin user with authentication tokens
|
||||
*/
|
||||
export async function createAuthenticatedSuperAdmin(overrides: CreateUserInput = {}): Promise<AuthenticatedUser> {
|
||||
const user = await createUser({
|
||||
...overrides,
|
||||
role: UserRole.SUPERADMIN,
|
||||
});
|
||||
|
||||
const tokens = generateTokens({
|
||||
userId: user.id,
|
||||
email: user.email,
|
||||
role: user.role,
|
||||
});
|
||||
|
||||
return { user, tokens };
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a token (for testing purposes)
|
||||
*/
|
||||
export function verifyAccessToken(token: string): TokenPayload {
|
||||
return jwt.verify(token, JWT_SECRET) as TokenPayload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify a refresh token (for testing purposes)
|
||||
*/
|
||||
export function verifyRefreshToken(token: string): TokenPayload {
|
||||
return jwt.verify(token, JWT_REFRESH_SECRET) as TokenPayload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a token without verification (for debugging)
|
||||
*/
|
||||
export function decodeToken(token: string): any {
|
||||
return jwt.decode(token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create expired token (for testing token expiration)
|
||||
*/
|
||||
export function generateExpiredToken(payload: TokenPayload): string {
|
||||
return jwt.sign(payload, JWT_SECRET, { expiresIn: '-1s' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create invalid token (signed with wrong secret)
|
||||
*/
|
||||
export function generateInvalidToken(payload: TokenPayload): string {
|
||||
return jwt.sign(payload, 'wrong-secret-key', { expiresIn: '1h' });
|
||||
}
|
||||
Reference in New Issue
Block a user