A free open source IT asset/license management system
Added tests
snipe5d7123eb0591
diff --git a/tests/Feature/Licenses/Ui/LicenseViewTest.php b/tests/Feature/Licenses/Ui/LicenseViewTest.phpindex 199afde4d1..5cae33239b 100644--- a/tests/Feature/Licenses/Ui/LicenseViewTest.php+++ b/tests/Feature/Licenses/Ui/LicenseViewTest.php@@ -5,6 +5,7 @@ namespace Tests\Feature\Licenses\Ui;use App\Models\Depreciation;use App\Models\License;use App\Models\User;+use Carbon\Carbon;use Tests\TestCase;class LicenseViewTest extends TestCase@@ -26,13 +27,24 @@ class LicenseViewTest extends TestCasepublic function test_license_with_purchase_date_depreciates_correctly(){- $depreciation = Depreciation::factory()->create(['months' => 12]);- $license = License::factory()->create(['depreciation_id' => $depreciation->id, 'purchase_date' => '2020-01-01']);- $this->actingAs(User::factory()->superuser()->create())- ->get(route('licenses.show', $license))- ->assertOk()- ->assertSee([- '2021-01-01',- ], false);+ Carbon::setTestNow(Carbon::create(2021, 1, 1, 0, 0, 0));++ try {+ $depreciation = Depreciation::factory()->create(['months' => 24]);+ $license = License::factory()->create([+ 'depreciation_id' => $depreciation->id,+ 'purchase_date' => '2020-01-01',+ ]);++ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('licenses.show', $license))+ ->assertOk()+ ->assertSee([+ '2022-01-01',+ '(50%)',+ ], false);+ } finally {+ Carbon::setTestNow();+ }}}diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.phpindex ff792c337d..1973aec01b 100644--- a/tests/Unit/AssetTest.php+++ b/tests/Unit/AssetTest.php@@ -9,6 +9,7 @@ use App\Models\Asset;use App\Models\AssetModel;use App\Models\Category;use App\Models\Component;+use App\Models\Depreciation;use App\Models\Setting;use App\Models\Statuslabel;use App\Models\User;@@ -195,6 +196,55 @@ class AssetTest extends TestCase}+ public function test_eol_progress_percent_returns_expected_value(): void+ {+ Carbon::setTestNow(Carbon::create(2026, 1, 1, 0, 0, 0));++ try {+ $asset = Asset::factory()->create([+ 'purchase_date' => '2025-01-01',+ 'eol_explicit' => 1,+ ]);++ $asset->asset_eol_date = '2027-01-01';+ $asset->save();+ $asset->refresh();++ $this->assertSame(50.0, $asset->eolProgressPercent());+ } finally {+ Carbon::setTestNow();+ }+ }++ public function test_depreciation_progress_percent_returns_expected_value(): void+ {+ Carbon::setTestNow(Carbon::create(2026, 1, 1, 0, 0, 0));++ try {+ $depreciation = Depreciation::factory()->create(['months' => 24]);+ $model = AssetModel::factory()->create(['depreciation_id' => $depreciation->id]);++ $asset = Asset::factory()->create([+ 'model_id' => $model->id,+ 'purchase_date' => '2025-01-01',+ ]);++ $this->assertSame(50.0, $asset->depreciationProgressPercent());+ } finally {+ Carbon::setTestNow();+ }+ }++ public function test_warranty_progress_percent_returns_zero_without_required_dates(): void+ {+ $asset = Asset::factory()->create([+ 'purchase_date' => null,+ 'warranty_months' => 24,+ ]);++ $this->assertSame(0.0, $asset->warrantyProgressPercent());+ }+public function test_assigned_type_without_assign_to(){$user = User::factory()->create();diff --git a/tests/Unit/Models/LicenseTest.php b/tests/Unit/Models/LicenseTest.phpindex 08db3e33e4..92678e0f52 100644--- a/tests/Unit/Models/LicenseTest.php+++ b/tests/Unit/Models/LicenseTest.php@@ -5,6 +5,7 @@ namespace Tests\Unit\Models;use App\Enums\ActionType;use App\Models\License;use App\Models\User;+use Carbon\Carbon;use Tests\TestCase;class LicenseTest extends TestCase@@ -100,4 +101,40 @@ class LicenseTest extends TestCase$license->remaining = 99;$this->assertEquals(100.0, $license->percentRemaining());}++ public function test_depreciation_progress_percent_is_available_for_license(): void+ {+ Carbon::setTestNow(Carbon::create(2026, 1, 1, 0, 0, 0));++ try {+ $license = new class extends License+ {+ public function depreciated_date()+ {+ return date_create('2027-01-01');+ }+ };++ $license->purchase_date = '2025-01-01';++ $this->assertSame(50.0, $license->depreciationProgressPercent());+ } finally {+ Carbon::setTestNow();+ }+ }++ public function test_depreciation_progress_percent_returns_zero_when_dates_are_missing(): void+ {+ $license = new class extends License+ {+ public function depreciated_date()+ {+ return null;+ }+ };++ $license->purchase_date = null;++ $this->assertSame(0.0, $license->depreciationProgressPercent());+ }}