Begin to build out test

This commit is contained in:
Marcus Moore
2025-09-08 17:20:22 -07:00
parent e1aa843b6d
commit 324070f345
2 changed files with 29 additions and 5 deletions
+13 -2
View File
@@ -1290,9 +1290,20 @@ class AssetsController extends Controller
public function assignedAssets(Request $request, Asset $asset) : JsonResponse | array
{
// @todo: authorization
return [];
// to do
$query = Asset::where([
'assigned_to' => $asset->id,
'assigned_type' => Asset::class,
]);
// @todo: offset
// @todo: limit
$total = $query->count();
$assets = $query->get();
return (new AssetsTransformer)->transformAssets($assets, $total);
}
public function assignedAccessories(Request $request, Asset $asset) : JsonResponse | array
@@ -4,6 +4,7 @@ namespace Tests\Feature\Assets\Api;
use App\Models\Asset;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
class AssignedAssetsTest extends TestCase
@@ -17,12 +18,24 @@ class AssignedAssetsTest extends TestCase
public function test_can_get_assets_assigned_to_specific_asset()
{
$this->markTestIncomplete();
$unassociatedAsset = Asset::factory()->create();
// check out asset to an asset
$asset = Asset::factory()->hasAssignedAssets(2)->create();
// make request
$assetsAssignedToAsset = Asset::where([
'assigned_to' => $asset->id,
'assigned_type' => Asset::class,
])->get();
$this->actingAsForApi(User::factory()->viewAssets()->create())
->getJson(route('api.assets.assigned_assets', $asset))
->assertOk()
->dump()
->assertJson(function (AssertableJson $json) {
$json->etc();
});
// assert assigned asset included in response
// assert unassociated asset not in response
}
}