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';
import { setDb } from '../../../src/db/locator';

describe('CommandService - formato dd/MM en ACK de creación', () => {
  let memdb: Database;

  beforeAll(() => {
    memdb = new Database(':memory:');
    initializeDatabase(memdb);
    setDb(memdb);
  });

  beforeEach(() => {
    process.env.NODE_ENV = 'test';
    process.env.TZ = 'Europe/Madrid';
    memdb.exec('DELETE FROM task_assignments; DELETE FROM tasks;');
  });

  it('muestra la fecha como dd/MM en el ACK al creador', async () => {
    const sender = '600111222';
    const responses = await CommandService.handle({
      sender,
      groupId: `${sender}@s.whatsapp.net`, // DM
      message: 't n tarea con fecha 2099-01-05',
      mentions: [],
    });

    const ack = responses.find(r => r.recipient === sender);
    expect(ack).toBeTruthy();
    expect(ack!.message).toContain('📅 05/01');
  });
});
