From c7fa2c04ad1685e372ed0b37bfb19ae478232fbd Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 22 May 2024 13:33:12 -0700 Subject: [PATCH] Add scenario --- app/Http/Controllers/Api/AssetsController.php | 3 --- tests/Feature/Api/Assets/AssetCheckoutTest.php | 12 ++++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index b1697d7c6c..bfdc0255e1 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -823,7 +823,6 @@ class AssetsController extends Controller // This item is checked out to a location if (request('checkout_to_type') == 'location') { $target = Location::find(request('assigned_location')); - // @todo: test the setting of '' $asset->location_id = ($target) ? $target->id : ''; $error_payload['target_id'] = $request->input('assigned_location'); $error_payload['target_type'] = 'location'; @@ -836,10 +835,8 @@ class AssetsController extends Controller $error_payload['target_type'] = 'asset'; } elseif (request('checkout_to_type') == 'user') { - // @todo: test this code path // Fetch the target and set the asset's new location_id $target = User::find(request('assigned_user')); - // @todo: test if this is needed or already handled in checkOut method $asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : ''; $error_payload['target_id'] = $request->input('assigned_user'); $error_payload['target_type'] = 'user'; diff --git a/tests/Feature/Api/Assets/AssetCheckoutTest.php b/tests/Feature/Api/Assets/AssetCheckoutTest.php index 34183650cb..1199f8c6d4 100644 --- a/tests/Feature/Api/Assets/AssetCheckoutTest.php +++ b/tests/Feature/Api/Assets/AssetCheckoutTest.php @@ -85,6 +85,18 @@ class AssetCheckoutTest extends TestCase public function checkoutTargets(): array { return [ + 'Checkout to User without location set' => [ + function () { + $userLocation = Location::factory()->create(); + $user = User::factory()->for($userLocation)->create(['location_id' => null]); + + return [ + 'checkout_type' => 'user', + 'target' => $user, + 'expected_location' => null, + ]; + } + ], 'Checkout to User' => [ function () { $userLocation = Location::factory()->create();