Improve assertions

This commit is contained in:
Marcus Moore 2024-09-16 14:20:24 -07:00
parent b8b3f91ce4
commit 4af893df61
No known key found for this signature in database
8 changed files with 31 additions and 25 deletions

View file

@ -28,7 +28,7 @@ class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.accessories.destroy', $accessory)) ->deleteJson(route('api.accessories.destroy', $accessory))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($accessory->fresh()->trashed()); $this->assertSoftDeleted($accessory);
} }
public function testCannotDeleteAccessoryThatHasCheckouts() public function testCannotDeleteAccessoryThatHasCheckouts()
@ -39,7 +39,7 @@ class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.accessories.destroy', $accessory)) ->deleteJson(route('api.accessories.destroy', $accessory))
->assertStatusMessageIs('error'); ->assertStatusMessageIs('error');
$this->assertFalse($accessory->fresh()->trashed()); $this->assertNotSoftDeleted($accessory);
} }
public function testAdheresToMultipleFullCompanySupportScoping() public function testAdheresToMultipleFullCompanySupportScoping()
@ -68,8 +68,8 @@ class DeleteAccessoriesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.accessories.destroy', $accessoryC)) ->deleteJson(route('api.accessories.destroy', $accessoryC))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertNull($accessoryA->fresh()->deleted_at, 'Accessory unexpectedly deleted'); $this->assertNotSoftDeleted($accessoryA);
$this->assertNull($accessoryB->fresh()->deleted_at, 'Accessory unexpectedly deleted'); $this->assertNotSoftDeleted($accessoryB);
$this->assertNotNull($accessoryC->fresh()->deleted_at, 'Accessory was not deleted'); $this->assertSoftDeleted($accessoryC);
} }
} }

View file

@ -28,7 +28,7 @@ class DeleteAssetMaintenancesTest extends TestCase implements TestsMultipleFullC
->deleteJson(route('api.maintenances.destroy', $assetMaintenance)) ->deleteJson(route('api.maintenances.destroy', $assetMaintenance))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($assetMaintenance->fresh()->trashed()); $this->assertSoftDeleted($assetMaintenance);
} }
public function testAdheresToMultipleFullCompanySupportScoping() public function testAdheresToMultipleFullCompanySupportScoping()
@ -61,8 +61,8 @@ class DeleteAssetMaintenancesTest extends TestCase implements TestsMultipleFullC
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC)) ->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertNull($assetMaintenanceA->fresh()->deleted_at, 'Asset Maintenance unexpectedly deleted'); $this->assertNotSoftDeleted($assetMaintenanceA);
$this->assertNull($assetMaintenanceB->fresh()->deleted_at, 'Asset Maintenance unexpectedly deleted'); $this->assertNotSoftDeleted($assetMaintenanceB);
$this->assertNotNull($assetMaintenanceC->fresh()->deleted_at, 'Asset Maintenance was not deleted'); $this->assertSoftDeleted($assetMaintenanceC);
} }
} }

View file

@ -27,7 +27,7 @@ class DeleteAssetModelsTest extends TestCase implements TestsPermissionsRequirem
->deleteJson(route('api.models.destroy', $assetModel)) ->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($assetModel->fresh()->trashed()); $this->assertSoftDeleted($assetModel);
} }
public function testCannotDeleteAssetModelThatStillHasAssociatedAssets() public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
@ -38,6 +38,6 @@ class DeleteAssetModelsTest extends TestCase implements TestsPermissionsRequirem
->deleteJson(route('api.models.destroy', $assetModel)) ->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('error'); ->assertStatusMessageIs('error');
$this->assertFalse($assetModel->fresh()->trashed()); $this->assertNotSoftDeleted($assetModel);
} }
} }

View file

