test: ampliar pruebas de parseo de fechas a YYYY-MM-DD y YY-MM-DD

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
main
borja 3 weeks ago
parent b39ca2041a
commit 414374367d

@ -22,7 +22,7 @@ function addDaysToYMD(ymd: string, days: number, tz: string = 'Europe/Madrid'):
return ymdInTZ(base, tz);
}
describe('CommandService - parser de fechas (hoy/mañana)', () => {
describe('CommandService - parser de fechas (hoy/mañana y formatos YYYY/YY-MM-DD)', () => {
let memdb: Database;
beforeAll(() => {
@ -88,4 +88,65 @@ describe('CommandService - parser de fechas (hoy/mañana)', () => {
expect(row).toBeTruthy();
expect(String(row.due_date)).toBe(tomorrowYMD);
});
it('acepta formato YY-MM-DD y normaliza a YYYY-MM-DD (pivot en 2000s)', async () => {
const sender = '600111222';
const ctx = {
sender,
groupId: `${sender}@s.whatsapp.net`,
message: '/t n con corto 25-12-19',
mentions: [] as string[],
};
await CommandService.handle(ctx);
const row = memdb.prepare(`SELECT id, due_date FROM tasks ORDER BY id DESC LIMIT 1`).get() as any;
expect(row).toBeTruthy();
expect(String(row.due_date)).toBe('2025-12-19');
});
it('acepta formato YY-MM-DD con ceros y futuro lejano seguro (30-01-05 → 2030-01-05)', async () => {
const sender = '600111222';
const ctx = {
sender,
groupId: `${sender}@s.whatsapp.net`,
message: '/t n con corto 30-01-05',
mentions: [] as string[],
};
await CommandService.handle(ctx);
const row = memdb.prepare(`SELECT id, due_date FROM tasks ORDER BY id DESC LIMIT 1`).get() as any;
expect(row).toBeTruthy();
expect(String(row.due_date)).toBe('2030-01-05');
});
it('rechaza formatos no permitidos y no establece due_date', async () => {
const sender = '600111222';
const invalids = [
'/t n invalida 25/12/30', // separador no permitido
'/t n invalida 2025/12/01', // separador no permitido
'/t n invalida 2025-2-01', // mes 1 dígito
'/t n invalida 2025-02-3', // día 1 dígito
'/t n invalida 2025-13-01', // mes inválido
'/t n invalida 2025-00-10', // mes inválido
'/t n invalida 2025-02-30', // día inválido calendario
'/t n invalida 25-12', // dos partes no permitido
'/t n invalida 12-25', // dos partes no permitido
'/t n invalida 2025-1-1', // sin padding
];
for (const msg of invalids) {
memdb.exec('DELETE FROM task_assignments; DELETE FROM tasks;');
await CommandService.handle({
sender,
groupId: `${sender}@s.whatsapp.net`,
message: msg,
mentions: [] as string[],
});
const row = memdb.prepare(`SELECT id, due_date FROM tasks ORDER BY id DESC LIMIT 1`).get() as any;
expect(row).toBeTruthy();
expect(row.due_date).toBeNull();
}
});
});

Loading…
Cancel
Save