A free open source IT asset/license management system
adds tests for requiring serial to asset model
Godfrey M8c0281bf7038
diff --git a/tests/Feature/Assets/Ui/StoreAssetsTest.php b/tests/Feature/Assets/Ui/StoreAssetsTest.phpindex 8abea545cf..baa9babcc0 100644--- a/tests/Feature/Assets/Ui/StoreAssetsTest.php+++ b/tests/Feature/Assets/Ui/StoreAssetsTest.php@@ -2,6 +2,8 @@namespace Tests\Feature\Assets\Ui;+use App\Models\Asset;+use App\Models\AssetModel;use App\Models\User;use Tests\TestCase;@@ -13,4 +15,63 @@ class StoreAssetsTest extends TestCase->get(route('hardware.create'))->assertOk();}++ public function testAssetCanBeStoredWithSerialRequiredAndSerialProvided()+ {+ $user = User::factory()->superuser()->create();+ $this->actingAs($user);++ $model = AssetModel::factory()->create([+ 'require_serial' => 1,+ ]);++ $response = $this->post(route('hardware.store'), [+ 'model_id' => $model->id,+ 'serials' => [1 => 'ABC123'],+ 'asset_tags' =>[1 => '1234'],+ 'status_id' => 1,+ // other required fields...+ ]);++ $response->assertRedirect();+ $response->assertSessionHas('success-unescaped');+ $this->assertNotEquals(+ trans('admin/hardware/form.serial_required'),+ session('error')+ );+ $this->assertDatabaseHas('assets', [+ 'model_id' => $model->id,+ 'serial' => 'ABC123',+ 'asset_tag' => '1234',+ ]);+++ }++ public function testAssetCannotBeStoredIfSerialRequiredAndMissing()+ {+ $user = User::factory()->superuser()->create();+ $this->actingAs($user);++ $model = AssetModel::factory()->create([+ 'require_serial' => 1,+ ]);++ $response = $this->post(route('hardware.store'), [+ 'model_id' => $model->id,+ 'serials' => [], // ← serial missing+ 'asset_tags' => [1 => '1234'],+ 'status_id' => 1,+ ]);++ $response->assertRedirect();+ $response->assertSessionHasErrors(['serials.1']);++ $this->assertDatabaseMissing('assets', [+ 'model_id' => $model->id,+ 'asset_tag' => '1234',+ ]);++ $response->assertSessionMissing('success-unescaped');+ }}