A free open source IT asset/license management system
Added tests
snipe4382e01f5777
diff --git a/tests/Feature/Assets/Api/AuditAssetTest.php b/tests/Feature/Assets/Api/AuditAssetTest.phpindex 4ebbfc382b..d60e74630d 100644--- a/tests/Feature/Assets/Api/AuditAssetTest.php+++ b/tests/Feature/Assets/Api/AuditAssetTest.php@@ -162,4 +162,33 @@ class AuditAssetTest extends TestCase$asset->refresh();$this->assertNull($asset->next_audit_date);}++ public function test_asset_name_is_cleared_on_audit_when_clear_name_is_set()+ {+ $asset = Asset::factory()->create(['name' => 'My Asset Name']);++ $this->actingAsForApi(User::factory()->auditAssets()->create())+ ->postJson(route('api.asset.audit.legacy'), [+ 'asset_tag' => $asset->asset_tag,+ 'clear_name' => '1',+ ])+ ->assertStatusMessageIs('success')+ ->assertStatus(200);++ $this->assertNull($asset->refresh()->name);+ }++ public function test_asset_name_is_not_cleared_on_audit_when_clear_name_is_not_set()+ {+ $asset = Asset::factory()->create(['name' => 'My Asset Name']);++ $this->actingAsForApi(User::factory()->auditAssets()->create())+ ->postJson(route('api.asset.audit.legacy'), [+ 'asset_tag' => $asset->asset_tag,+ ])+ ->assertStatusMessageIs('success')+ ->assertStatus(200);++ $this->assertEquals('My Asset Name', $asset->refresh()->name);+ }}diff --git a/tests/Feature/Checkins/Api/AssetCheckinByTagTest.php b/tests/Feature/Checkins/Api/AssetCheckinByTagTest.phpnew file mode 100644index 0000000000..65c931a264--- /dev/null+++ b/tests/Feature/Checkins/Api/AssetCheckinByTagTest.php@@ -0,0 +1,66 @@+<?php++namespace Tests\Feature\Checkins\Api;++use App\Models\Asset;+use App\Models\User;+use Tests\TestCase;++class AssetCheckinByTagTest extends TestCase+{+ public function test_checking_in_asset_by_tag_requires_correct_permission()+ {+ $asset = Asset::factory()->assignedToUser()->create();++ $this->actingAsForApi(User::factory()->create())+ ->postJson(route('api.asset.checkinbytag'), ['asset_tag' => $asset->asset_tag])+ ->assertForbidden();+ }++ public function test_asset_can_be_checked_in_by_tag()+ {+ $asset = Asset::factory()->assignedToUser()->create();++ $this->actingAsForApi(User::factory()->checkinAssets()->create())+ ->postJson(route('api.asset.checkinbytag'), ['asset_tag' => $asset->asset_tag])+ ->assertOk()+ ->assertStatusMessageIs('success');++ $this->assertNull($asset->refresh()->assignedTo);+ }++ public function test_checkin_by_tag_returns_error_for_unknown_tag()+ {+ $this->actingAsForApi(User::factory()->checkinAssets()->create())+ ->postJson(route('api.asset.checkinbytag'), ['asset_tag' => 'DOES-NOT-EXIST'])+ ->assertOk()+ ->assertStatusMessageIs('error');+ }++ public function test_asset_name_is_cleared_on_checkin_by_tag_when_clear_name_is_set()+ {+ $asset = Asset::factory()->assignedToUser()->create(['name' => 'My Asset Name']);++ $this->actingAsForApi(User::factory()->checkinAssets()->create())+ ->postJson(route('api.asset.checkinbytag'), [+ 'asset_tag' => $asset->asset_tag,+ 'clear_name' => '1',+ ])+ ->assertOk()+ ->assertStatusMessageIs('success');++ $this->assertNull($asset->refresh()->name);+ }++ public function test_asset_name_is_not_cleared_on_checkin_by_tag_when_clear_name_is_not_set()+ {+ $asset = Asset::factory()->assignedToUser()->create(['name' => 'My Asset Name']);++ $this->actingAsForApi(User::factory()->checkinAssets()->create())+ ->postJson(route('api.asset.checkinbytag'), ['asset_tag' => $asset->asset_tag])+ ->assertOk()+ ->assertStatusMessageIs('success');++ $this->assertEquals('My Asset Name', $asset->refresh()->name);+ }+}diff --git a/tests/Feature/Checkins/Api/AssetCheckinTest.php b/tests/Feature/Checkins/Api/AssetCheckinTest.phpindex 5b6c87af47..cd061f5a61 100644--- a/tests/Feature/Checkins/Api/AssetCheckinTest.php+++ b/tests/Feature/Checkins/Api/AssetCheckinTest.php@@ -191,4 +191,28 @@ class AssetCheckinTest extends TestCase&& $event->note === 'hi there';}, 1);}++ public function test_asset_name_is_cleared_on_checkin_when_clear_name_is_set()+ {+ $asset = Asset::factory()->assignedToUser()->create(['name' => 'My Asset Name']);++ $this->actingAsForApi(User::factory()->checkinAssets()->create())+ ->postJson(route('api.asset.checkin', $asset), ['clear_name' => '1'])+ ->assertOk()+ ->assertStatusMessageIs('success');++ $this->assertNull($asset->refresh()->name);+ }++ public function test_asset_name_is_not_cleared_on_checkin_when_clear_name_is_not_set()+ {+ $asset = Asset::factory()->assignedToUser()->create(['name' => 'My Asset Name']);++ $this->actingAsForApi(User::factory()->checkinAssets()->create())+ ->postJson(route('api.asset.checkin', $asset))+ ->assertOk()+ ->assertStatusMessageIs('success');++ $this->assertEquals('My Asset Name', $asset->refresh()->name);+ }}