Skip to content

A free open source IT asset/license management system

Add failing test

Marcus Moore272385db6cce
diff --git a/tests/Feature/Assets/Ui/EditAssetTest.php b/tests/Feature/Assets/Ui/EditAssetTest.php
index a2645f7320..0fe29c6936 100644
--- a/tests/Feature/Assets/Ui/EditAssetTest.php
+++ b/tests/Feature/Assets/Ui/EditAssetTest.php
@@ -125,4 +125,32 @@ class EditAssetTest extends TestCase
$this->assertEquals($currentLocation->id, $asset->location_id);
}
+
+ public function test_handles_model_being_deleted()
+ {
+ $this->withoutExceptionHandling();
+
+ $newStatus = StatusLabel::factory()->create();
+
+ $asset = Asset::factory()->create();
+
+ $asset->model()->forceDelete();
+
+ $this->actingAs(User::factory()->viewAssets()->editAssets()->create())
+ ->from(route('hardware.edit', $asset))
+ ->put(route('hardware.update', $asset), [
+ 'redirect_option' => 'index',
+ 'purchase_date' => '2025-08-30',
+ 'name' => 'New name',
+ 'asset_tags' => 'New Asset Tag',
+ 'status_id' => $newStatus->id,
+ // triggers potential issue in AssetObserver's saving method
+ 'model_id' => AssetModel::factory()->create()->id,
+ ]);
+
+ $this->assertDatabaseHas('assets', [
+ 'id' => $asset->id,
+ 'status_id' => $newStatus->id,
+ ]);
+ }
}