mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Remove unnecessary parameter and add delete asset tests
Removed the redundant $request parameter from the destroy method in AssetsController. Added feature tests to verify asset deletion functionality with proper permissions and ensure deletion is forbidden without permissions.
This commit is contained in:
parent
233656df01
commit
09d4e0cb05
|
@ -279,7 +279,7 @@ class AssetsController extends Controller
|
|||
* @param int $assetId
|
||||
* @since [v1.0]
|
||||
*/
|
||||
public function destroy(Asset $asset, $request): RedirectResponse
|
||||
public function destroy(Asset $asset): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $asset);
|
||||
try {
|
||||
|
|
31
tests/Feature/Assets/Ui/DeleteAssetTest.php
Normal file
31
tests/Feature/Assets/Ui/DeleteAssetTest.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Assets\Ui;
|
||||
|
||||
use App\Models\Asset;
|
||||
use App\Models\User;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DeleteAssetTest extends TestCase
|
||||
{
|
||||
public function test_asset_can_be_deleted_with_permissions()
|
||||
{
|
||||
$user = User::factory()->deleteAssets()->create();
|
||||
|
||||
$asset = Asset::factory()->create();
|
||||
$this->actingAs($user)
|
||||
->delete(route('hardware.destroy', $asset))
|
||||
->assertRedirect(route('hardware.index'));
|
||||
}
|
||||
|
||||
public function test_asset_cannot_be_deleted_without_permissions()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$asset = Asset::factory()->create();
|
||||
$this->actingAs($user)
|
||||
->delete(route('hardware.destroy', $asset))
|
||||
->assertForbidden();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue