Skip to content

Commit

Permalink
Improve assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmoore committed Sep 16, 2024
1 parent b8b3f91 commit 4af893d
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
10 changes: 5 additions & 5 deletions tests/Feature/Accessories/Api/DeleteAccessoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCanDeleteAccessory()
->deleteJson(route('api.accessories.destroy', $accessory))
->assertStatusMessageIs('success');

$this->assertTrue($accessory->fresh()->trashed());
$this->assertSoftDeleted($accessory);
}

public function testCannotDeleteAccessoryThatHasCheckouts()
Expand All @@ -39,7 +39,7 @@ public function testCannotDeleteAccessoryThatHasCheckouts()
->deleteJson(route('api.accessories.destroy', $accessory))
->assertStatusMessageIs('error');

$this->assertFalse($accessory->fresh()->trashed());
$this->assertNotSoftDeleted($accessory);
}

public function testAdheresToMultipleFullCompanySupportScoping()
Expand Down Expand Up @@ -68,8 +68,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
->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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCanDeleteAssetMaintenance()
->deleteJson(route('api.maintenances.destroy', $assetMaintenance))
->assertStatusMessageIs('success');

$this->assertTrue($assetMaintenance->fresh()->trashed());
$this->assertSoftDeleted($assetMaintenance);
}

public function testAdheresToMultipleFullCompanySupportScoping()
Expand Down Expand Up @@ -61,8 +61,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
->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);
}
}
4 changes: 2 additions & 2 deletions tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCanDeleteAssetModel()
->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('success');

$this->assertTrue($assetModel->fresh()->trashed());
$this->assertSoftDeleted($assetModel);
}

public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
Expand All @@ -38,6 +38,6 @@ public function testCannotDeleteAssetModelThatStillHasAssociatedAssets()
->deleteJson(route('api.models.destroy', $assetModel))
->assertStatusMessageIs('error');

$this->assertFalse($assetModel->fresh()->trashed());
$this->assertNotSoftDeleted($assetModel);
}
}
8 changes: 4 additions & 4 deletions tests/Feature/Assets/Api/DeleteAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCanDeleteAsset()
->deleteJson(route('api.assets.destroy', $asset))
->assertStatusMessageIs('success');

$this->assertTrue($asset->fresh()->trashed());
$this->assertSoftDeleted($asset);
}

public function testCannotDeleteAssetThatIsCheckedOut()
Expand Down Expand Up @@ -62,8 +62,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
->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);
}
}
4 changes: 2 additions & 2 deletions tests/Feature/Categories/Api/DeleteCategoriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCanDeleteCategory()
->deleteJson(route('api.categories.destroy', $category))
->assertStatusMessageIs('success');

$this->assertTrue($category->fresh()->trashed());
$this->assertSoftDeleted($category);
}

public function testCannotDeleteCategoryThatStillHasAssociatedItems()
Expand All @@ -39,6 +39,6 @@ public function testCannotDeleteCategoryThatStillHasAssociatedItems()
->deleteJson(route('api.categories.destroy', $category))
->assertStatusMessageIs('error');

$this->assertFalse($category->fresh()->trashed());
$this->assertNotSoftDeleted($category);
}
}
6 changes: 6 additions & 0 deletions tests/Feature/Companies/Api/DeleteCompaniesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,11 @@ public function testCannotDeleteCompanyThatHasAssociatedItems()
$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]);
}
}
8 changes: 4 additions & 4 deletions tests/Feature/Components/Api/DeleteComponentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCanDeleteComponents()
->deleteJson(route('api.components.destroy', $component))
->assertStatusMessageIs('success');

$this->assertTrue($component->fresh()->trashed());
$this->assertSoftDeleted($component);
}

public function testAdheresToMultipleFullCompanySupportScoping()
Expand Down Expand Up @@ -57,8 +57,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
->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);
}
}
8 changes: 4 additions & 4 deletions tests/Feature/Consumables/Api/DeleteConsumablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCanDeleteConsumables()
->deleteJson(route('api.consumables.destroy', $consumable))
->assertStatusMessageIs('success');

$this->assertTrue($consumable->fresh()->trashed());
$this->assertSoftDeleted($consumable);
}

public function testAdheresToMultipleFullCompanySupportScoping()
Expand Down Expand Up @@ -57,8 +57,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
->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);
}
}

0 comments on commit 4af893d

Please sign in to comment.