mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Added tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
adf58a06da
commit
ef145e47b4
42
tests/Feature/Licenses/Ui/CreateLicenseTest.php
Normal file
42
tests/Feature/Licenses/Ui/CreateLicenseTest.php
Normal 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());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
41
tests/Feature/Licenses/Ui/LicenseViewTest.php
Normal file
41
tests/Feature/Licenses/Ui/LicenseViewTest.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue