diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bc415c0f3d..f798232a7b 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -629,14 +629,12 @@ class AssetsController extends Controller // this is _always_ filled now, see UpdateAssetRequest // i'm leaving it like this for now, but when would we ever want model_id to be `null`?? // it actually breaks at the model validation if it gets to null... - ($request->validated()['model_id']) ? + ($request->has('model_id')) ? $asset->model()->associate(AssetModel::find($request->validated()['model_id'])) : null; - //($request->validated()['rtd_location_id']) ? - // $asset->location_id = $request->validated()['rtd_location_id'] : ''; - //($request->validated()['company_id']) ? - // $asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']) : ''; - //($request->validated()['rtd_location_id']) ? - // $asset->location_id = $request->validated()['rtd_location_id'] : null; + ($request->has('company_id')) ? + $asset->company_id = Company::getIdForCurrentUser($request->validated()['company_id']) : null; + ($request->has('rtd_location_id')) ? + $asset->location_id = $request->validated()['rtd_location_id'] : null; /** * this is here just legacy reasons. Api\AssetController diff --git a/tests/Feature/Api/Assets/AssetUpdateTest.php b/tests/Feature/Api/Assets/AssetUpdateTest.php index 79a9eb4e0b..c134c70db6 100644 --- a/tests/Feature/Api/Assets/AssetUpdateTest.php +++ b/tests/Feature/Api/Assets/AssetUpdateTest.php @@ -29,13 +29,15 @@ class AssetUpdateTest extends TestCase ->assertForbidden(); } - public function testGivenPermissionUpdateAssetIsAllower() + public function testGivenPermissionUpdateAssetIsAllowed() { $asset = Asset::factory()->create(); $this->actingAsForApi(User::factory()->editAssets()->create()) - ->patchJson(route('api.assets.update', $asset->id)) + ->patchJson(route('api.assets.update', $asset->id), [ + 'name' => 'test' + ]) ->assertOk(); } @@ -103,21 +105,20 @@ class AssetUpdateTest extends TestCase public function testAssetEolDateIsCalculatedIfPurchaseDateUpdated() { - $model = AssetModel::factory()->mbp13Model()->create(); - $asset = Asset::factory()->create(); + $asset = Asset::factory()->laptopMbp()->create(); $this->settings->enableAutoIncrement(); $response = $this->actingAsForApi(User::factory()->editAssets()->create()) ->patchJson((route('api.assets.update', $asset->id)), [ - 'model_id' => $model->id, 'purchase_date' => '2021-01-01', ]) - //->dd() ->assertOk() ->assertStatusMessageIs('success') ->json(); + $asset->refresh(); + $this->assertEquals('2024-01-01', $asset->asset_eol_date); }