Skip to content

A free open source IT asset/license management system

Added tests

snipe6a1bb06c1365
diff --git a/tests/Feature/Assets/Api/AuditAssetTest.php b/tests/Feature/Assets/Api/AuditAssetTest.php
new file mode 100644
index 0000000000..f93a65ae6d
--- /dev/null
+++ b/tests/Feature/Assets/Api/AuditAssetTest.php
@@ -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);
+
+ }
+
+
+}
diff --git a/tests/Feature/Assets/Ui/AuditAssetTest.php b/tests/Feature/Assets/Ui/AuditAssetTest.php
new file mode 100644
index 0000000000..8b7f49ffc5
--- /dev/null
+++ b/tests/Feature/Assets/Ui/AuditAssetTest.php
@@ -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'));
+ }
+}