Skip to content

A free open source IT asset/license management system

Test against other types

Marcus Moore7a3596c86d54
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php
index 8ba3ccf99d..4b9ccb6753 100644
--- a/app/Http/Controllers/Assets/BulkAssetsController.php
+++ b/app/Http/Controllers/Assets/BulkAssetsController.php
@@ -647,6 +647,7 @@ class BulkAssetsController extends Controller
$assets = Asset::findOrFail($asset_ids);
+ // Prevent checking out assets that are already checked out
if ($assets->pluck('assigned_to')->unique()->filter()->isNotEmpty()) {
// re-add the asset ids so the assets select is re-populated
$request->session()->flashInput(['selected_assets' => $asset_ids]);
diff --git a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
index 0791b3b422..c9619dbd69 100644
--- a/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
+++ b/tests/Feature/Checkouts/Ui/BulkAssetCheckoutTest.php
@@ -4,8 +4,10 @@ namespace Tests\Feature\Checkouts\Ui;
use App\Mail\CheckoutAssetMail;
use App\Models\Asset;
+use App\Models\Location;
use App\Models\User;
use Illuminate\Support\Facades\Mail;
+use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\ExpectationFailedException;
use Tests\TestCase;
@@ -90,22 +92,53 @@ class BulkAssetCheckoutTest extends TestCase
}
}
- public function test_prevents_checkouts_checked_out_items()
+ public static function checkoutTargets()
{
+ yield 'Checkout to user' => [
+ function () {
+ return [
+ 'type' => 'user',
+ 'target' => User::factory()->forCompany()->create(),
+ ];
+ }
+ ];
+
+ yield 'Checkout to asset' => [
+ function () {
+ return [
+ 'type' => 'asset',
+ 'target' => Asset::factory()->forCompany()->create(),
+ ];
+ }
+ ];
+
+ yield 'Checkout to location' => [
+ function () {
+ return [
+ 'type' => 'location',
+ 'target' => Location::factory()->forCompany()->create(),
+ ];
+ }
+ ];
+ }
+
+ #[DataProvider('checkoutTargets')]
+ public function test_prevents_checkouts_checked_out_items($data)
+ {
+ ['type' => $type, 'target' => $target] = $data();
+
$asset = Asset::factory()->create();
$checkedOutAsset = Asset::factory()->assignedToUser()->create();
$existingUserId = $checkedOutAsset->assigned_to;
- $target = User::factory()->create();
-
$response = $this->actingAs(User::factory()->superuser()->create())
->post(route('hardware.bulkcheckout.store'), [
'selected_assets' => [
$asset->id,
$checkedOutAsset->id,
],
- 'checkout_to_type' => 'user',
- 'assigned_user' => $target->id,
+ 'checkout_to_type' => $type,
+ "assigned_$type" => $target->id,
]);
$this->assertEquals(