fix(forms): hide inactive food event dates

This commit is contained in:
ncoronel 2026-09-14 15:00:23 -03:00
parent 61314d5166
commit 91022c5897
2 changed files with 50 additions and 1 deletions

View File

@ -27,7 +27,11 @@ class FoodFormService
->keyBy('codigo');
return [
'event_dates' => $tenant->eventDates()->with('validityTime')->get(),
'event_dates' => $tenant->eventDates()
->whereNull('rescheduled_to_event_date_id')
->whereNull('suspended_at')
->with('validityTime')
->get(),
'schedules' => $attributes->get('horario')?->options ?? new Collection,
'services' => $attributes->get('servicio')?->options ?? new Collection,
];

View File

@ -67,6 +67,51 @@ class AdminAppFoodFormControllerTest extends TestCase
->assertJsonPath('data.services.0.value', 'Comedor');
}
public function test_it_excludes_rescheduled_and_suspended_event_dates(): void
{
$tenant = Tenant::query()->create([
'codigo' => 'fiesta',
'nombre' => 'Fiesta',
'dominio' => 'fiesta.test',
'website_type_code' => 'onticket',
]);
$available = $tenant->eventDates()->create([
'date' => '2026-10-09',
'time_start' => '00:00',
'time_end' => '23:59',
]);
$rescheduled = $tenant->eventDates()->create([
'date' => '2026-10-10',
'time_start' => '00:00',
'time_end' => '23:59',
]);
$replacement = $tenant->eventDates()->create([
'date' => '2026-10-11',
'time_start' => '00:00',
'time_end' => '23:59',
]);
$rescheduled->update(['rescheduled_to_event_date_id' => $replacement->id]);
$tenant->eventDates()->create([
'date' => '2026-10-12',
'time_start' => '00:00',
'time_end' => '23:59',
'suspended_at' => now(),
]);
Sanctum::actingAs(User::factory()->create([
'rol_codigo' => RoleCode::AdminApp->value,
'tenant_codigo' => $tenant->codigo,
]));
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/food')
->assertOk()
->assertJsonCount(2, 'data.event_dates')
->assertJsonFragment(['id' => $available->id, 'date' => '2026-10-09'])
->assertJsonFragment(['id' => $replacement->id, 'date' => '2026-10-11'])
->assertJsonMissing(['date' => '2026-10-10'])
->assertJsonMissing(['date' => '2026-10-12']);
}
/** @param array<int, array{value: string, label: string, sort_order: int}> $options */
private function createAttribute(Tenant $tenant, string $code, array $options): void
{