A free open source IT asset/license management system
Moar tests
snipe6090955b4528
diff --git a/tests/Feature/Accessories/Ui/AccessoryCheckoutRequestContextTest.php b/tests/Feature/Accessories/Ui/AccessoryCheckoutRequestContextTest.phpnew file mode 100644index 0000000000..a155afc514--- /dev/null+++ b/tests/Feature/Accessories/Ui/AccessoryCheckoutRequestContextTest.php@@ -0,0 +1,123 @@+<?php++namespace Tests\Feature\Accessories\Ui;++use App\Models\Accessory;+use App\Models\CheckoutRequest;+use App\Models\Consumable;+use App\Models\User;+use Tests\TestCase;++/**+ * Accessory-checkout screen reached from /requests: the right column+ * gains a "Requested" box + optional "Also Requested By" box so the+ * admin sees who asked and who else is waiting before deciding how+ * much to hand out. Wiring lives in AccessoryCheckoutController::+ * create (calls CheckoutRequest::contextForCheckout for URL-twiddle+ * guards) and is rendered by the shared <x-checkout-request-context>+ * component. The full guard matrix is exercised through the+ * Components equivalent (ComponentCheckoutRequestingUserTest); these+ * tests just prove the wiring reaches the accessory checkout view.+ */+class AccessoryCheckoutRequestContextTest extends TestCase+{+ public function test_view_receives_checkout_request_when_request_id_is_valid(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $accessory = Accessory::factory()->create();+ $checkoutRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);++ $this->actingAs($admin)+ ->get(route('accessories.checkout.show', [+ 'accessory' => $accessory->id,+ 'request_id' => $checkoutRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', fn ($r) => $r?->id === $checkoutRequest->id);+ }++ public function test_view_receives_null_when_request_id_absent(): void+ {+ $admin = User::factory()->superuser()->create();+ $accessory = Accessory::factory()->create();++ $this->actingAs($admin)+ ->get(route('accessories.checkout.show', ['accessory' => $accessory->id]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null)+ ->assertViewHas('otherPendingRequests', fn ($p) => collect($p)->isEmpty());+ }++ public function test_forged_request_id_for_a_different_requestable_type_is_ignored(): void+ {+ // Cross-type guard: a Consumable's request_id passed to the+ // accessory screen must not hydrate an off-scope requester+ // into the accessory checkout context.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $accessory = Accessory::factory()->create();+ $consumable = Consumable::factory()->create();++ $consumableRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $consumable->id,+ 'requestable_type' => Consumable::class,+ ]);++ $this->actingAs($admin)+ ->get(route('accessories.checkout.show', [+ 'accessory' => $accessory->id,+ 'request_id' => $consumableRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null);+ }++ public function test_view_receives_other_pending_requests_ordered_oldest_first(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $earlier = User::factory()->create();+ $later = User::factory()->create();+ $accessory = Accessory::factory()->create();++ // Waiting-list ordering: created_at then id. Persist rows in+ // reverse to confirm the helper sorts, doesn't rely on insert+ // order.+ $currentRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);+ $laterOther = CheckoutRequest::factory()->create([+ 'user_id' => $later->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ 'created_at' => now()->subMinutes(2),+ ]);+ $earlierOther = CheckoutRequest::factory()->create([+ 'user_id' => $earlier->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ 'created_at' => now()->subHours(2),+ ]);++ $this->actingAs($admin)+ ->get(route('accessories.checkout.show', [+ 'accessory' => $accessory->id,+ 'request_id' => $currentRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('otherPendingRequests', function ($pending) use ($earlierOther, $laterOther, $currentRequest) {+ $ids = collect($pending)->pluck('id')->all();++ return $ids === [$earlierOther->id, $laterOther->id]+ && ! in_array($currentRequest->id, $ids, true);+ });+ }+}diff --git a/tests/Feature/AssetModels/Api/RequestableAssetModelsApiTest.php b/tests/Feature/AssetModels/Api/RequestableAssetModelsApiTest.phpnew file mode 100644index 0000000000..29ff230764--- /dev/null+++ b/tests/Feature/AssetModels/Api/RequestableAssetModelsApiTest.php@@ -0,0 +1,152 @@+<?php++namespace Tests\Feature\AssetModels\Api;++use App\Models\Accessory;+use App\Models\AssetModel;+use App\Models\CheckoutRequest;+use App\Models\User;+use Tests\TestCase;++/**+ * api.assetmodels.requestable — hydrates the models tab on+ * /account/requestable. Row shape has to carry the per-user+ * assigned_to_self flag and available_actions.request/cancel so the+ * assetmodelRequestableActionsFormatter JS helper can render the+ * request-vs-cancel button-swap without a second query.+ *+ * Mirrors the coverage other requestable endpoints have (accessories,+ * consumables, components, licenses) and closes the N+1 that the+ * server-rendered @foreach on the old page fired one query per row.+ */+class RequestableAssetModelsApiTest extends TestCase+{+ public function test_returns_only_requestable_models(): void+ {+ $requestable = AssetModel::factory()->create(['requestable' => 1]);+ $notRequestable = AssetModel::factory()->create(['requestable' => 0]);++ $rows = $this->actingAsForApi(User::factory()->create())+ ->getJson(route('api.assetmodels.requestable'))+ ->assertOk()+ ->json('rows');++ $ids = collect($rows)->pluck('id')->all();+ $this->assertContains($requestable->id, $ids);+ $this->assertNotContains($notRequestable->id, $ids);+ }++ public function test_row_carries_assigned_to_self_true_when_user_has_open_request(): void+ {+ $user = User::factory()->create();+ $model = AssetModel::factory()->create(['requestable' => 1]);+ CheckoutRequest::factory()->create([+ 'user_id' => $user->id,+ 'requestable_id' => $model->id,+ 'requestable_type' => AssetModel::class,+ ]);++ $row = $this->actingAsForApi($user)+ ->getJson(route('api.assetmodels.requestable'))+ ->assertOk()+ ->json('rows.0');++ $this->assertTrue($row['assigned_to_self']);+ // Button-swap contract: caller with an open request sees+ // cancel, not request.+ $this->assertFalse($row['available_actions']['request']);+ $this->assertTrue($row['available_actions']['cancel']);+ }++ public function test_row_carries_assigned_to_self_false_for_other_users_requests(): void+ {+ $me = User::factory()->create();+ $someoneElse = User::factory()->create();+ $model = AssetModel::factory()->create(['requestable' => 1]);+ // Not my request.+ CheckoutRequest::factory()->create([+ 'user_id' => $someoneElse->id,+ 'requestable_id' => $model->id,+ 'requestable_type' => AssetModel::class,+ ]);++ $row = $this->actingAsForApi($me)+ ->getJson(route('api.assetmodels.requestable'))+ ->assertOk()+ ->json('rows.0');++ $this->assertFalse($row['assigned_to_self']);+ $this->assertTrue($row['available_actions']['request']);+ $this->assertFalse($row['available_actions']['cancel']);+ }++ public function test_canceled_requests_do_not_flip_assigned_to_self(): void+ {+ // Cancel semantics: a canceled row shouldn't leave the user+ // stuck seeing a cancel button they can't act on.+ $user = User::factory()->create();+ $model = AssetModel::factory()->create(['requestable' => 1]);+ CheckoutRequest::factory()->create([+ 'user_id' => $user->id,+ 'requestable_id' => $model->id,+ 'requestable_type' => AssetModel::class,+ 'canceled_at' => now()->subMinute(),+ ]);++ $row = $this->actingAsForApi($user)+ ->getJson(route('api.assetmodels.requestable'))+ ->assertOk()+ ->json('rows.0');++ $this->assertFalse($row['assigned_to_self']);+ $this->assertTrue($row['available_actions']['request']);+ }++ public function test_cross_type_open_requests_do_not_flip_assigned_to_self(): void+ {+ // Guard: an open request against an Accessory with the same+ // requestable_id must not bleed into the AssetModel row's+ // assigned_to_self flag. The transformer's contains-check+ // matches purely on user_id + canceled_at because the+ // eager-loaded requests collection is already scoped to this+ // model - but codify the isolation with a test so a future+ // refactor doesn't regress it.+ $user = User::factory()->create();+ $model = AssetModel::factory()->create(['requestable' => 1]);+ $accessory = Accessory::factory()->create();+ CheckoutRequest::factory()->create([+ 'user_id' => $user->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);++ $row = $this->actingAsForApi($user)+ ->getJson(route('api.assetmodels.requestable'))+ ->assertOk()+ ->json('rows.0');++ $this->assertFalse($row['assigned_to_self']);+ }++ public function test_available_actions_view_reflects_caller_permission(): void+ {+ // The formatter uses available_actions.view to decide+ // whether to render the name as an <a> link or plain text.+ // A user with the view-assetmodel permission gets view=true;+ // a user without it gets view=false.+ AssetModel::factory()->create(['requestable' => 1]);++ $withView = User::factory()->viewAssetModels()->create();+ $withoutView = User::factory()->create();++ $rowWith = $this->actingAsForApi($withView)+ ->getJson(route('api.assetmodels.requestable'))+ ->json('rows.0');+ $rowWithout = $this->actingAsForApi($withoutView)+ ->getJson(route('api.assetmodels.requestable'))+ ->json('rows.0');++ $this->assertTrue($rowWith['available_actions']['view']);+ $this->assertFalse($rowWithout['available_actions']['view']);+ }+}diff --git a/tests/Feature/Checkouts/Ui/AssetCheckoutRequestContextTest.php b/tests/Feature/Checkouts/Ui/AssetCheckoutRequestContextTest.phpnew file mode 100644index 0000000000..3ca202e919--- /dev/null+++ b/tests/Feature/Checkouts/Ui/AssetCheckoutRequestContextTest.php@@ -0,0 +1,118 @@+<?php++namespace Tests\Feature\Checkouts\Ui;++use App\Models\Accessory;+use App\Models\Asset;+use App\Models\CheckoutRequest;+use App\Models\User;+use Tests\TestCase;++/**+ * Asset-checkout screen reached from /requests: the right column+ * gains a "Requested" box + optional "Also Requested By" box so the+ * admin sees who asked and who else is waiting. Wiring lives in+ * AssetCheckoutController::create (calls CheckoutRequest::+ * contextForCheckout for URL-twiddle guards) and is rendered by the+ * shared <x-checkout-request-context> component. Full guard matrix+ * is covered in ComponentCheckoutRequestingUserTest; these tests+ * just prove the wiring reaches this view.+ */+class AssetCheckoutRequestContextTest extends TestCase+{+ public function test_view_receives_checkout_request_when_request_id_is_valid(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $asset = Asset::factory()->create();+ $checkoutRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $asset->id,+ 'requestable_type' => Asset::class,+ ]);++ $this->actingAs($admin)+ ->get(route('hardware.checkout.create', [+ 'asset' => $asset->id,+ 'request_id' => $checkoutRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', fn ($r) => $r?->id === $checkoutRequest->id);+ }++ public function test_view_receives_null_when_request_id_absent(): void+ {+ $admin = User::factory()->superuser()->create();+ $asset = Asset::factory()->create();++ $this->actingAs($admin)+ ->get(route('hardware.checkout.create', ['asset' => $asset->id]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null)+ ->assertViewHas('otherPendingRequests', fn ($p) => collect($p)->isEmpty());+ }++ public function test_forged_request_id_for_a_different_requestable_type_is_ignored(): void+ {+ // Cross-type guard: an Accessory's request_id passed to the+ // asset screen must not hydrate an off-scope requester.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $asset = Asset::factory()->create();+ $accessory = Accessory::factory()->create();++ $accessoryRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);++ $this->actingAs($admin)+ ->get(route('hardware.checkout.create', [+ 'asset' => $asset->id,+ 'request_id' => $accessoryRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null);+ }++ public function test_view_receives_other_pending_requests_excluding_current_and_canceled(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $other = User::factory()->create();+ $asset = Asset::factory()->create();++ $currentRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $asset->id,+ 'requestable_type' => Asset::class,+ ]);+ $otherOpen = CheckoutRequest::factory()->create([+ 'user_id' => $other->id,+ 'requestable_id' => $asset->id,+ 'requestable_type' => Asset::class,+ ]);+ // Canceled row must not appear.+ CheckoutRequest::factory()->create([+ 'user_id' => User::factory()->create()->id,+ 'requestable_id' => $asset->id,+ 'requestable_type' => Asset::class,+ 'canceled_at' => now(),+ ]);++ $this->actingAs($admin)+ ->get(route('hardware.checkout.create', [+ 'asset' => $asset->id,+ 'request_id' => $currentRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('otherPendingRequests', function ($pending) use ($otherOpen, $currentRequest) {+ $ids = collect($pending)->pluck('id')->all();++ return count($ids) === 1+ && in_array($otherOpen->id, $ids, true)+ && ! in_array($currentRequest->id, $ids, true);+ });+ }+}diff --git a/tests/Feature/Components/Ui/ComponentCheckoutRequestingUserTest.php b/tests/Feature/Components/Ui/ComponentCheckoutRequestingUserTest.phpnew file mode 100644index 0000000000..d3823dd65a--- /dev/null+++ b/tests/Feature/Components/Ui/ComponentCheckoutRequestingUserTest.php@@ -0,0 +1,252 @@+<?php++namespace Tests\Feature\Components\Ui;++use App\Models\Accessory;+use App\Models\Asset;+use App\Models\CheckoutRequest;+use App\Models\Component;+use App\Models\User;+use Tests\TestCase;++/**+ * Component-checkout screen reached from /requests: the target-asset+ * picker pre-scopes to the requesting user's assigned assets so the+ * admin can install the part without hunting, and an info callout+ * above the form surfaces the request context (who asked for it and+ * who else is still waiting).+ *+ * Wiring: `checkoutRequestActionsFormatter` appends ?request_id={id}+ * for Component rows; ComponentCheckoutController::create loads the+ * CheckoutRequest, validates it targets THIS component (guarded+ * against URL-twiddling), and exposes requestingUserId ++ * checkoutRequest + otherPendingRequests to the view; the asset+ * select2 forwards requestingUserId as assignedTo which+ * AssetsController::selectlist honors unconditionally (empty picker+ * when the requester has no assigned assets, so the admin sees the+ * scoping instead of a silent fallback to the full fleet).+ */+class ComponentCheckoutRequestingUserTest extends TestCase+{+ public function test_view_receives_requesting_user_id_from_valid_request_id(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $component = Component::factory()->create(['qty' => 5]);+ Asset::factory()->assignedToUser($requester)->create();+ $checkoutRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $component->id,+ 'requestable_type' => Component::class,+ ]);++ $this->actingAs($admin)+ ->get(route('components.checkout.show', [+ 'componentID' => $component->id,+ 'request_id' => $checkoutRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('requestingUserId', $requester->id);+ }++ public function test_view_falls_back_to_null_when_request_id_absent(): void+ {+ $admin = User::factory()->superuser()->create();+ $component = Component::factory()->create(['qty' => 5]);++ $this->actingAs($admin)+ ->get(route('components.checkout.show', ['componentID' => $component->id]))+ ->assertOk()+ ->assertViewHas('requestingUserId', null);+ }++ public function test_forged_request_id_targeting_different_component_is_ignored(): void+ {+ // Admin twiddles the URL to reference a CheckoutRequest that+ // targets a DIFFERENT component. Guard must ignore it so an+ // admin can't see which users have open requests on+ // components they aren't currently working with.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();++ $component = Component::factory()->create(['qty' => 5]);+ $otherComponent = Component::factory()->create(['qty' => 5]);++ $requestForOther = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $otherComponent->id,+ 'requestable_type' => Component::class,+ ]);++ $this->actingAs($admin)+ ->get(route('components.checkout.show', [+ 'componentID' => $component->id,+ 'request_id' => $requestForOther->id,+ ]))+ ->assertOk()+ ->assertViewHas('requestingUserId', null);+ }++ public function test_forged_request_id_of_different_requestable_type_is_ignored(): void+ {+ // Same guard, non-Component requestable_type. An accessory+ // request-id passed to a component checkout must not hydrate+ // the picker from an unrelated request's user.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $component = Component::factory()->create(['qty' => 5]);+ $accessory = Accessory::factory()->create();++ $accessoryRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);++ $this->actingAs($admin)+ ->get(route('components.checkout.show', [+ 'componentID' => $component->id,+ 'request_id' => $accessoryRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('requestingUserId', null);+ }++ public function test_canceled_request_is_ignored(): void+ {+ // Stale canceled rows shouldn't influence live checkout UX.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $component = Component::factory()->create(['qty' => 5]);+ $canceledRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $component->id,+ 'requestable_type' => Component::class,+ 'canceled_at' => now()->subMinute(),+ ]);++ $this->actingAs($admin)+ ->get(route('components.checkout.show', [+ 'componentID' => $component->id,+ 'request_id' => $canceledRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('requestingUserId', null);+ }++ public function test_nonexistent_request_id_is_ignored(): void+ {+ $admin = User::factory()->superuser()->create();+ $component = Component::factory()->create(['qty' => 5]);++ $this->actingAs($admin)+ ->get(route('components.checkout.show', [+ 'componentID' => $component->id,+ 'request_id' => 999999,+ ]))+ ->assertOk()+ ->assertViewHas('requestingUserId', null);+ }++ public function test_selectlist_scopes_to_users_assigned_assets_when_assigned_to_is_set(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $otherUser = User::factory()->create();++ $assignedToRequester = Asset::factory()->assignedToUser($requester)->create();+ $assignedToOther = Asset::factory()->assignedToUser($otherUser)->create();++ $rows = $this->actingAsForApi($admin)+ ->getJson(route('assets.selectlist', ['assignedTo' => $requester->id]))+ ->assertOk()+ ->json('results');++ $ids = collect($rows)->pluck('id')->all();+ $this->assertContains($assignedToRequester->id, $ids);+ $this->assertNotContains($assignedToOther->id, $ids);+ }++ public function test_view_receives_checkout_request_and_other_pending_requests(): void+ {+ // The info callout above the form reads from two view vars:+ // $checkoutRequest (the row we came in on) and+ // $otherPendingRequests (anyone else still waiting on the same+ // component). Both must resolve when the request_id is valid;+ // the other-pending list must exclude the current row and any+ // canceled rows so the admin sees an accurate waiting list.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $anotherRequester = User::factory()->create();+ $thirdRequester = User::factory()->create();+ $component = Component::factory()->create(['qty' => 5]);++ $currentRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $component->id,+ 'requestable_type' => Component::class,+ 'quantity' => 2,+ ]);+ $otherOpen = CheckoutRequest::factory()->create([+ 'user_id' => $anotherRequester->id,+ 'requestable_id' => $component->id,+ 'requestable_type' => Component::class,+ 'quantity' => 1,+ ]);+ // Canceled row shouldn't appear in the waiting list.+ CheckoutRequest::factory()->create([+ 'user_id' => $thirdRequester->id,+ 'requestable_id' => $component->id,+ 'requestable_type' => Component::class,+ 'canceled_at' => now(),+ ]);++ $response = $this->actingAs($admin)+ ->get(route('components.checkout.show', [+ 'componentID' => $component->id,+ 'request_id' => $currentRequest->id,+ ]))+ ->assertOk();++ $response->assertViewHas('checkoutRequest', fn ($request) => $request?->id === $currentRequest->id);+ $response->assertViewHas('otherPendingRequests', function ($pending) use ($otherOpen, $currentRequest) {+ $ids = collect($pending)->pluck('id')->all();++ return count($ids) === 1+ && in_array($otherOpen->id, $ids, true)+ && ! in_array($currentRequest->id, $ids, true);+ });+ }++ public function test_view_falls_back_to_empty_pending_list_when_request_id_absent(): void+ {+ $admin = User::factory()->superuser()->create();+ $component = Component::factory()->create(['qty' => 5]);++ $response = $this->actingAs($admin)+ ->get(route('components.checkout.show', ['componentID' => $component->id]))+ ->assertOk();++ $response->assertViewHas('checkoutRequest', null);+ $response->assertViewHas('otherPendingRequests', fn ($pending) => collect($pending)->isEmpty());+ }++ public function test_selectlist_returns_empty_when_target_user_has_no_assigned_assets(): void+ {+ // When the requester has nothing assigned to them, the picker+ // returns an empty list rather than falling through to the+ // full fleet. Showing every asset would defeat the point of+ // scoping ("install this into one of the requester's assets")+ // and misleads the admin about who owns what.+ $admin = User::factory()->superuser()->create();+ $userWithNoAssets = User::factory()->create();+ Asset::factory()->create();++ $rows = $this->actingAsForApi($admin)+ ->getJson(route('assets.selectlist', ['assignedTo' => $userWithNoAssets->id]))+ ->assertOk()+ ->json('results');++ $this->assertSame([], $rows);+ }+}diff --git a/tests/Feature/Consumables/Ui/ConsumableCheckoutRequestContextTest.php b/tests/Feature/Consumables/Ui/ConsumableCheckoutRequestContextTest.phpnew file mode 100644index 0000000000..e9d32f169e--- /dev/null+++ b/tests/Feature/Consumables/Ui/ConsumableCheckoutRequestContextTest.php@@ -0,0 +1,118 @@+<?php++namespace Tests\Feature\Consumables\Ui;++use App\Models\Accessory;+use App\Models\CheckoutRequest;+use App\Models\Consumable;+use App\Models\User;+use Tests\TestCase;++/**+ * Consumable-checkout screen reached from /requests: the right column+ * gains a "Requested" box + optional "Also Requested By" box so the+ * admin sees who asked and who else is waiting. Wiring lives in+ * ConsumableCheckoutController::create (calls CheckoutRequest::+ * contextForCheckout for URL-twiddle guards) and is rendered by the+ * shared <x-checkout-request-context> component. Full guard matrix+ * is covered in ComponentCheckoutRequestingUserTest; these tests+ * just prove the wiring reaches this view.+ */+class ConsumableCheckoutRequestContextTest extends TestCase+{+ public function test_view_receives_checkout_request_when_request_id_is_valid(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $consumable = Consumable::factory()->create();+ $checkoutRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $consumable->id,+ 'requestable_type' => Consumable::class,+ ]);++ $this->actingAs($admin)+ ->get(route('consumables.checkout.show', [+ 'consumablesID' => $consumable->id,+ 'request_id' => $checkoutRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', fn ($r) => $r?->id === $checkoutRequest->id);+ }++ public function test_view_receives_null_when_request_id_absent(): void+ {+ $admin = User::factory()->superuser()->create();+ $consumable = Consumable::factory()->create();++ $this->actingAs($admin)+ ->get(route('consumables.checkout.show', ['consumablesID' => $consumable->id]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null)+ ->assertViewHas('otherPendingRequests', fn ($p) => collect($p)->isEmpty());+ }++ public function test_forged_request_id_for_a_different_requestable_type_is_ignored(): void+ {+ // Cross-type guard: an Accessory's request_id passed to the+ // consumable screen must not hydrate an off-scope requester.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $consumable = Consumable::factory()->create();+ $accessory = Accessory::factory()->create();++ $accessoryRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);++ $this->actingAs($admin)+ ->get(route('consumables.checkout.show', [+ 'consumablesID' => $consumable->id,+ 'request_id' => $accessoryRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null);+ }++ public function test_view_receives_other_pending_requests_excluding_the_current_row(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $other = User::factory()->create();+ $consumable = Consumable::factory()->create();++ $currentRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $consumable->id,+ 'requestable_type' => Consumable::class,+ ]);+ $otherOpen = CheckoutRequest::factory()->create([+ 'user_id' => $other->id,+ 'requestable_id' => $consumable->id,+ 'requestable_type' => Consumable::class,+ ]);+ // Canceled row must not appear.+ CheckoutRequest::factory()->create([+ 'user_id' => User::factory()->create()->id,+ 'requestable_id' => $consumable->id,+ 'requestable_type' => Consumable::class,+ 'canceled_at' => now(),+ ]);++ $this->actingAs($admin)+ ->get(route('consumables.checkout.show', [+ 'consumablesID' => $consumable->id,+ 'request_id' => $currentRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('otherPendingRequests', function ($pending) use ($otherOpen, $currentRequest) {+ $ids = collect($pending)->pluck('id')->all();++ return count($ids) === 1+ && in_array($otherOpen->id, $ids, true)+ && ! in_array($currentRequest->id, $ids, true);+ });+ }+}diff --git a/tests/Feature/Licenses/Ui/LicenseCheckoutRequestContextTest.php b/tests/Feature/Licenses/Ui/LicenseCheckoutRequestContextTest.phpnew file mode 100644index 0000000000..18313dd0e3--- /dev/null+++ b/tests/Feature/Licenses/Ui/LicenseCheckoutRequestContextTest.php@@ -0,0 +1,78 @@+<?php++namespace Tests\Feature\Licenses\Ui;++use App\Models\Accessory;+use App\Models\CheckoutRequest;+use App\Models\License;+use App\Models\User;+use Tests\TestCase;++/**+ * License-checkout screen reached from /requests: the right column+ * gains a "Requested" box + optional "Also Requested By" box so the+ * admin sees who asked and who else is waiting. Wiring lives in+ * LicenseCheckoutController::create (calls CheckoutRequest::+ * contextForCheckout for URL-twiddle guards) and is rendered by the+ * shared <x-checkout-request-context> component. Full guard matrix+ * is covered in ComponentCheckoutRequestingUserTest; these tests+ * just prove the wiring reaches this view.+ */+class LicenseCheckoutRequestContextTest extends TestCase+{+ public function test_view_receives_checkout_request_when_request_id_is_valid(): void+ {+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $license = License::factory()->create(['seats' => 5]);+ $checkoutRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $license->id,+ 'requestable_type' => License::class,+ ]);++ $this->actingAs($admin)+ ->get(route('licenses.checkout', [+ 'license' => $license->id,+ 'request_id' => $checkoutRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', fn ($r) => $r?->id === $checkoutRequest->id);+ }++ public function test_view_receives_null_when_request_id_absent(): void+ {+ $admin = User::factory()->superuser()->create();+ $license = License::factory()->create(['seats' => 5]);++ $this->actingAs($admin)+ ->get(route('licenses.checkout', ['license' => $license->id]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null)+ ->assertViewHas('otherPendingRequests', fn ($p) => collect($p)->isEmpty());+ }++ public function test_forged_request_id_for_a_different_requestable_type_is_ignored(): void+ {+ // Cross-type guard: an Accessory's request_id passed to the+ // license screen must not hydrate an off-scope requester.+ $admin = User::factory()->superuser()->create();+ $requester = User::factory()->create();+ $license = License::factory()->create(['seats' => 5]);+ $accessory = Accessory::factory()->create();++ $accessoryRequest = CheckoutRequest::factory()->create([+ 'user_id' => $requester->id,+ 'requestable_id' => $accessory->id,+ 'requestable_type' => Accessory::class,+ ]);++ $this->actingAs($admin)+ ->get(route('licenses.checkout', [+ 'license' => $license->id,+ 'request_id' => $accessoryRequest->id,+ ]))+ ->assertOk()+ ->assertViewHas('checkoutRequest', null);+ }+}diff --git a/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.php b/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.phpindex ef76081fa7..b8dc4df261 100644--- a/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.php+++ b/tests/Feature/Requests/Api/IndexCheckoutRequestsTest.php@@ -196,6 +196,55 @@ class IndexCheckoutRequestsTest extends TestCase$this->assertSame([], $rows[$primary->id]['pending_requesters']);}+ public function test_row_exposes_reservation_window_qty_and_notes_when_set(): void+ {+ // Fields feed the /requests page columns (quantity, remaining,+ // start_date, end_date, notes). All nullable, so a bare+ // "just get me one whenever" request stays clean.+ $admin = User::factory()->viewAssets()->create();+ $consumable = \App\Models\Consumable::factory()->create(['qty' => 20, 'requestable' => true]);+ $request = CheckoutRequest::factory()->create([+ 'requestable_id' => $consumable->id,+ 'requestable_type' => \App\Models\Consumable::class,+ 'quantity' => 4,+ 'start_date' => '2026-09-01',+ 'end_date' => '2026-09-05',+ 'notes' => 'Q3 offsite kit',+ ]);++ $row = collect(+ $this->actingAsForApi($admin)+ ->getJson(route('api.requests.index'))+ ->assertOk()+ ->json('rows')+ )->firstWhere('id', $request->id);++ $this->assertNotNull($row);+ $this->assertSame(4, $row['quantity']);+ $this->assertSame(20, $row['requestable']['remaining']);+ $this->assertNotNull($row['start_date']);+ $this->assertNotNull($row['end_date']);+ $this->assertSame('Q3 offsite kit', $row['notes']);+ }++ public function test_row_leaves_reservation_fields_null_when_unset(): void+ {+ $admin = User::factory()->viewAssets()->create();+ $request = CheckoutRequest::factory()->create();++ $row = collect(+ $this->actingAsForApi($admin)+ ->getJson(route('api.requests.index'))+ ->assertOk()+ ->json('rows')+ )->firstWhere('id', $request->id);++ $this->assertNotNull($row);+ $this->assertNull($row['start_date']);+ $this->assertNull($row['end_date']);+ $this->assertNull($row['notes']);+ }+public function test_asset_requestable_exposes_assigned_flag_and_action_hints(): void{// The Blade page renders "Checkout" vs "Checkin" based ondiff --git a/tests/Feature/Requests/Ui/AccessoryRequestTest.php b/tests/Feature/Requests/Ui/AccessoryRequestTest.phpindex 026d8f7cbf..458bca2e8c 100644--- a/tests/Feature/Requests/Ui/AccessoryRequestTest.php+++ b/tests/Feature/Requests/Ui/AccessoryRequestTest.php@@ -11,7 +11,7 @@ class AccessoryRequestTest extends TestCase{public function test_requestable_index_lists_requestable_accessories(): void{- // The accessories tab on /account/requestable-assets is now+ // The accessories tab on /account/requestable is now// API-backed via api.accessories.requestable. Shell page still// needs a non-empty $accessories view var so the tab-badge// count renders (0 hides the tab entirely), and the API row@@ -21,9 +21,9 @@ class AccessoryRequestTest extends TestCase$nonRequestable = Accessory::factory()->create(['requestable' => false]);$this->actingAs(User::factory()->create())- ->get(route('requestable-assets'))+ ->get(route('account.requestable'))->assertOk()- ->assertViewHas('accessories');+ ->assertViewHas('counts', fn ($counts) => ($counts['accessories'] ?? 0) > 0);$rows = $this->actingAsForApi(User::factory()->create())->getJson(route('api.accessories.requestable'))@@ -133,6 +133,60 @@ class AccessoryRequestTest extends TestCase$this->assertSame('2026-09-05', $request->end_date->toDateString());}+ public function test_user_can_attach_notes_to_an_accessory_request(): void+ {+ // Notes are optional but persist end-to-end when supplied: on+ // the row for admin-queue rendering and via the notification+ // for the fulfillment email/slack.+ $accessory = Accessory::factory()->create(['requestable' => true]);+ $user = User::factory()->create();++ $this->actingAs($user)+ ->post(route('account/request-item', [+ 'itemType' => 'accessory',+ 'itemId' => $accessory->id,+ ]), [+ 'request-quantity' => 1,+ 'notes' => 'Needed for the Q3 offsite',+ ])+ ->assertRedirect();++ $request = CheckoutRequest::where('requestable_id', $accessory->id)+ ->where('requestable_type', Accessory::class)+ ->where('user_id', $user->id)+ ->first();++ $this->assertNotNull($request);+ $this->assertSame('Needed for the Q3 offsite', $request->notes);+ }++ public function test_blank_notes_do_not_persist_as_empty_string(): void+ {+ // An untouched textarea shouldn't create an empty "Additional+ // Notes" block in the admin's email. Controller coerces the+ // empty string to null.+ $accessory = Accessory::factory()->create(['requestable' => true]);+ $user = User::factory()->create();++ $this->actingAs($user)+ ->post(route('account/request-item', [+ 'itemType' => 'accessory',+ 'itemId' => $accessory->id,+ ]), [+ 'request-quantity' => 1,+ 'notes' => '',+ ])+ ->assertRedirect();++ $request = CheckoutRequest::where('requestable_id', $accessory->id)+ ->where('requestable_type', Accessory::class)+ ->where('user_id', $user->id)+ ->first();++ $this->assertNotNull($request);+ $this->assertNull($request->notes);+ }+public function test_request_is_rejected_when_end_date_precedes_start_date(): void{$accessory = Accessory::factory()->create(['requestable' => true]);diff --git a/tests/Feature/Requests/Ui/AssetRequestIndexTest.php b/tests/Feature/Requests/Ui/AssetRequestIndexTest.phpindex 6c3b7bdd01..312eb150af 100644--- a/tests/Feature/Requests/Ui/AssetRequestIndexTest.php+++ b/tests/Feature/Requests/Ui/AssetRequestIndexTest.php@@ -5,20 +5,19 @@ namespace Tests\Feature\Requests\Ui;use App\Models\User;use Tests\TestCase;-class AssetRequestIndexTest extends TestCase{public function test_requires_permission_to_view_asset_request_index(){$this->actingAs(User::factory()->create())- ->get(route('assets.requested'))+ ->get(route('requests.index'))->assertForbidden();}public function test_privileged_user_gets_the_shell_page(){$this->actingAs(User::factory()->viewAssets()->create())- ->get(route('assets.requested'))+ ->get(route('requests.index'))->assertOk();}}diff --git a/tests/Feature/Requests/Ui/BulkCancelRequestTest.php b/tests/Feature/Requests/Ui/BulkCancelRequestTest.phpindex 76d7102d7a..78edb59a42 100644--- a/tests/Feature/Requests/Ui/BulkCancelRequestTest.php+++ b/tests/Feature/Requests/Ui/BulkCancelRequestTest.php@@ -20,15 +20,15 @@ class BulkCancelRequestTest extends TestCasepublic function test_requires_view_assets_permission(): void{$this->actingAs(User::factory()->create())- ->post(route('assets.requested.bulk-cancel'), ['ids' => [1]])+ ->post(route('requests.bulk-cancel'), ['ids' => [1]])->assertForbidden();}public function test_empty_selection_flashes_an_error(): void{$this->actingAs(User::factory()->viewAssets()->create())- ->post(route('assets.requested.bulk-cancel'), ['ids' => []])- ->assertRedirectToRoute('assets.requested')+ ->post(route('requests.bulk-cancel'), ['ids' => []])+ ->assertRedirectToRoute('requests.index')->assertSessionHas('error');}@@ -38,10 +38,10 @@ class BulkCancelRequestTest extends TestCase$requests = CheckoutRequest::factory()->count(3)->create();$this->actingAs($admin)- ->post(route('assets.requested.bulk-cancel'), [+ ->post(route('requests.bulk-cancel'), ['ids' => $requests->pluck('id')->all(),])- ->assertRedirectToRoute('assets.requested')+ ->assertRedirectToRoute('requests.index')->assertSessionHas('success');foreach ($requests as $request) {@@ -59,10 +59,10 @@ class BulkCancelRequestTest extends TestCase$canceled = CheckoutRequest::factory()->create(['canceled_at' => now()->subMinute()]);$this->actingAs($admin)- ->post(route('assets.requested.bulk-cancel'), [+ ->post(route('requests.bulk-cancel'), ['ids' => [$canceled->id],])- ->assertRedirectToRoute('assets.requested')+ ->assertRedirectToRoute('requests.index')->assertSessionHas('warning');}@@ -84,10 +84,10 @@ class BulkCancelRequestTest extends TestCase]);$this->actingAs($adminInA)- ->post(route('assets.requested.bulk-cancel'), [+ ->post(route('requests.bulk-cancel'), ['ids' => [$requestInB->id],])- ->assertRedirectToRoute('assets.requested');+ ->assertRedirectToRoute('requests.index');$this->assertNull($requestInB->fresh()->canceled_at,@@ -115,10 +115,10 @@ class BulkCancelRequestTest extends TestCase]);$this->actingAs($superuser)- ->post(route('assets.requested.bulk-cancel'), [+ ->post(route('requests.bulk-cancel'), ['ids' => [$requestA->id, $requestB->id],])- ->assertRedirectToRoute('assets.requested')+ ->assertRedirectToRoute('requests.index')->assertSessionHas('success');$this->assertNotNull($requestA->fresh()->canceled_at);diff --git a/tests/Feature/Requests/Ui/ComponentRequestTest.php b/tests/Feature/Requests/Ui/ComponentRequestTest.phpindex 5adde82bbf..496fa2284a 100644--- a/tests/Feature/Requests/Ui/ComponentRequestTest.php+++ b/tests/Feature/Requests/Ui/ComponentRequestTest.php@@ -8,19 +8,27 @@ use App\Models\Component;use App\Models\User;use Tests\TestCase;-class ComponentRequestTest extends TestCase{public function test_requestable_index_lists_requestable_components(): void{- $component = Component::factory()->create(['requestable' => true]);- Component::factory()->create(['requestable' => false]);+ // API-backed. See AccessoryRequestTest for the rationale.+ $requestable = Component::factory()->create(['requestable' => true]);+ $nonRequestable = Component::factory()->create(['requestable' => false]);$this->actingAs(User::factory()->create())- ->get(route('requestable-assets'))+ ->get(route('account.requestable'))->assertOk()- ->assertViewHas('components')- ->assertSeeText($component->name);+ ->assertViewHas('counts', fn ($counts) => ($counts['components'] ?? 0) > 0);++ $rows = $this->actingAsForApi(User::factory()->create())+ ->getJson(route('api.components.requestable'))+ ->assertOk()+ ->json('rows');++ $ids = collect($rows)->pluck('id')->all();+ $this->assertContains($requestable->id, $ids);+ $this->assertNotContains($nonRequestable->id, $ids);}public function test_user_can_request_a_requestable_component(): voiddiff --git a/tests/Feature/Requests/Ui/ConsumableRequestTest.php b/tests/Feature/Requests/Ui/ConsumableRequestTest.phpindex 95ca5ce1f9..6ed1e7d7e5 100644--- a/tests/Feature/Requests/Ui/ConsumableRequestTest.php+++ b/tests/Feature/Requests/Ui/ConsumableRequestTest.php@@ -18,16 +18,16 @@ class ConsumableRequestTest extends TestCase{public function test_requestable_index_lists_requestable_consumables(): void{- // The consumables tab on /account/requestable-assets is now+ // The consumables tab on /account/requestable is now// API-backed via api.consumables.requestable. See the sibling// AccessoryRequestTest for the shell-page + API-shape rationale.$requestable = Consumable::factory()->create(['requestable' => true]);$nonRequestable = Consumable::factory()->create(['requestable' => false]);$this->actingAs(User::factory()->create())- ->get(route('requestable-assets'))+ ->get(route('account.requestable'))->assertOk()- ->assertViewHas('consumables');+ ->assertViewHas('counts', fn ($counts) => ($counts['consumables'] ?? 0) > 0);$rows = $this->actingAsForApi(User::factory()->create())->getJson(route('api.consumables.requestable'))diff --git a/tests/Feature/Requests/Ui/LicenseRequestTest.php b/tests/Feature/Requests/Ui/LicenseRequestTest.phpindex 9a055fb6bb..bda1c6e4fc 100644--- a/tests/Feature/Requests/Ui/LicenseRequestTest.php+++ b/tests/Feature/Requests/Ui/LicenseRequestTest.php@@ -18,14 +18,23 @@ class LicenseRequestTest extends TestCase{public function test_requestable_index_lists_requestable_licenses(): void{- $license = License::factory()->create(['requestable' => true]);- License::factory()->create(['requestable' => false]);+ // API-backed. See AccessoryRequestTest for the rationale.+ $requestable = License::factory()->create(['requestable' => true]);+ $nonRequestable = License::factory()->create(['requestable' => false]);$this->actingAs(User::factory()->create())- ->get(route('requestable-assets'))+ ->get(route('account.requestable'))+ ->assertOk()+ ->assertViewHas('counts', fn ($counts) => ($counts['licenses'] ?? 0) > 0);++ $rows = $this->actingAsForApi(User::factory()->create())+ ->getJson(route('api.licenses.requestable'))->assertOk()- ->assertViewHas('licenses')- ->assertSeeText($license->name);+ ->json('rows');++ $ids = collect($rows)->pluck('id')->all();+ $this->assertContains($requestable->id, $ids);+ $this->assertNotContains($nonRequestable->id, $ids);}public function test_user_can_request_a_requestable_license(): void