create(); $user = User::factory()->create(); $reservation = Reservation::create([ 'reference' => 'REQ-TEST-001', 'requester_id' => $user->id, 'purpose' => 'Sessão de formação audiovisual', 'usage_location' => 'Auditório', 'starts_at' => '2026-09-10 09:00:00', 'ends_at' => '2026-09-10 11:00:00', 'status' => ReservationStatus::Approved, ]); $reservation->items()->create([ 'snipe_asset_id' => $asset->id, 'starts_at' => '2026-09-10 09:00:00', 'ends_at' => '2026-09-10 11:00:00', 'status' => ReservationItemStatus::Reserved, ]); $service = app(AvailabilityService::class); expect($service->isAvailable($asset, new DateTimeImmutable('2026-09-10 10:30:00'), new DateTimeImmutable('2026-09-10 12:00:00')))->toBeFalse() ->and($service->isAvailable($asset, new DateTimeImmutable('2026-09-10 11:00:00'), new DateTimeImmutable('2026-09-10 13:00:00')))->toBeTrue(); }); it('recusa ativos atribuídos ou não requisitáveis', function () { $service = app(AvailabilityService::class); $period = [new DateTimeImmutable('+2 days'), new DateTimeImmutable('+3 days')]; $assigned = SnipeAsset::factory()->create(['assigned_id' => 42]); $notRequestable = SnipeAsset::factory()->create(['requestable' => false]); expect($service->isAvailable($assigned, ...$period))->toBeFalse() ->and($service->isAvailable($notRequestable, ...$period))->toBeFalse(); }); it('produz uma consulta de equipamentos livres para um período', function () { $free = SnipeAsset::factory()->create(); $busy = SnipeAsset::factory()->create(); $touching = SnipeAsset::factory()->create(); $blocked = SnipeAsset::factory()->create(); $user = User::factory()->create(); foreach ([$busy, $touching] as $index => $asset) { $reservation = Reservation::create([ 'reference' => "REQ-QUERY-00{$index}", 'requester_id' => $user->id, 'purpose' => 'Reserva existente para testar disponibilidade.', 'usage_location' => 'Estúdio', 'starts_at' => '2026-09-10 09:00:00', 'ends_at' => '2026-09-10 11:00:00', 'status' => ReservationStatus::Approved, ]); $reservation->items()->create([ 'snipe_asset_id' => $asset->id, 'starts_at' => '2026-09-10 09:00:00', 'ends_at' => '2026-09-10 11:00:00', 'status' => ReservationItemStatus::Reserved, ]); } $blocked->blocks()->create([ 'starts_at' => '2026-09-10 10:45:00', 'ends_at' => '2026-09-10 11:30:00', 'reason' => 'Manutenção preventiva programada.', 'created_by' => $user->id, ]); $ids = app(AvailabilityService::class) ->availableAssets( new DateTimeImmutable('2026-09-10 10:30:00'), new DateTimeImmutable('2026-09-10 12:00:00'), ) ->pluck('id'); expect($ids)->toContain($free->id) ->not->toContain($busy->id, $touching->id, $blocked->id); $boundaryIds = app(AvailabilityService::class) ->availableAssets( new DateTimeImmutable('2026-09-10 11:00:00'), new DateTimeImmutable('2026-09-10 12:00:00'), ) ->pluck('id'); expect($boundaryIds)->toContain($free->id, $busy->id, $touching->id) ->not->toContain($blocked->id); }); it('filtra o catálogo pelo período solicitado', function () { CarbonImmutable::setTestNow('2026-09-01 08:00:00'); $user = User::factory()->create(); $free = SnipeAsset::factory()->create(); $busy = SnipeAsset::factory()->create(); $reservation = Reservation::create([ 'reference' => 'REQ-CATALOG-001', 'requester_id' => $user->id, 'purpose' => 'Reserva existente para testar o catálogo público.', 'usage_location' => 'Estúdio', 'starts_at' => '2026-09-10 09:00:00', 'ends_at' => '2026-09-10 11:00:00', 'status' => ReservationStatus::Approved, ]); $reservation->items()->create([ 'snipe_asset_id' => $busy->id, 'starts_at' => '2026-09-10 09:00:00', 'ends_at' => '2026-09-10 11:00:00', 'status' => ReservationItemStatus::Reserved, ]); $query = http_build_query([ 'starts_at' => '2026-09-10T10:00', 'ends_at' => '2026-09-10T12:00', ]); $this->actingAs($user) ->get("/equipamentos?{$query}") ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('assets/index') ->where('periodSelected', true) ->has('assets.data', 1) ->where('assets.data.0.id', $free->id)); $this->get("/requisicoes/nova?asset={$busy->id}&{$query}") ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('reservations/create') ->where('periodSelected', true) ->where('selectedAssetId', 0) ->has('assets', 1) ->where('assets.0.id', $free->id)); });