A free open source IT asset/license management system
some more tests and refinement
spencerrlonggc0110e7f29bd
diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.phpindex 71792b85fc..97282036fa 100644--- a/app/Http/Requests/UpdateAssetRequest.php+++ b/app/Http/Requests/UpdateAssetRequest.php@@ -23,9 +23,9 @@ class UpdateAssetRequest extends ImageUploadRequest// the following are 'required' attributes that may or may not be present on an patch request// so supplying them here instead of doing funky array modification to the rulesreturn $this->merge([- 'asset_tag' => $this->asset_tag ?? $this->asset->asset_tag,- 'model_id' => $this->model_id ?? $this->asset->model_id,- 'status_id' => $this->status_id ?? $this->asset->status_id,+ //'asset_tag' => $this->asset_tag ?? $this->asset->asset_tag,+ //'model_id' => $this->model_id ?? $this->asset->model_id,+ //'status_id' => $this->status_id ?? $this->asset->status_id,]);}@@ -37,9 +37,9 @@ class UpdateAssetRequest extends ImageUploadRequestpublic function rules(){$rules = [- 'model_id' => 'required|integer|exists:models,id,deleted_at,NULL|not_array',- 'status_id' => 'required|integer|exists:status_labels,id',- 'asset_tag' => ['required', 'min:1', 'max:255', 'not_array', Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed()],+ 'model_id' => 'integer|exists:models,id,deleted_at,NULL|not_array',+ 'status_id' => 'integer|exists:status_labels,id',+ 'asset_tag' => ['min:1', 'max:255', 'not_array', Rule::unique('assets', 'asset_tag')->ignore($this->asset)->withoutTrashed()],'name' => 'nullable|max:255','company_id' => 'nullable|integer|exists:companies,id','warranty_months' => 'nullable|numeric|digits_between:0,240',diff --git a/tests/Feature/Api/Assets/AssetUpdateTest.php b/tests/Feature/Api/Assets/AssetUpdateTest.phpindex 17bb72fa30..79a9eb4e0b 100644--- a/tests/Feature/Api/Assets/AssetUpdateTest.php+++ b/tests/Feature/Api/Assets/AssetUpdateTest.php@@ -11,6 +11,8 @@ use App\Models\Supplier;use App\Models\User;use Carbon\Carbon;use Illuminate\Testing\Fluent\AssertableJson;++// TODO: DELETE INTERACTSWITHSETTINGS BEFORE FINAL PRuse Tests\Support\InteractsWithSettings;use Tests\TestCase;@@ -125,7 +127,7 @@ class AssetUpdateTest extends TestCase$this->settings->enableAutoIncrement();- $response = $this->actingAsForApi(User::factory()->editAssets()->create())+ $this->actingAsForApi(User::factory()->editAssets()->create())->patchJson(route('api.assets.update', $asset->id), ['name' => 'test asset','asset_eol_date' => '2022-01-01'@@ -139,4 +141,93 @@ class AssetUpdateTest extends TestCase$this->assertEquals('2022-01-01', $asset->asset_eol_date);}+ public function testAssetEolExplicitIsSetIfAssetEolDateIsExplicitlySet()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'asset_eol_date' => '2025-01-01',+ ])+ ->assertOk()+ ->assertStatusMessageIs('success')+ ->json();++ $asset->refresh();++ $this->assertEquals('2025-01-01', $asset->asset_eol_date);+ $this->assertTrue($asset->eol_explicit);+ }++ public function testAssetTagCannotUpdateToNullValue()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'asset_tag' => null,+ ])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }++ public function testAssetTagCannotUpdateToEmptyStringValue()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'asset_tag' => "",+ ])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }++ public function testModelIdCannotUpdateToNullValue()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'model_id' => null+ ])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }++ public function testModelIdCannotUpdateToEmptyStringValue()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'model_id' => ""+ ])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }++ public function testStatusIdCannotUpdateToNullValue()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'status_id' => null+ ])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }++ public function testStatusIdCannotUpdateToEmptyStringValue()+ {+ $asset = Asset::factory()->laptopMbp()->create();++ $this->actingAsForApi(User::factory()->editAssets()->create())+ ->patchJson(route('api.assets.update', $asset->id), [+ 'status_id' => ""+ ])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }}\ No newline at end of file