A free open source IT asset/license management system
Added tests
snipeef145e47b45d
diff --git a/tests/Feature/Licenses/Ui/CreateLicenseTest.php b/tests/Feature/Licenses/Ui/CreateLicenseTest.phpnew file mode 100644index 0000000000..f24c3bd2ce--- /dev/null+++ b/tests/Feature/Licenses/Ui/CreateLicenseTest.php@@ -0,0 +1,42 @@+<?php++namespace Tests\Feature\Consumables\Ui;++use App\Models\AssetModel;+use App\Models\Category;+use App\Models\License;+use App\Models\Depreciation;+use App\Models\User;+use Tests\TestCase;++class CreateLicenseTest extends TestCase+{+ public function testPermissionRequiredToViewLicense()+ {+ $license = License::factory()->create();+ $this->actingAs(User::factory()->create())+ ->get(route('licenses.create', $license))+ ->assertForbidden();+ }++++ public function testLicenseWithoutPurchaseDateFailsValidation()+ {+ $response = $this->actingAs(User::factory()->superuser()->create())+ ->from(route('licenses.create'))+ ->post(route('licenses.store'), [+ 'name' => 'Test Invalid License',+ 'seats' => '10',+ 'category_id' => Category::factory()->forLicenses()->create()->id,+ 'depreciation_id' => Depreciation::factory()->create()->id+ ]);+ $response->assertStatus(302);+ $response->assertRedirect(route('licenses.create'));+ $response->assertInvalid(['purchase_date']);+ $response->assertSessionHasErrors(['purchase_date']);+ $this->followRedirects($response)->assertSee(trans('general.error'));+ $this->assertFalse(AssetModel::where('name', 'Test Invalid License')->exists());++ }+}diff --git a/tests/Feature/Licenses/Ui/LicenseViewTest.php b/tests/Feature/Licenses/Ui/LicenseViewTest.phpnew file mode 100644index 0000000000..295b23c5f0--- /dev/null+++ b/tests/Feature/Licenses/Ui/LicenseViewTest.php@@ -0,0 +1,41 @@+<?php++namespace Tests\Feature\Consumables\Ui;++use App\Models\License;+use App\Models\Depreciation;+use App\Models\User;+use Tests\TestCase;++class LicenseViewTest extends TestCase+{+ public function testPermissionRequiredToViewLicense()+ {+ $license = License::factory()->create();+ $this->actingAs(User::factory()->create())+ ->get(route('licenses.show', $license))+ ->assertForbidden();+ }+++ public function testLicenseWithNoPurchaseDateDoesNotTriggerDepreciation()+ {+ $depreciation = Depreciation::factory()->create(['months' => 12]);+ $license = License::factory()->create(['depreciation_id' => $depreciation->id, 'purchase_date' => null]);+ $this->actingAs(User::factory()->superuser()->create())+ ->get(route('licenses.show', $license))+ ->assertOk();+ }++ public function testLicenseWithPurchaseDateDepreciatesCorrectly()+ {+ $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);+ }+}