A free open source IT asset/license management system
Updated tests
snipea6c6c7eae990
diff --git a/tests/Feature/Maintenances/Api/CreateMaintenanceTest.php b/tests/Feature/Maintenances/Api/CreateMaintenanceTest.phpindex f2872e9e41..11fb93d0db 100644--- a/tests/Feature/Maintenances/Api/CreateMaintenanceTest.php+++ b/tests/Feature/Maintenances/Api/CreateMaintenanceTest.php@@ -48,10 +48,10 @@ class CreateMaintenanceTest extends TestCase->assertStatus(200);// Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database- $assetMaintenance = Maintenance::where('title', 'Test Maintenance')->first();+ $maintenance = Maintenance::where('title', 'Test Maintenance')->first();// Assert file was stored...- Storage::disk('public')->assertExists(app('maintenances_path').$assetMaintenance->image);+ Storage::disk('public')->assertExists(app('maintenances_path').$maintenance->image);$this->assertDatabaseHas('asset_maintenances', ['asset_id' => $asset->id,@@ -62,7 +62,7 @@ class CreateMaintenanceTest extends TestCase'start_date' => '2021-01-01','completion_date' => '2021-01-10','notes' => 'A note',- 'image' => $assetMaintenance->image,+ 'image' => $maintenance->image,'created_by' => $actor->id,]);}diff --git a/tests/Feature/Maintenances/Api/DeleteMaintenancesTest.php b/tests/Feature/Maintenances/Api/DeleteMaintenancesTest.phpindex b8f34e3c63..eac8c25ba7 100644--- a/tests/Feature/Maintenances/Api/DeleteMaintenancesTest.php+++ b/tests/Feature/Maintenances/Api/DeleteMaintenancesTest.php@@ -13,26 +13,26 @@ class DeleteMaintenancesTest extends TestCase implements TestsFullMultipleCompan{public function testRequiresPermission(){- $assetMaintenance = Maintenance::factory()->create();+ $maintenance = Maintenance::factory()->create();$this->actingAsForApi(User::factory()->create())- ->deleteJson(route('api.maintenances.destroy', $assetMaintenance))+ ->deleteJson(route('api.maintenances.destroy', $maintenance))->assertForbidden();- $this->assertNotSoftDeleted($assetMaintenance);+ $this->assertNotSoftDeleted($maintenance);}public function testAdheresToFullMultipleCompaniesSupportScoping(){[$companyA, $companyB] = Company::factory()->count(2)->create();- $assetMaintenanceA = Maintenance::factory()->create();- $assetMaintenanceB = Maintenance::factory()->create();- $assetMaintenanceC = Maintenance::factory()->create();+ $maintenanceA = Maintenance::factory()->create();+ $maintenanceB = Maintenance::factory()->create();+ $maintenanceC = Maintenance::factory()->create();- $assetMaintenanceA->asset->update(['company_id' => $companyA->id]);- $assetMaintenanceB->asset->update(['company_id' => $companyB->id]);- $assetMaintenanceC->asset->update(['company_id' => $companyB->id]);+ $maintenanceA->asset->update(['company_id' => $companyA->id]);+ $maintenanceB->asset->update(['company_id' => $companyB->id]);+ $maintenanceC->asset->update(['company_id' => $companyB->id]);$superUser = $companyA->users()->save(User::factory()->superuser()->make());$userInCompanyA = $companyA->users()->save(User::factory()->editAssets()->make());@@ -41,30 +41,30 @@ class DeleteMaintenancesTest extends TestCase implements TestsFullMultipleCompan$this->settings->enableMultipleFullCompanySupport();$this->actingAsForApi($userInCompanyA)- ->deleteJson(route('api.maintenances.destroy', $assetMaintenanceB))+ ->deleteJson(route('api.maintenances.destroy', $maintenanceB))->assertStatusMessageIs('error');$this->actingAsForApi($userInCompanyB)- ->deleteJson(route('api.maintenances.destroy', $assetMaintenanceA))+ ->deleteJson(route('api.maintenances.destroy', $maintenanceA))->assertStatusMessageIs('error');$this->actingAsForApi($superUser)- ->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC))+ ->deleteJson(route('api.maintenances.destroy', $maintenanceC))->assertStatusMessageIs('success');- $this->assertNotSoftDeleted($assetMaintenanceA);- $this->assertNotSoftDeleted($assetMaintenanceB);- $this->assertSoftDeleted($assetMaintenanceC);+ $this->assertNotSoftDeleted($maintenanceA);+ $this->assertNotSoftDeleted($maintenanceB);+ $this->assertSoftDeleted($maintenanceC);}public function testCanDeleteMaintenance(){- $assetMaintenance = Maintenance::factory()->create();+ $maintenance = Maintenance::factory()->create();$this->actingAsForApi(User::factory()->editAssets()->create())- ->deleteJson(route('api.maintenances.destroy', $assetMaintenance))+ ->deleteJson(route('api.maintenances.destroy', $maintenance))->assertStatusMessageIs('success');- $this->assertSoftDeleted($assetMaintenance);+ $this->assertSoftDeleted($maintenance);}}diff --git a/tests/Feature/Maintenances/Api/EditMaintenanceTest.php b/tests/Feature/Maintenances/Api/EditMaintenanceTest.phpindex 4aec56efa7..d4ba8c3e0f 100644--- a/tests/Feature/Maintenances/Api/EditMaintenanceTest.php+++ b/tests/Feature/Maintenances/Api/EditMaintenanceTest.php@@ -24,7 +24,6 @@ class EditMaintenanceTest extends TestCase{Storage::fake('public');$actor = User::factory()->superuser()->create();- $asset = Asset::factory()->create();$supplier = Supplier::factory()->create();$maintenance = Maintenance::factory()->create();diff --git a/tests/Feature/Maintenances/Ui/CreateMaintenanceTest.php b/tests/Feature/Maintenances/Ui/CreateMaintenanceTest.phpindex 03f618ac8c..52ff3d34e6 100644--- a/tests/Feature/Maintenances/Ui/CreateMaintenanceTest.php+++ b/tests/Feature/Maintenances/Ui/CreateMaintenanceTest.php@@ -45,10 +45,10 @@ class CreateMaintenanceTest extends TestCase->assertOk();// Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database- $assetMaintenance = Maintenance::where('title', 'Test Maintenance')->first();+ $maintenance = Maintenance::where('name', 'Test Maintenance')->first();// Assert file was stored...- Storage::disk('public')->assertExists(app('maintenances_path').$assetMaintenance->image);+ Storage::disk('public')->assertExists(app('maintenances_path').$maintenance->image);$this->assertDatabaseHas('asset_maintenances', [@@ -62,7 +62,7 @@ class CreateMaintenanceTest extends TestCase'asset_maintenance_time' => '9','notes' => 'A note','cost' => '100.00',- 'image' => $assetMaintenance->image,+ 'image' => $maintenance->image,'created_by' => $actor->id,]);}diff --git a/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php b/tests/Feature/Maintenances/Ui/EditMaintenanceTest.phpindex 9b18ad629b..e5ebec889f 100644--- a/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php+++ b/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php@@ -23,12 +23,12 @@ class EditMaintenanceTest extends TestCase{$actor = User::factory()->superuser()->create();$asset = Asset::factory()->create();- $assetMaintenance = Maintenance::factory()->create(['asset_id' => $asset]);+ $maintenance = Maintenance::factory()->create(['asset_id' => $asset]);$supplier = Supplier::factory()->create();$this->actingAs($actor)->followingRedirects()- ->put(route('maintenances.update', $assetMaintenance), [+ ->put(route('maintenances.update', $maintenance), ['name' => 'Test Maintenance','asset_id' => $asset->id,'supplier_id' => $supplier->id,@@ -43,10 +43,10 @@ class EditMaintenanceTest extends TestCase->assertOk();// Since we rename the file in the ImageUploadRequest, we have to fetch the record from the database- $assetMaintenance = Maintenance::where('title', 'Test Maintenance')->first();+ $maintenance = Maintenance::where('name', 'Test Maintenance')->first();// Assert file was stored...- Storage::disk('public')->assertExists(app('maintenances_path').$assetMaintenance->image);+ Storage::disk('public')->assertExists(app('maintenances_path').$maintenance->image);$this->assertDatabaseHas('asset_maintenances', ['asset_id' => $asset->id,diff --git a/tests/Feature/Redirects/ModelNotFoundRedirectTest.php b/tests/Feature/Redirects/ModelNotFoundRedirectTest.phpindex 26401e9607..59180cbdb0 100644--- a/tests/Feature/Redirects/ModelNotFoundRedirectTest.php+++ b/tests/Feature/Redirects/ModelNotFoundRedirectTest.php@@ -14,7 +14,7 @@ class ModelNotFoundRedirectTest extends TestCase->assertRedirectToRoute('hardware.index');}- public function testHandlesAssetMaintenance404()+ public function testHandlesMaintenance404(){$this->actingAs(User::factory()->viewAssets()->create())->get(route('maintenances.show', 9999))diff --git a/tests/Feature/Suppliers/Api/DeleteSuppliersTest.php b/tests/Feature/Suppliers/Api/DeleteSuppliersTest.phpindex 7da8197bde..9bdc13ca8c 100644--- a/tests/Feature/Suppliers/Api/DeleteSuppliersTest.php+++ b/tests/Feature/Suppliers/Api/DeleteSuppliersTest.php@@ -2,7 +2,7 @@namespace Tests\Feature\Suppliers\Api;-use App\Models\AssetMaintenance;+use App\Models\Maintenance;use App\Models\Supplier;use App\Models\User;use Tests\Concerns\TestsPermissionsRequirement;@@ -24,17 +24,17 @@ class DeleteSuppliersTest extends TestCase implements TestsPermissionsRequiremenpublic function testCannotDeleteSupplierWithDataStillAssociated(){$supplierWithAsset = Supplier::factory()->hasAssets()->create();- $supplierWithAssetMaintenance = Supplier::factory()->has(AssetMaintenance::factory(), 'asset_maintenances')->create();+ $supplierWithMaintenance = Supplier::factory()->has(Maintenance::factory(), 'maintenances')->create();$supplierWithLicense = Supplier::factory()->hasLicenses()->create();$actor = $this->actingAsForApi(User::factory()->deleteSuppliers()->create());$actor->deleteJson(route('api.suppliers.destroy', $supplierWithAsset))->assertStatusMessageIs('error');- $actor->deleteJson(route('api.suppliers.destroy', $supplierWithAssetMaintenance))->assertStatusMessageIs('error');+ $actor->deleteJson(route('api.suppliers.destroy', $supplierWithMaintenance))->assertStatusMessageIs('error');$actor->deleteJson(route('api.suppliers.destroy', $supplierWithLicense))->assertStatusMessageIs('error');$this->assertNotSoftDeleted($supplierWithAsset);- $this->assertNotSoftDeleted($supplierWithAssetMaintenance);+ $this->assertNotSoftDeleted($supplierWithMaintenance);$this->assertNotSoftDeleted($supplierWithLicense);}diff --git a/tests/Unit/CompanyScopingTest.php b/tests/Unit/CompanyScopingTest.phpindex ff55e83056..f1a6daaf0c 100644--- a/tests/Unit/CompanyScopingTest.php+++ b/tests/Unit/CompanyScopingTest.php@@ -5,7 +5,7 @@ namespace Tests\Unit;use PHPUnit\Framework\Attributes\DataProvider;use App\Models\Accessory;use App\Models\Asset;-use App\Models\AssetMaintenance;+use App\Models\Maintenance;use App\Models\Company;use App\Models\Component;use App\Models\Consumable;@@ -69,12 +69,12 @@ class CompanyScopingTest extends TestCase$this->assertCanSee($modelB);}- public function testAssetMaintenanceCompanyScoping()+ public function testMaintenanceCompanyScoping(){[$companyA, $companyB] = Company::factory()->count(2)->create();- $assetMaintenanceForCompanyA = AssetMaintenance::factory()->for(Asset::factory()->for($companyA))->create();- $assetMaintenanceForCompanyB = AssetMaintenance::factory()->for(Asset::factory()->for($companyB))->create();+ $maintenanceForCompanyA = Maintenance::factory()->for(Asset::factory()->for($companyA))->create();+ $maintenanceForCompanyB = Maintenance::factory()->for(Asset::factory()->for($companyB))->create();$superUser = $companyA->users()->save(User::factory()->superuser()->make());$userInCompanyA = $companyA->users()->save(User::factory()->make());@@ -83,30 +83,30 @@ class CompanyScopingTest extends TestCase$this->settings->disableMultipleFullCompanySupport();$this->actingAs($superUser);- $this->assertCanSee($assetMaintenanceForCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyB);+ $this->assertCanSee($maintenanceForCompanyA);+ $this->assertCanSee($maintenanceForCompanyB);$this->actingAs($userInCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyB);+ $this->assertCanSee($maintenanceForCompanyA);+ $this->assertCanSee($maintenanceForCompanyB);$this->actingAs($userInCompanyB);- $this->assertCanSee($assetMaintenanceForCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyB);+ $this->assertCanSee($maintenanceForCompanyA);+ $this->assertCanSee($maintenanceForCompanyB);$this->settings->enableMultipleFullCompanySupport();$this->actingAs($superUser);- $this->assertCanSee($assetMaintenanceForCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyB);+ $this->assertCanSee($maintenanceForCompanyA);+ $this->assertCanSee($maintenanceForCompanyB);$this->actingAs($userInCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyA);- $this->assertCannotSee($assetMaintenanceForCompanyB);+ $this->assertCanSee($maintenanceForCompanyA);+ $this->assertCannotSee($maintenanceForCompanyB);$this->actingAs($userInCompanyB);- $this->assertCannotSee($assetMaintenanceForCompanyA);- $this->assertCanSee($assetMaintenanceForCompanyB);+ $this->assertCannotSee($maintenanceForCompanyA);+ $this->assertCanSee($maintenanceForCompanyB);}public function testLicenseSeatCompanyScoping()