Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tests/arena-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
export async function navigateToSchedule(
page: Page,
allowedDays: DayOfWeek[],
weekOffset = 0
): Promise<void> {
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`;
Expand Down
16 changes: 15 additions & 1 deletion tests/gym-reservations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down