@ -28,7 +28,7 @@ class DeleteAssetsTest extends TestCase implements TestsMultipleFullCompanySuppo
->deleteJson(route('api.assets.destroy', $asset)) ->deleteJson(route('api.assets.destroy', $asset))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($asset->fresh()->trashed()); $this->assertSoftDeleted($asset);
} }
public function testCannotDeleteAssetThatIsCheckedOut() public function testCannotDeleteAssetThatIsCheckedOut()
@ -62,8 +62,8 @@ class DeleteAssetsTest extends TestCase implements TestsMultipleFullCompanySuppo
->deleteJson(route('api.assets.destroy', $assetC)) ->deleteJson(route('api.assets.destroy', $assetC))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertNull($assetA->fresh()->deleted_at, 'Asset unexpectedly deleted'); $this->assertNotSoftDeleted($assetA);
$this->assertNull($assetB->fresh()->deleted_at, 'Asset unexpectedly deleted'); $this->assertNotSoftDeleted($assetB);
$this->assertNotNull($assetC->fresh()->deleted_at, 'Asset was not deleted'); $this->assertSoftDeleted($assetC);
} }
} }

View file

@ -27,7 +27,7 @@ class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequireme
->deleteJson(route('api.categories.destroy', $category)) ->deleteJson(route('api.categories.destroy', $category))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($category->fresh()->trashed()); $this->assertSoftDeleted($category);
} }
public function testCannotDeleteCategoryThatStillHasAssociatedItems() public function testCannotDeleteCategoryThatStillHasAssociatedItems()
@ -39,6 +39,6 @@ class DeleteCategoriesTest extends TestCase implements TestsPermissionsRequireme
->deleteJson(route('api.categories.destroy', $category)) ->deleteJson(route('api.categories.destroy', $category))
->assertStatusMessageIs('error'); ->assertStatusMessageIs('error');
$this->assertFalse($category->fresh()->trashed()); $this->assertNotSoftDeleted($category);
} }
} }

View file

@ -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', $companyWithConsumables))->assertStatusMessageIs('error');
$actor->deleteJson(route('api.companies.destroy', $companyWithComponents))->assertStatusMessageIs('error'); $actor->deleteJson(route('api.companies.destroy', $companyWithComponents))->assertStatusMessageIs('error');
$actor->deleteJson(route('api.companies.destroy', $companyWithUsers))->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]);
} }
} }

View file

@ -28,7 +28,7 @@ class DeleteComponentsTest extends TestCase implements TestsMultipleFullCompanyS
->deleteJson(route('api.components.destroy', $component)) ->deleteJson(route('api.components.destroy', $component))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($component->fresh()->trashed()); $this->assertSoftDeleted($component);
} }
public function testAdheresToMultipleFullCompanySupportScoping() public function testAdheresToMultipleFullCompanySupportScoping()
@ -57,8 +57,8 @@ class DeleteComponentsTest extends TestCase implements TestsMultipleFullCompanyS
->deleteJson(route('api.components.destroy', $componentC)) ->deleteJson(route('api.components.destroy', $componentC))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertNull($componentA->fresh()->deleted_at, 'Component unexpectedly deleted'); $this->assertNotSoftDeleted($componentA);
$this->assertNull($componentB->fresh()->deleted_at, 'Component unexpectedly deleted'); $this->assertNotSoftDeleted($componentB);
$this->assertNotNull($componentC->fresh()->deleted_at, 'Component was not deleted'); $this->assertSoftDeleted($componentC);
} }
} }

View file

@ -28,7 +28,7 @@ class DeleteConsumablesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.consumables.destroy', $consumable)) ->deleteJson(route('api.consumables.destroy', $consumable))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertTrue($consumable->fresh()->trashed()); $this->assertSoftDeleted($consumable);
} }
public function testAdheresToMultipleFullCompanySupportScoping() public function testAdheresToMultipleFullCompanySupportScoping()
@ -57,8 +57,8 @@ class DeleteConsumablesTest extends TestCase implements TestsMultipleFullCompany
->deleteJson(route('api.consumables.destroy', $consumableC)) ->deleteJson(route('api.consumables.destroy', $consumableC))
->assertStatusMessageIs('success'); ->assertStatusMessageIs('success');
$this->assertNull($consumableA->fresh()->deleted_at, 'Consumable unexpectedly deleted'); $this->assertNotSoftDeleted($consumableA);
$this->assertNull($consumableB->fresh()->deleted_at, 'Consumable unexpectedly deleted'); $this->assertNotSoftDeleted($consumableB);
$this->assertNotNull($consumableC->fresh()->deleted_at, 'Consumable was not deleted'); $this->assertSoftDeleted($consumableC);
} }
} }