From d05f7c1ddee6b647f5ff0b555c7925d0f53b8b43 Mon Sep 17 00:00:00 2001 From: Toni <33262178+toniDefez@users.noreply.github.com> Date: Sun, 8 Mar 2026 18:33:56 +0100 Subject: [PATCH] Fix fallback search for next week's classes --- tests/arena-helpers.ts | 14 ++++++++++---- tests/gym-reservations.spec.ts | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/arena-helpers.ts b/tests/arena-helpers.ts index 9d754e0..51747a9 100644 --- a/tests/arena-helpers.ts +++ b/tests/arena-helpers.ts @@ -62,19 +62,25 @@ function pad(n: number): string { return n.toString().padStart(2, '0'); } -function nextAllowedDate(allowedDays: DayOfWeek[]): Date { +function nextAllowedDate(allowedDays: DayOfWeek[], weekOffset = 0): Date { const today = new Date(); - for (let offset = 0; offset < 14; offset++) { + const startOffset = weekOffset * 7; + + for (let offset = startOffset; offset < startOffset + 14; offset++) { const candidate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + offset); if (allowedDays.includes(candidate.getDay())) return candidate; } return today; } -export async function navigateToSchedule(page: Page, allowedDays: DayOfWeek[]): Promise { +export async function navigateToSchedule( + page: Page, + allowedDays: DayOfWeek[], + weekOffset = 0 +): Promise { console.log("\nšŸ“… Navegando a horario semanal..."); - const scheduleDate = nextAllowedDate(allowedDays); + const scheduleDate = nextAllowedDate(allowedDays, weekOffset); const fechaIso = `${scheduleDate.getFullYear()}-${pad(scheduleDate.getMonth() + 1)}-${pad(scheduleDate.getDate())}T00:00:00`; const url = `https://arenaalicante.provis.es/ActividadesColectivas/ActividadesColectivasHorarioSemanal?fecha=${fechaIso}&integration=False&publico=False`; diff --git a/tests/gym-reservations.spec.ts b/tests/gym-reservations.spec.ts index 37f9410..b8f949e 100644 --- a/tests/gym-reservations.spec.ts +++ b/tests/gym-reservations.spec.ts @@ -112,7 +112,7 @@ test('Reservar actividad configurada', async ({ page }) => { await login(page); await navigateToSchedule(page, cfg.allowedDays); - const classData = await findClass(page, { + let classData = await findClass(page, { activityId: cfg.activityId, allowedDays: cfg.allowedDays, minHour: cfg.minHour, @@ -121,6 +121,20 @@ test('Reservar actividad configurada', async ({ page }) => { requireOpenWindow: cfg.requireOpenWindow ?? true, }); + if (!classData) { + console.log('šŸ” No hubo coincidencias en la semana actual, probando la siguiente semana...'); + + await navigateToSchedule(page, cfg.allowedDays, 1); + classData = await findClass(page, { + activityId: cfg.activityId, + allowedDays: cfg.allowedDays, + minHour: cfg.minHour, + minMinutes: cfg.minMinutes ?? 0, + label: activityToRun.toUpperCase(), + requireOpenWindow: cfg.requireOpenWindow ?? true, + }); + } + if (classData) { const success = await reserveClass(page, classData.Id, activityToRun.toUpperCase()); expect(success).toBe(true);