A free open source IT asset/license management system
Scaffold route and tests
Marcus Moore73e185bf9de0
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.phpindex 755a50ccac..32f1a8b359 100644--- a/app/Http/Controllers/Api/AssetsController.php+++ b/app/Http/Controllers/Api/AssetsController.php@@ -1322,6 +1322,10 @@ class AssetsController extends Controllerreturn (new AssetsTransformer)->transformCheckedoutAccessories($accessory_checkouts, $total);}+ public function assignedComponents(Request $request, Asset $asset): JsonResponse+ {+ //+ }/*** Generate asset labels by tagdiff --git a/routes/api.php b/routes/api.phpindex 988cedb645..a6697b6b19 100644--- a/routes/api.php+++ b/routes/api.php@@ -571,6 +571,13 @@ Route::group(['prefix' => 'v1', 'middleware' => ['api', 'api-throttle:api']], fu'assignedAccessories'])->name('api.assets.assigned_accessories');++ Route::get('{asset}/assigned/components',+ [+ Api\AssetsController::class,+ 'assignedComponents'+ ]+ )->name('api.assets.assigned_components');/** End assigned routes */});diff --git a/tests/Feature/Assets/Api/AssignedComponentsTest.php b/tests/Feature/Assets/Api/AssignedComponentsTest.phpnew file mode 100644index 0000000000..13156d8204--- /dev/null+++ b/tests/Feature/Assets/Api/AssignedComponentsTest.php@@ -0,0 +1,57 @@+<?php++namespace Tests\Feature\Assets\Api;++use App\Models\Asset;+use App\Models\Company;+use App\Models\Component;+use App\Models\User;+use Illuminate\Testing\Fluent\AssertableJson;+use Tests\TestCase;++class AssignedComponentsTest extends TestCase+{+ public function test_requires_permission()+ {+ $this->actingAsForApi(User::factory()->create())+ ->getJson(route('api.assets.assigned_components', Asset::factory()->create()))+ ->assertForbidden();+ }++ public function test_adheres_to_company_scoping()+ {+ $this->settings->enableMultipleFullCompanySupport();++ [$companyA, $companyB] = Company::factory()->count(2)->create();++ $asset = Asset::factory()->for($companyA)->create();++ $user = User::factory()->for($companyB)->viewAssets()->create();++ $this->actingAsForApi($user)+ ->getJson(route('api.assets.assigned_components', $asset))+ ->assertOk()+ ->assertStatusMessageIs('error')+ ->assertMessagesAre('Asset not found');+ }++ public function test_can_get_components_assigned_to_specific_asset()+ {+ $unassociatedComponent = Component::factory()->create();++ $asset = Asset::factory()->hasComponents(2)->create();++ $componentsAssignedToAsset = $asset->components;++ $this->actingAsForApi(User::factory()->viewAssets()->create())+ ->getJson(route('api.assets.assigned_components', $asset))+ ->assertOk()+ ->assertResponseContainsInRows($componentsAssignedToAsset)+ ->assertResponseDoesNotContainInRows($unassociatedComponent)+ ->assertJson(function (AssertableJson $json) {+ $json->where('total', 2)+ ->count('rows', 2)+ ->etc();+ });+ }+}