A free open source IT asset/license management system
Populate tests
Marcus Moorea026ca92ffd9
diff --git a/tests/Feature/Assets/Api/AuditAssetTest.php b/tests/Feature/Assets/Api/AuditAssetTest.phpindex b114cf8503..0437a9e6c1 100644--- a/tests/Feature/Assets/Api/AuditAssetTest.php+++ b/tests/Feature/Assets/Api/AuditAssetTest.php@@ -3,18 +3,18 @@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 testPermissionRequiredToBulkAuditAssets()+ {+ $this->actingAsForApi(User::factory()->create())+ ->postJson(route('api.asset.audit', Asset::factory()->create()))+ ->assertForbidden();+ }+public function testThatANonExistentAssetIdReturnsError(){$this->actingAsForApi(User::factory()->auditAssets()->create())@@ -33,9 +33,12 @@ class AuditAssetTest extends TestCasepublic function testLegacyAssetAuditIsSaved(){$asset = Asset::factory()->create();+ $future = now()->addMonths(5)->toDateString();+$this->actingAsForApi(User::factory()->auditAssets()->create())->postJson(route('api.asset.audit.legacy'), ['asset_tag' => $asset->asset_tag,+ 'next_audit_date' => $future,'note' => 'test',])->assertStatusMessageIs('success')@@ -50,8 +53,32 @@ class AuditAssetTest extends TestCase])->assertStatus(200);+ $asset->refresh();+ $this->assertEquals($future, $asset->next_audit_date);}+ /**+ * @link https://github.com/grokability/snipe-it/issues/18495+ */+ public function testAuditDoesNotSetNextAuditDateIfGivenNull()+ {+ $this->settings->setAuditInterval(null);++ $asset = Asset::factory()->create(['next_audit_date' => null]);++ $this->actingAsForApi(User::factory()->auditAssets()->create())+ ->postJson(route('api.asset.audit', $asset), [+ 'asset_tag' => $asset->asset_tag,+ // this is the important part+ 'next_audit_date' => null,+ 'note' => null,+ ])+ ->assertStatusMessageIs('success')+ ->assertStatus(200);++ $asset->refresh();+ $this->assertNull($asset->next_audit_date);+ }public function testAssetAuditIsSaved(){@@ -73,6 +100,4 @@ class AuditAssetTest extends TestCase->assertStatus(200);$this->assertHasTheseActionLogs($asset, ['create', 'audit']);}--}diff --git a/tests/Feature/Assets/Ui/BulkAuditAssetsTest.php b/tests/Feature/Assets/Ui/BulkAuditAssetsTest.phpindex 8e8df1ad69..c3ae295a89 100644--- a/tests/Feature/Assets/Ui/BulkAuditAssetsTest.php+++ b/tests/Feature/Assets/Ui/BulkAuditAssetsTest.php@@ -2,30 +2,52 @@namespace Tests\Feature\Assets\Ui;+use App\Models\User;+use Carbon\Carbon;use Tests\TestCase;class BulkAuditAssetsTest extends TestCase{+ private User $actor;++ protected function setUp(): void+ {+ parent::setUp();++ $this->actor = User::factory()->auditAssets()->create();+ }+public function test_permission_required_to_view_page(){- $this->markTestIncomplete();+ $this->actingAs(User::factory()->create())+ ->get(route('assets.bulkaudit'))+ ->assertStatus(403);}- public function test_permission_required_to_bulk_audit_assets()+ public function test_can_view_audit_page(){- $this->markTestIncomplete();+ $this->actingAs($this->actor)+ ->get(route('assets.bulkaudit'))+ ->assertViewIs('hardware.quickscan');}- public function test_can_bulk_audit_assets()+ public function test_audit_page_is_given_todays_date_when_audit_interval_is_null(){- $this->markTestIncomplete();+ $this->settings->setAuditInterval(null);++ $this->actingAs($this->actor)+ ->get(route('assets.bulkaudit'))+ ->assertViewIs('hardware.quickscan')+ ->assertViewHas('next_audit_date', Carbon::now()->toDateString());}- /**- * @link https://github.com/grokability/snipe-it/issues/18495- */- public function test_next_audit_date_is_correctly_updated()+ public function test_audit_page_is_given_correct_date_when_audit_interval_is_set(){- $this->markTestIncomplete();+ $this->settings->setAuditInterval(5);++ $this->actingAs($this->actor)+ ->get(route('assets.bulkaudit'))+ ->assertViewIs('hardware.quickscan')+ ->assertViewHas('next_audit_date', Carbon::now()->addMonths(5)->toDateString());}}diff --git a/tests/Support/Settings.php b/tests/Support/Settings.phpindex f675c5438a..181199a3f2 100644--- a/tests/Support/Settings.php+++ b/tests/Support/Settings.php@@ -38,6 +38,14 @@ class Settings'audit_warning_days' => $days,]);}++ public function setAuditInterval(?int $months): Settings+ {+ return $this->update([+ 'audit_interval' => $months,+ ]);+ }+public function disableAlertEmail(): Settings{return $this->update([