From 240406aaceed01bfb1af6c6a8fcf87c5de9b50bc Mon Sep 17 00:00:00 2001 From: brobert Date: Sun, 9 Nov 2025 21:52:21 +0100 Subject: [PATCH] feat: centralizar helpers de tests (ymdUTC/addDays) y marcar Lote 2 Co-authored-by: aider (openrouter/openai/gpt-5) --- docs/2025-11-01-plan-refactor-tecnico.md | 9 ++++++--- tests/helpers/dates.ts | 13 +++++++++++++ tests/web/ics.aggregate.test.ts | 13 +------------ tests/web/ics.group.test.ts | 13 +------------ tests/web/ics.personal.test.ts | 13 +------------ 5 files changed, 22 insertions(+), 39 deletions(-) diff --git a/docs/2025-11-01-plan-refactor-tecnico.md b/docs/2025-11-01-plan-refactor-tecnico.md index b6ddbbf..209843b 100644 --- a/docs/2025-11-01-plan-refactor-tecnico.md +++ b/docs/2025-11-01-plan-refactor-tecnico.md @@ -78,14 +78,17 @@ Resultados esperados después del refactor: disminución drástica de duplicados - 2025-11-07: - Lote 0 completado: scripts `typecheck:core` y `typecheck:web` configurados y verificados. Se utiliza `tsconfig.core.json` para aislar el typecheck del core con reglas laxas, mientras que la web usa su propia configuración de SvelteKit. Los shims en `src/types/shims.d.ts` resuelven conflictos de tipos entre Bun y el DOM. - Verificación exitosa: `bun run typecheck:core` y `bun run typecheck:web` se ejecutan sin errores. +- 2025-11-09: + - Lote 2 completado: centralización de helpers de tests (sha256Hex, toIsoSql), unificación de SimulatedResponseQueue y helpers ICS (ymdUTC, addDays) en tests. + - Commits relevantes: 77e318e, 1ad36ee, y este commit. -## Estado actual (2025-11-07) +## Estado actual (2025-11-09) - Fase 1 — Diagnóstico asistido: Completada. - Fase 2 — Plan de refactor por lotes: En curso. - Lote 0 — Infra de typecheck: Completado. - Lote 1 — Utilidades de fecha/hora y validaciones: Completado. - - Lote 2 — Helpers de test y cripto: Pendiente. + - Lote 2 — Helpers de test y cripto: Completado. - Lote 3 — Tipos y endurecimiento suave: Pendiente. - Lote 4 — ICS central y rutas homogéneas: Pendiente. - Lote 5 — Svelte: dividir componentes grandes: Pendiente. @@ -125,7 +128,7 @@ Cada lote incluye objetivo, cambios, métricas y comprobaciones. Mantener tests - Comprobaciones: - Tests ICS y API siguen verdes. -### Lote 2 — Helpers de test y cripto +### Lote 2 — Helpers de test y cripto - Completado - Objetivo: - Eliminar duplicación en tests. diff --git a/tests/helpers/dates.ts b/tests/helpers/dates.ts index d398469..993491c 100644 --- a/tests/helpers/dates.ts +++ b/tests/helpers/dates.ts @@ -23,3 +23,16 @@ export function addDaysToYMD(ymd: string, days: number, tz: string = 'Europe/Mad base.setUTCDate(base.getUTCDate() + days); return ymdInTZ(base, tz); } + +export function ymdUTC(date: Date = new Date()): string { + const yyyy = String(date.getUTCFullYear()).padStart(4, '0'); + const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); + const dd = String(date.getUTCDate()).padStart(2, '0'); + return `${yyyy}-${mm}-${dd}`; +} + +export function addDays(date: Date, days: number): Date { + const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())); + d.setUTCDate(d.getUTCDate() + days); + return d; +} diff --git a/tests/web/ics.aggregate.test.ts b/tests/web/ics.aggregate.test.ts index 3016541..2ec0264 100644 --- a/tests/web/ics.aggregate.test.ts +++ b/tests/web/ics.aggregate.test.ts @@ -5,20 +5,9 @@ import { createTempDb } from './helpers/db'; import { sha256Hex } from '../helpers/crypto'; -import { toIsoSql } from '../helpers/dates'; +import { toIsoSql, ymdUTC, addDays } from '../helpers/dates'; -function ymdUTC(date = new Date()): string { - const yyyy = String(date.getUTCFullYear()).padStart(4, '0'); - const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); - const dd = String(date.getUTCDate()).padStart(2, '0'); - return `${yyyy}-${mm}-${dd}`; -} -function addDays(date: Date, days: number): Date { - const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())); - d.setUTCDate(d.getUTCDate() + days); - return d; -} function pad4(n: number): string { const s = String(Math.floor(n)); diff --git a/tests/web/ics.group.test.ts b/tests/web/ics.group.test.ts index 0e10c13..a670d31 100644 --- a/tests/web/ics.group.test.ts +++ b/tests/web/ics.group.test.ts @@ -5,20 +5,9 @@ import { createTempDb } from './helpers/db'; import { sha256Hex } from '../helpers/crypto'; -import { toIsoSql } from '../helpers/dates'; +import { toIsoSql, ymdUTC, addDays } from '../helpers/dates'; -function ymdUTC(date = new Date()): string { - const yyyy = String(date.getUTCFullYear()).padStart(4, '0'); - const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); - const dd = String(date.getUTCDate()).padStart(2, '0'); - return `${yyyy}-${mm}-${dd}`; -} -function addDays(date: Date, days: number): Date { - const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())); - d.setUTCDate(d.getUTCDate() + days); - return d; -} function pad4(n: number): string { const s = String(Math.floor(n)); diff --git a/tests/web/ics.personal.test.ts b/tests/web/ics.personal.test.ts index af693e9..53e6ab7 100644 --- a/tests/web/ics.personal.test.ts +++ b/tests/web/ics.personal.test.ts @@ -5,20 +5,9 @@ import { createTempDb } from './helpers/db'; import { sha256Hex } from '../helpers/crypto'; -import { toIsoSql } from '../helpers/dates'; +import { toIsoSql, ymdUTC, addDays } from '../helpers/dates'; -function ymdUTC(date = new Date()): string { - const yyyy = String(date.getUTCFullYear()).padStart(4, '0'); - const mm = String(date.getUTCMonth() + 1).padStart(2, '0'); - const dd = String(date.getUTCDate()).padStart(2, '0'); - return `${yyyy}-${mm}-${dd}`; -} -function addDays(date: Date, days: number): Date { - const d = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())); - d.setUTCDate(d.getUTCDate() + days); - return d; -} function pad4(n: number): string { const s = String(Math.floor(n));