Added tests
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
cfa8ddffc0
commit
6a1bb06c13
2 changed files with 113 additions and 0 deletions
78
tests/Feature/Assets/Api/AuditAssetTest.php
Normal file
78
tests/Feature/Assets/Api/AuditAssetTest.php
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Assets\Api;
|
||||||
|
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\AssetModel;
|
||||||
|
use App\Models\Company;
|
||||||
|
use App\Models\Location;
|
||||||
|
use App\Models\Statuslabel;
|
||||||
|
use App\Models\Supplier;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\CustomField;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AuditAssetTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testThatANonExistentAssetIdReturnsError()
|
||||||
|
{
|
||||||
|
$this->actingAsForApi(User::factory()->auditAssets()->create())
|
||||||
|
->postJson(route('api.asset.audit', 123456789))
|
||||||
|
->assertStatusMessageIs('error');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRequiresPermissionToAuditAsset()
|
||||||
|
{
|
||||||
|
$asset = Asset::factory()->create();
|
||||||
|
$this->actingAsForApi(User::factory()->create())
|
||||||
|
->postJson(route('api.asset.audit', $asset))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLegacyAssetAuditIsSaved()
|
||||||
|
{
|
||||||
|
$asset = Asset::factory()->create();
|
||||||
|
$this->actingAsForApi(User::factory()->auditAssets()->create())
|
||||||
|
->postJson(route('api.asset.audit.legacy'), [
|
||||||
|
'asset_tag' => $asset->asset_tag,
|
||||||
|
'note' => 'test',
|
||||||
|
])
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertJson(
|
||||||
|
[
|
||||||
|
'messages' =>trans('admin/hardware/message.audit.success'),
|
||||||
|
'payload' => [
|
||||||
|
'id' => $asset->id,
|
||||||
|
'asset_tag' => $asset->asset_tag,
|
||||||
|
'note' => 'test'
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testAssetAuditIsSaved()
|
||||||
|
{
|
||||||
|
$asset = Asset::factory()->create();
|
||||||
|
$this->actingAsForApi(User::factory()->auditAssets()->create())
|
||||||
|
->postJson(route('api.asset.audit', $asset), [
|
||||||
|
'note' => 'test'
|
||||||
|
])
|
||||||
|
->assertStatusMessageIs('success')
|
||||||
|
->assertJson(
|
||||||
|
[
|
||||||
|
'messages' =>trans('admin/hardware/message.audit.success'),
|
||||||
|
'payload' => [
|
||||||
|
'id' => $asset->id,
|
||||||
|
'asset_tag' => $asset->asset_tag,
|
||||||
|
'note' => 'test'
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertStatus(200);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
35
tests/Feature/Assets/Ui/AuditAssetTest.php
Normal file
35
tests/Feature/Assets/Ui/AuditAssetTest.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Assets\Ui;
|
||||||
|
|
||||||
|
use App\Models\Asset;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AuditAssetTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPermissionRequiredToCreateAssetModel()
|
||||||
|
{
|
||||||
|
$asset = Asset::factory()->create();
|
||||||
|
$this->actingAs(User::factory()->create())
|
||||||
|
->get(route('clone/hardware', $asset))
|
||||||
|
->assertForbidden();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPageCanBeAccessed(): void
|
||||||
|
{
|
||||||
|
$asset = Asset::factory()->create();
|
||||||
|
$response = $this->actingAs(User::factory()->auditAssets()->create())
|
||||||
|
->get(route('asset.audit.create', $asset));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAssetCanBeAudited()
|
||||||
|
{
|
||||||
|
$asset = Asset::factory()->create(['name'=>'Asset to clone']);
|
||||||
|
$this->actingAs(User::factory()->auditAssets()->create())
|
||||||
|
->post(route('asset.audit.store', $asset))
|
||||||
|
->assertStatus(302)
|
||||||
|
->assertRedirect(route('assets.audit.due'));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue