Test against other types
This commit is contained in:
@@ -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]);
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user