Skip to content

A free open source IT asset/license management system

Improve assertions

Marcus Moore4af893df6189
diff --git a/tests/Feature/Accessories/Api/DeleteAccessoriesTest.php b/tests/Feature/Accessories/Api/DeleteAccessoriesTest.php
index 6fa4a78160..f36e5fbedd 100644
--- a/tests/Feature/Accessories/Api/DeleteAccessoriesTest.php
+++ b/tests/Feature/Accessories/Api/DeleteAccessoriesTest.php
@@ -28,7 +28,7 @@ class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.accessories.destroy', $accessory))
->assertStatusMessageIs('success');
- $this->assertTrue($accessory->fresh()->trashed());
+ $this->assertSoftDeleted($accessory);
}
public function testCannotDeleteAccessoryThatHasCheckouts()
@@ -39,7 +39,7 @@ class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.accessories.destroy', $accessory))
->assertStatusMessageIs('error');
- $this->assertFalse($accessory->fresh()->trashed());
+ $this->assertNotSoftDeleted($accessory);
}
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -68,8 +68,8 @@ class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.accessories.destroy', $accessoryC))
->assertStatusMessageIs('success');
- $this->assertNull($accessoryA->fresh()->deleted_at, 'Accessory unexpectedly deleted');
- $this->assertNull($accessoryB->fresh()->deleted_at, 'Accessory unexpectedly deleted');
- $this->assertNotNull($accessoryC->fresh()->deleted_at, 'Accessory was not deleted');
+ $this->assertNotSoftDeleted($accessoryA);
+ $this->assertNotSoftDeleted($accessoryB);
+ $this->assertSoftDeleted($accessoryC);
}
}
diff --git a/tests/Feature/AssetMaintenances/Api/DeleteAssetMaintenancesTest.php b/tests/Feature/AssetMaintenances/Api/DeleteAssetMaintenancesTest.php
index 9532fdcf22..80c570646e 100644
--- a/tests/Feature/AssetMaintenances/Api/DeleteAssetMaintenancesTest.php
+++ b/tests/Feature/AssetMaintenances/Api/DeleteAssetMaintenancesTest.php
@@ -28,7 +28,7 @@ class DeleteAssetMaintenancesTest extends TestCase implements TestsMultipleFullC
->deleteJson(route('api.maintenances.destroy', $assetMaintenance))
->assertStatusMessageIs('success');
- $this->assertTrue($assetMaintenance->fresh()->trashed());
+ $this->assertSoftDeleted($assetMaintenance);
}
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -61,8 +61,8 @@ class DeleteAssetMaintenancesTest extends TestCase implements TestsMultipleFullC
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC))
->assertStatusMessageIs('success');
- $this->assertNull($assetMaintenanceA->fresh()->deleted_at, 'Asset Maintenance unexpectedly deleted');
- $this->assertNull($assetMaintenanceB->fresh()->deleted_at, 'Asset Maintenance unexpectedly deleted');
- $this->assertNotNull($assetMaintenanceC->fresh()->deleted_at, 'Asset Maintenance was not deleted');
+ $this->assertNotSoftDeleted($assetMaintenanceA);
+ $this->assertNotSoftDeleted($assetMaintenanceB);
+ $this->assertSoftDeleted($assetMaintenanceC);
}
}
diff --git a/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php b/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php
index 7bc18e95f2..8511d72d80 100644
--- a/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php
+++ b/tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php
@@ -27,7 +27,7 @@ class DeleteAssetModelsTest extends TestCase implements TestsPermissionsRequirem
->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('success');
- $this->assertTrue($assetModel->fresh()->trashed());
+ $this->assertSoftDeleted($assetModel);
}
public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
@@ -38,6 +38,6 @@ class DeleteAssetModelsTest extends TestCase implements TestsPermissionsRequirem
->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('error');
- $this->assertFalse($assetModel->fresh()->trashed());
+ $this->assertNotSoftDeleted($assetModel);
}
}
diff --git a/tests/Feature/Assets/Api/DeleteAssetsTest.php b/tests/Feature/Assets/Api/DeleteAssetsTest.php
index 3d34422b9d..fb1fc0cad0 100644
--- a/tests/Feature/Assets/Api/DeleteAssetsTest.php
+++ b/tests/Feature/Assets/Api/DeleteAssetsTest.php
@@ -28,7 +28,7 @@ class DeleteAssetsTest extends TestCase implements TestsMultipleFullCompanySuppo
->deleteJson(route('api.assets.destroy', $asset))
->assertStatusMessageIs('success');
- $this->assertTrue($asset->fresh()->trashed());
+ $this->assertSoftDeleted($asset);
}
public function testCannotDeleteAssetThatIsCheckedOut()
@@ -62,8 +62,8 @@ class DeleteAssetsTest extends TestCase implements TestsMultipleFullCompanySuppo
->deleteJson(route('api.assets.destroy', $assetC))
->assertStatusMessageIs('success');
- $this->assertNull($assetA->fresh()->deleted_at, 'Asset unexpectedly deleted');
- $this->assertNull($assetB->fresh()->deleted_at, 'Asset unexpectedly deleted');
- $this->assertNotNull($assetC->fresh()->deleted_at, 'Asset was not deleted');
+ $this->assertNotSoftDeleted($assetA);
+ $this->assertNotSoftDeleted($assetB);
+ $this->assertSoftDeleted($assetC);
}
}
diff --git a/tests/Feature/Categories/Api/DeleteCategoriesTest.php b/tests/Feature/Categories/Api/DeleteCategoriesTest.php
index 105f6f3948..e4a28b7b98 100644
--- a/tests/Feature/Categories/Api/DeleteCategoriesTest.php
+++ b/tests/Feature/Categories/Api/DeleteCategoriesTest.php
@@ -27,7 +27,7 @@ class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequireme
->deleteJson(route('api.categories.destroy', $category))
->assertStatusMessageIs('success');
- $this->assertTrue($category->fresh()->trashed());
+ $this->assertSoftDeleted($category);
}
public function testCannotDeleteCategoryThatStillHasAssociatedItems()
@@ -39,6 +39,6 @@ class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequireme
->deleteJson(route('api.categories.destroy', $category))
->assertStatusMessageIs('error');
- $this->assertFalse($category->fresh()->trashed());
+ $this->assertNotSoftDeleted($category);
}
}
diff --git a/tests/Feature/Companies/Api/DeleteCompaniesTest.php b/tests/Feature/Companies/Api/DeleteCompaniesTest.php
index 64421b47d4..868dd36ab2 100644
--- a/tests/Feature/Companies/Api/DeleteCompaniesTest.php
+++ b/tests/Feature/Companies/Api/DeleteCompaniesTest.php
@@ -44,5 +44,11 @@ class DeleteCompaniesTest extends TestCase implements TestsPermissionsRequiremen
$actor->deleteJson(route('api.companies.destroy', $companyWithConsumables))->assertStatusMessageIs('error');
$actor->deleteJson(route('api.companies.destroy', $companyWithComponents))->assertStatusMessageIs('error');
$actor->deleteJson(route('api.companies.destroy', $companyWithUsers))->assertStatusMessageIs('error');
+
+ $this->assertDatabaseHas('companies', ['id' => $companyWithAssets->id]);
+ $this->assertDatabaseHas('companies', ['id' => $companyWithAccessories->id]);
+ $this->assertDatabaseHas('companies', ['id' => $companyWithConsumables->id]);
+ $this->assertDatabaseHas('companies', ['id' => $companyWithComponents->id]);
+ $this->assertDatabaseHas('companies', ['id' => $companyWithUsers->id]);
}
}
diff --git a/tests/Feature/Components/Api/DeleteComponentsTest.php b/tests/Feature/Components/Api/DeleteComponentsTest.php
index 98f418449c..89bd8ffc8c 100644
--- a/tests/Feature/Components/Api/DeleteComponentsTest.php
+++ b/tests/Feature/Components/Api/DeleteComponentsTest.php
@@ -28,7 +28,7 @@ class DeleteComponentsTest extends TestCase implements TestsMultipleFullCompanyS
->deleteJson(route('api.components.destroy', $component))
->assertStatusMessageIs('success');
- $this->assertTrue($component->fresh()->trashed());
+ $this->assertSoftDeleted($component);
}
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -57,8 +57,8 @@ class DeleteComponentsTest extends TestCase implements TestsMultipleFullCompanyS
->deleteJson(route('api.components.destroy', $componentC))
->assertStatusMessageIs('success');
- $this->assertNull($componentA->fresh()->deleted_at, 'Component unexpectedly deleted');
- $this->assertNull($componentB->fresh()->deleted_at, 'Component unexpectedly deleted');
- $this->assertNotNull($componentC->fresh()->deleted_at, 'Component was not deleted');
+ $this->assertNotSoftDeleted($componentA);
+ $this->assertNotSoftDeleted($componentB);
+ $this->assertSoftDeleted($componentC);
}
}
diff --git a/tests/Feature/Consumables/Api/DeleteConsumablesTest.php b/tests/Feature/Consumables/Api/DeleteConsumablesTest.php
index 7a800ca500..72666a5d1a 100644
--- a/tests/Feature/Consumables/Api/DeleteConsumablesTest.php
+++ b/tests/Feature/Consumables/Api/DeleteConsumablesTest.php
@@ -28,7 +28,7 @@ class DeleteConsumablesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.consumables.destroy', $consumable))
->assertStatusMessageIs('success');
- $this->assertTrue($consumable->fresh()->trashed());
+ $this->assertSoftDeleted($consumable);
}
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -57,8 +57,8 @@ class DeleteConsumablesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.consumables.destroy', $consumableC))
->assertStatusMessageIs('success');
- $this->assertNull($consumableA->fresh()->deleted_at, 'Consumable unexpectedly deleted');
- $this->assertNull($consumableB->fresh()->deleted_at, 'Consumable unexpectedly deleted');
- $this->assertNotNull($consumableC->fresh()->deleted_at, 'Consumable was not deleted');
+ $this->assertNotSoftDeleted($consumableA);
+ $this->assertNotSoftDeleted($consumableB);
+ $this->assertSoftDeleted($consumableC);
}
}