Skip to content

A free open source IT asset/license management system

standardize some of the validation rules, fix int/string issue

spencerrlonggcba5f869c0aa
diff --git a/app/Models/Asset.php b/app/Models/Asset.php
index 4acb08099f..406f4deb19 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -89,28 +89,28 @@ class Asset extends Depreciable
];
protected $rules = [
- 'name' => 'max:255|nullable',
+ 'name' => 'nullable|max:255',
'model_id' => 'required|integer|exists:models,id,deleted_at,NULL|not_array',
'status_id' => 'required|integer|exists:status_labels,id',
- 'company_id' => 'integer|nullable|exists:companies,id',
- 'warranty_months' => 'numeric|nullable|digits_between:0,240',
- 'physical' => 'numeric|max:1|nullable',
- 'last_checkout' => 'date_format:Y-m-d H:i:s|nullable',
- 'expected_checkin' => 'date|nullable',
- 'location_id' => 'exists:locations,id|nullable',
- 'rtd_location_id' => 'exists:locations,id|nullable',
+ 'company_id' => 'nullable|integer|exists:companies,id',
+ 'warranty_months' => 'nullable|numeric|digits_between:0,240',
+ 'physical' => 'nullable|numeric|max:1',
+ 'last_checkout' => 'nullable|date_format:Y-m-d H:i:s',
+ 'expected_checkin' => 'nullable|date',
+ 'location_id' => 'nullable|exists:locations,id',
+ 'rtd_location_id' => 'nullable|exists:locations,id',
'asset_tag' => 'required|min:1|max:255|unique_undeleted:assets,asset_tag|not_array',
- 'purchase_date' => 'date|date_format:Y-m-d|nullable',
- 'serial' => 'unique_undeleted:assets,serial|nullable',
- 'purchase_cost' => 'numeric|nullable|gte:0',
- 'supplier_id' => 'exists:suppliers,id|nullable',
- 'asset_eol_date' => 'date|nullable',
- 'eol_explicit' => 'boolean|nullable',
+ 'purchase_date' => 'nullable|date|date_format:Y-m-d',
+ 'serial' => 'nullable|unique_undeleted:assets,serial',
+ 'purchase_cost' => 'nullable|numeric|gte:0',
+ 'supplier_id' => 'nullable|exists:suppliers,id',
+ 'asset_eol_date' => 'nullable|date',
+ 'eol_explicit' => 'nullable|boolean',
'byod' => 'nullable|boolean',
- 'order_number' => 'string|max:191|nullable',
- 'notes' => 'string|max:65535|nullable',
- 'assigned_to' => 'integer|exists:users,id|nullable',
- 'requestable' => 'boolean|nullable',
+ 'order_number' => 'nullable|string|max:191',
+ 'notes' => 'nullable|string|max:65535',
+ 'assigned_to' => 'nullable|integer|exists:users,id',
+ 'requestable' => 'nullable|boolean',
];
diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php
index ccb6474e5a..432495bcc7 100644
--- a/database/factories/AssetFactory.php
+++ b/database/factories/AssetFactory.php
@@ -41,7 +41,7 @@ class AssetFactory extends Factory
'notes' => 'Created by DB seeder',
'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'),
'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'),
- 'order_number' => $this->faker->numberBetween(1000000, 50000000),
+ 'order_number' => (string) $this->faker->numberBetween(1000000, 50000000),
'supplier_id' => Supplier::factory(),
'requestable' => $this->faker->boolean(),
'assigned_to' => null,
diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php
index 8771187b2a..845e7fce90 100644
--- a/tests/Unit/AssetModelTest.php
+++ b/tests/Unit/AssetModelTest.php
@@ -22,19 +22,16 @@ class AssetModelTest extends TestCase
public function testAnAssetModelContainsAssets()
{
- $category = Category::factory()->create(
- ['category_type' => 'asset']
- );
+ $category = Category::factory()->create([
+ 'category_type' => 'asset'
+ ]);
$model = AssetModel::factory()->create([
'category_id' => $category->id,
]);
- $asset = Asset::factory()
- ->create(
- [
+ $asset = Asset::factory()->create([
'model_id' => $model->id
- ]
- );
+ ]);
$this->assertEquals(1, $model->assets()->count());
}
}