mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
some more tests and refinement
This commit is contained in:
parent
86ab880c90
commit
c0110e7f29
|
@ -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 rules
|
||||
return $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 ImageUploadRequest
|
|||
public 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',
|
||||
|
|
|
@ -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 PR
|
||||
use 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');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue