A free open source IT asset/license management system
Updated tests
snipe831b2823862d
diff --git a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.phpindex 1515c12f8f..601508ff84 100644--- a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php@@ -10,6 +10,7 @@ use App\Models\CheckoutAcceptance;use App\Models\Location;use App\Models\User;use Illuminate\Support\Facades\Mail;+use PHPUnit\Framework\Attributes\DataProvider;use Tests\TestCase;class AccessoryCheckoutTest extends TestCase@@ -346,4 +347,45 @@ class AccessoryCheckoutTest extends TestCase$response->assertSessionHas('sign_in_place', true);}++ /**+ * Regression: AccessoryCheckoutController::store used to call+ * session()->put(['checkout_to_type' => $target]);+ * with $target being the resolved Eloquent model, not the string kind.+ * The checkout-selector partial compares against 'user'/'asset'/'location'+ * literals, so an object silently mismatched and no radio was rendered+ * `checked`.+ *+ * @see \App\Http\Controllers\Accessories\AccessoryCheckoutController::store+ */+ #[DataProvider('accessoryCheckoutTargetTypesProvider')]+ public function test_accessory_checkout_stores_target_type_as_string_in_session(string $type)+ {+ [$field, $target] = match ($type) {+ 'user' => ['assigned_user', User::factory()->create()->id],+ 'asset' => ['assigned_asset', Asset::factory()->create()->id],+ 'location' => ['assigned_location', Location::factory()->create()->id],+ };+ $accessory = Accessory::factory()->create();++ $this->actingAs(User::factory()->admin()->create())+ ->post(route('accessories.checkout.store', $accessory), [+ 'checkout_to_type' => $type,+ $field => $target,+ ])+ ->assertSessionHasNoErrors();++ $stored = session('checkout_to_type');+ $this->assertIsString($stored, 'checkout_to_type must be a string, not an Eloquent model');+ $this->assertSame($type, $stored);+ }++ public static function accessoryCheckoutTargetTypesProvider(): array+ {+ return [+ 'user target' => ['user'],+ 'asset target' => ['asset'],+ 'location target' => ['location'],+ ];+ }}diff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.phpindex 31afcec4ee..f87f289707 100644--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php@@ -230,4 +230,44 @@ class BulkAssetCheckoutTest extends TestCase// ensure redirected back$response->assertRedirectToRoute('hardware.bulkcheckout.show');}++ /**+ * Regression: BulkAssetsController::store used to call+ * session()->put(['checkout_to_type' => $target]);+ * with $target being the resolved Eloquent model. The checkout-selector+ * partial compares against 'user'/'asset'/'location' string literals, so+ * an object silently mismatched and no radio rendered `checked`.+ *+ * @see \App\Http\Controllers\Assets\BulkAssetsController::store+ */+ #[DataProvider('bulkCheckoutTargetTypesProvider')]+ public function test_bulk_checkout_stores_target_type_as_string_in_session(string $type)+ {+ [$field, $target] = match ($type) {+ 'user' => ['assigned_user', User::factory()->create()->id],+ 'asset' => ['assigned_asset', Asset::factory()->create()->id],+ 'location' => ['assigned_location', Location::factory()->create()->id],+ };+ $asset = Asset::factory()->create();++ $this->actingAs(User::factory()->superuser()->create())+ ->post(route('hardware.bulkcheckout.store'), [+ 'selected_assets' => [$asset->id],+ 'checkout_to_type' => $type,+ $field => $target,+ ]);++ $stored = session('checkout_to_type');+ $this->assertIsString($stored, 'checkout_to_type must be a string, not an Eloquent model');+ $this->assertSame($type, $stored);+ }++ public static function bulkCheckoutTargetTypesProvider(): array+ {+ return [+ 'user target' => ['user'],+ 'asset target' => ['asset'],+ 'location target' => ['location'],+ ];+ }}diff --git a/tests/Feature/Livewire/CheckoutTargetPanelTest.php b/tests/Feature/Livewire/CheckoutTargetPanelTest.phpindex a0133c3a76..7650bedb18 100644--- a/tests/Feature/Livewire/CheckoutTargetPanelTest.php+++ b/tests/Feature/Livewire/CheckoutTargetPanelTest.php@@ -94,15 +94,15 @@ class CheckoutTargetPanelTest extends TestCase->assertSee($child->asset_tag);}- public function test_location_target_lists_assets_at_that_location(): void+ public function test_location_target_lists_assets_checked_out_to_that_location(): void{$admin = User::factory()->superuser()->create();$location = Location::factory()->create();- // Location::assets() is a hasMany on the assets.location_id column- // (physical location), not on the polymorphic assigned_to/assigned_type- // pair — Asset::checkOut() sets both when the target is a Location.+ // "Checked out to a location" = polymorphic assigned_to / assigned_type+ // pair. We deliberately do NOT set location_id here so this asserts+ // the panel is using Location::assignedAssets (checkout target),+ // not Location::assets (physical/default location).$asset = Asset::factory()->create([- 'location_id' => $location->id,'assigned_to' => $location->id,'assigned_type' => Location::class,'asset_tag' => 'PANEL-TEST-LOCATION-ASSET',@@ -114,6 +114,27 @@ class CheckoutTargetPanelTest extends TestCase->assertSee($asset->asset_tag);}+ public function test_location_target_does_not_list_assets_merely_assigned_to_that_location_id(): void+ {+ // Regression: earlier version used Location::assets() (location_id-+ // based) which pulls in assets that just happen to have this as their+ // physical/default location but were never CHECKED OUT to it. That's+ // wrong for a "current checkouts" sidebar.+ $admin = User::factory()->superuser()->create();+ $location = Location::factory()->create();+ Asset::factory()->create([+ 'location_id' => $location->id,+ // no assigned_to / assigned_type — asset is at this location+ // physically but not checked out to it.+ 'asset_tag' => 'PANEL-TEST-PHYSICAL-ONLY',+ ]);++ Livewire::actingAs($admin)+ ->test(CheckoutTargetPanel::class, ['type' => 'assets'])+ ->dispatch('checkout-target-selected', targetType: 'location', targetId: (string) $location->id)+ ->assertDontSee('PANEL-TEST-PHYSICAL-ONLY');+ }+public function test_impossible_combo_consumables_to_asset_returns_empty(): void{// Consumables can only be checked out to users; picking an asset target