|  |  | @ -21,16 +21,31 @@ describe('Database', () => { | 
			
		
	
		
		
			
				
					
					|  |  |  |   }); |  |  |  |   }); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   beforeEach(() => { |  |  |  |   beforeEach(() => { | 
			
		
	
		
		
			
				
					
					|  |  |  |     // Reset database schema between tests by dropping tables and re-initializing (respect FKs)
 |  |  |  |     // Reset del esquema entre tests.
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // Desactivar FKs para poder dropear en cualquier orden, incluyendo tablas nuevas con FKs (p.ej., calendar_tokens).
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('PRAGMA foreign_keys = OFF;'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // Tablas añadidas en migraciones posteriores (limpieza preventiva)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('DROP TABLE IF EXISTS calendar_tokens'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('DROP TABLE IF EXISTS web_sessions'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('DROP TABLE IF EXISTS web_tokens'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('DROP TABLE IF EXISTS allowed_groups'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('DROP TABLE IF EXISTS user_aliases'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('DROP TABLE IF EXISTS user_preferences'); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // Tablas base (dependientes primero)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS task_assignments'); // Drop dependent tables first
 |  |  |  |     testDb.exec('DROP TABLE IF EXISTS task_assignments'); // Drop dependent tables first
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS tasks'); |  |  |  |     testDb.exec('DROP TABLE IF EXISTS tasks'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS response_queue'); |  |  |  |     testDb.exec('DROP TABLE IF EXISTS response_queue'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS group_members'); |  |  |  |     testDb.exec('DROP TABLE IF EXISTS group_members'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS groups'); |  |  |  |     testDb.exec('DROP TABLE IF EXISTS groups'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS users'); |  |  |  |     testDb.exec('DROP TABLE IF EXISTS users'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     // También reiniciar histórico de migraciones para forzar recreación de tablas
 |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // Reiniciar histórico de migraciones para forzar recreación íntegra
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     testDb.exec('DROP TABLE IF EXISTS schema_migrations'); |  |  |  |     testDb.exec('DROP TABLE IF EXISTS schema_migrations'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     // Initialize schema on the test database instance
 |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // Re-activar FKs y re-inicializar el esquema
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     testDb.exec('PRAGMA foreign_keys = ON;'); | 
			
		
	
		
		
			
				
					
					|  |  |  |     initializeDatabase(testDb); |  |  |  |     initializeDatabase(testDb); | 
			
		
	
		
		
			
				
					
					|  |  |  |   }); |  |  |  |   }); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | 
 |