A free open source IT asset/license management system
Added regression test
snipe602dece95c12
diff --git a/tests/Feature/Assets/Api/AssetIndexTest.php b/tests/Feature/Assets/Api/AssetIndexTest.phpindex d1b98f0dcf..4a7a1fe3ba 100644--- a/tests/Feature/Assets/Api/AssetIndexTest.php+++ b/tests/Feature/Assets/Api/AssetIndexTest.php@@ -259,4 +259,46 @@ class AssetIndexTest extends TestCase[$response[0]['id'], $response[1]['id']],);}++ public function test_deleted_status_type_returns_soft_deleted_assets()+ {+ $deleted = Asset::factory()->count(3)->create();+ foreach ($deleted as $asset) {+ $asset->delete();+ }+ Asset::factory()->count(2)->create();++ $response = $this->actingAsForApi(User::factory()->superuser()->create())+ ->getJson(route('api.assets.index', ['status_type' => 'Deleted', 'limit' => 10]))+ ->assertOk();++ $response->assertJsonPath('total', 3);+ $rows = $response->json('rows');+ $this->assertCount(3, $rows, 'Deleted view must return the soft-deleted assets, not an empty rows array.');++ $returnedIds = collect($rows)->pluck('id')->sort()->values()->all();+ $expectedIds = $deleted->pluck('id')->sort()->values()->all();+ $this->assertSame($expectedIds, $returnedIds, 'Returned rows must match the soft-deleted asset ids, not any live ones.');+ }++ public function test_default_index_still_excludes_soft_deleted_assets()+ {+ // Companion to the Deleted-view regression. The withTrashed() on+ // re-hydration is scoped to that one query, so the id pluck+ // (which has no explicit onlyTrashed() for a default request)+ // keeps excluding soft-deleted rows and the rows array matches.+ $live = Asset::factory()->count(2)->create();+ $deleted = Asset::factory()->count(3)->create();+ foreach ($deleted as $asset) {+ $asset->delete();+ }++ $response = $this->actingAsForApi(User::factory()->superuser()->create())+ ->getJson(route('api.assets.index', ['limit' => 10]))+ ->assertOk();++ $response->assertJsonPath('total', 2);+ $returnedIds = collect($response->json('rows'))->pluck('id')->sort()->values()->all();+ $this->assertSame($live->pluck('id')->sort()->values()->all(), $returnedIds);+ }}