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.
		
		
		
		
		
			
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			TypeScript
		
	
| import { describe, it, expect, beforeAll, beforeEach } from 'bun:test';
 | |
| import { Database } from 'bun:sqlite';
 | |
| import { initializeDatabase } from '../../../src/db';
 | |
| import { TaskService } from '../../../src/tasks/service';
 | |
| import { CommandService } from '../../../src/services/command';
 | |
| 
 | |
| describe('CommandService - ayuda por DM', () => {
 | |
|   let memdb: Database;
 | |
| 
 | |
|   beforeAll(() => {
 | |
|     memdb = new Database(':memory:');
 | |
|     initializeDatabase(memdb);
 | |
|     TaskService.dbInstance = memdb;
 | |
|     CommandService.dbInstance = memdb;
 | |
|   });
 | |
| 
 | |
|   beforeEach(() => {
 | |
|     process.env.NODE_ENV = 'test';
 | |
|     process.env.TZ = 'Europe/Madrid';
 | |
|   });
 | |
| 
 | |
|   it('responde con ayuda cuando el usuario escribe "/t"', async () => {
 | |
|     const sender = '600111222';
 | |
|     const responses = await CommandService.handle({
 | |
|       sender,
 | |
|       groupId: '12345@g.us',
 | |
|       message: '/t',
 | |
|       mentions: [],
 | |
|     });
 | |
| 
 | |
|     expect(Array.isArray(responses)).toBe(true);
 | |
|     expect(responses.length).toBe(1);
 | |
|     const r = responses[0];
 | |
|     expect(r.recipient).toBe(sender);
 | |
|     expect(r.message).toContain('Guía rápida:');
 | |
|     expect(r.message).toContain('/t ver mis');
 | |
|   });
 | |
| 
 | |
|   it('responde con ayuda cuando el usuario escribe "/t ayuda"', async () => {
 | |
|     const sender = '600111222';
 | |
|     const responses = await CommandService.handle({
 | |
|       sender,
 | |
|       groupId: `${sender}@s.whatsapp.net`, // DM
 | |
|       message: '/t ayuda',
 | |
|       mentions: [],
 | |
|     });
 | |
| 
 | |
|     expect(responses.length).toBe(1);
 | |
|     const r = responses[0];
 | |
|     expect(r.recipient).toBe(sender);
 | |
|     expect(r.message).toContain('Guía rápida:');
 | |
|     expect(r.message).toContain('/t n');
 | |
|   });
 | |
| });
 |