Added tests

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2024-07-24 20:13:15 +01:00
parent adf58a06da
commit ef145e47b4
2 changed files with 83 additions and 0 deletions

View file

@ -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());
}
}

View file

@ -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);
}
}