You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			TypeScript
		
	
| import { db, initializeDatabase } from '../../src/db';
 | |
| import { describe, test, expect, beforeEach } from 'bun:test';
 | |
| 
 | |
| describe('Database', () => {
 | |
|   beforeEach(() => {
 | |
|     // Reset database between tests
 | |
|     db.exec('DROP TABLE IF EXISTS tasks');
 | |
|     db.exec('DROP TABLE IF EXISTS task_assignments');
 | |
|     db.exec('DROP TABLE IF EXISTS users');
 | |
|     db.exec('DROP TABLE IF EXISTS groups');
 | |
|     initializeDatabase();
 | |
|   });
 | |
| 
 | |
|   test('should create all required tables with correct schema', () => {
 | |
|     // Verify tables exist
 | |
|     const tables = db
 | |
|       .query("SELECT name FROM sqlite_master WHERE type='table'")
 | |
|       .all()
 | |
|       .map((t: any) => t.name);
 | |
|     
 | |
|     const expectedTables = ['groups', 'task_assignments', 'tasks', 'users'];
 | |
|     // Filter out system tables like sqlite_sequence
 | |
|     const userTables = tables.filter(t => !t.startsWith('sqlite_'));
 | |
|     expect(userTables.sort()).toEqual(expectedTables.sort());
 | |
| 
 | |
|     // Verify tasks table schema
 | |
|     const tasksColumns = db
 | |
|       .query("PRAGMA table_info(tasks)")
 | |
|       .all()
 | |
|       .map((c: any) => c.name);
 | |
|     expect(tasksColumns).toContain('description');
 | |
|     expect(tasksColumns).toContain('due_date');
 | |
| 
 | |
|     // Verify foreign key constraint
 | |
|     const fkInfo = db
 | |
|       .query("PRAGMA foreign_key_list(task_assignments)")
 | |
|       .all();
 | |
|     expect(fkInfo.length).toBe(1);
 | |
|     expect(fkInfo[0].from).toBe('task_id');
 | |
|     expect(fkInfo[0].to).toBe('id');
 | |
|     expect(fkInfo[0].table).toBe('tasks');
 | |
|   });
 | |
| });
 |