Skip to content

Commit 4af893d

Browse files
committed
Improve assertions
1 parent b8b3f91 commit 4af893d

File tree

8 files changed

+31
-25
lines changed

8 files changed

+31
-25
lines changed

tests/Feature/Accessories/Api/DeleteAccessoriesTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCanDeleteAccessory()
2828
->deleteJson(route('api.accessories.destroy', $accessory))
2929
->assertStatusMessageIs('success');
3030

31-
$this->assertTrue($accessory->fresh()->trashed());
31+
$this->assertSoftDeleted($accessory);
3232
}
3333

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

42-
$this->assertFalse($accessory->fresh()->trashed());
42+
$this->assertNotSoftDeleted($accessory);
4343
}
4444

4545
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -68,8 +68,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
6868
->deleteJson(route('api.accessories.destroy', $accessoryC))
6969
->assertStatusMessageIs('success');
7070

71-
$this->assertNull($accessoryA->fresh()->deleted_at, 'Accessory unexpectedly deleted');
72-
$this->assertNull($accessoryB->fresh()->deleted_at, 'Accessory unexpectedly deleted');
73-
$this->assertNotNull($accessoryC->fresh()->deleted_at, 'Accessory was not deleted');
71+
$this->assertNotSoftDeleted($accessoryA);
72+
$this->assertNotSoftDeleted($accessoryB);
73+
$this->assertSoftDeleted($accessoryC);
7474
}
7575
}

tests/Feature/AssetMaintenances/Api/DeleteAssetMaintenancesTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCanDeleteAssetMaintenance()
2828
->deleteJson(route('api.maintenances.destroy', $assetMaintenance))
2929
->assertStatusMessageIs('success');
3030

31-
$this->assertTrue($assetMaintenance->fresh()->trashed());
31+
$this->assertSoftDeleted($assetMaintenance);
3232
}
3333

3434
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -61,8 +61,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
6161
->deleteJson(route('api.maintenances.destroy', $assetMaintenanceC))
6262
->assertStatusMessageIs('success');
6363

64-
$this->assertNull($assetMaintenanceA->fresh()->deleted_at, 'Asset Maintenance unexpectedly deleted');
65-
$this->assertNull($assetMaintenanceB->fresh()->deleted_at, 'Asset Maintenance unexpectedly deleted');
66-
$this->assertNotNull($assetMaintenanceC->fresh()->deleted_at, 'Asset Maintenance was not deleted');
64+
$this->assertNotSoftDeleted($assetMaintenanceA);
65+
$this->assertNotSoftDeleted($assetMaintenanceB);
66+
$this->assertSoftDeleted($assetMaintenanceC);
6767
}
6868
}

tests/Feature/AssetModels/Api/DeleteAssetModelsTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testCanDeleteAssetModel()
2727
->deleteJson(route('api.models.destroy', $assetModel))
2828
->assertStatusMessageIs('success');
2929

30-
$this->assertTrue($assetModel->fresh()->trashed());
30+
$this->assertSoftDeleted($assetModel);
3131
}
3232

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

41-
$this->assertFalse($assetModel->fresh()->trashed());
41+
$this->assertNotSoftDeleted($assetModel);
4242
}
4343
}

tests/Feature/Assets/Api/DeleteAssetsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCanDeleteAsset()
2828
->deleteJson(route('api.assets.destroy', $asset))
2929
->assertStatusMessageIs('success');
3030

31-
$this->assertTrue($asset->fresh()->trashed());
31+
$this->assertSoftDeleted($asset);
3232
}
3333

3434
public function testCannotDeleteAssetThatIsCheckedOut()
@@ -62,8 +62,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
6262
->deleteJson(route('api.assets.destroy', $assetC))
6363
->assertStatusMessageIs('success');
6464

65-
$this->assertNull($assetA->fresh()->deleted_at, 'Asset unexpectedly deleted');
66-
$this->assertNull($assetB->fresh()->deleted_at, 'Asset unexpectedly deleted');
67-
$this->assertNotNull($assetC->fresh()->deleted_at, 'Asset was not deleted');
65+
$this->assertNotSoftDeleted($assetA);
66+
$this->assertNotSoftDeleted($assetB);
67+
$this->assertSoftDeleted($assetC);
6868
}
6969
}

tests/Feature/Categories/Api/DeleteCategoriesTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testCanDeleteCategory()
2727
->deleteJson(route('api.categories.destroy', $category))
2828
->assertStatusMessageIs('success');
2929

30-
$this->assertTrue($category->fresh()->trashed());
30+
$this->assertSoftDeleted($category);
3131
}
3232

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

42-
$this->assertFalse($category->fresh()->trashed());
42+
$this->assertNotSoftDeleted($category);
4343
}
4444
}

tests/Feature/Companies/Api/DeleteCompaniesTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,11 @@ public function testCannotDeleteCompanyThatHasAssociatedItems()
4444
$actor->deleteJson(route('api.companies.destroy', $companyWithConsumables))->assertStatusMessageIs('error');
4545
$actor->deleteJson(route('api.companies.destroy', $companyWithComponents))->assertStatusMessageIs('error');
4646
$actor->deleteJson(route('api.companies.destroy', $companyWithUsers))->assertStatusMessageIs('error');
47+
48+
$this->assertDatabaseHas('companies', ['id' => $companyWithAssets->id]);
49+
$this->assertDatabaseHas('companies', ['id' => $companyWithAccessories->id]);
50+
$this->assertDatabaseHas('companies', ['id' => $companyWithConsumables->id]);
51+
$this->assertDatabaseHas('companies', ['id' => $companyWithComponents->id]);
52+
$this->assertDatabaseHas('companies', ['id' => $companyWithUsers->id]);
4753
}
4854
}

tests/Feature/Components/Api/DeleteComponentsTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCanDeleteComponents()
2828
->deleteJson(route('api.components.destroy', $component))
2929
->assertStatusMessageIs('success');
3030

31-
$this->assertTrue($component->fresh()->trashed());
31+
$this->assertSoftDeleted($component);
3232
}
3333

3434
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -57,8 +57,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
5757
->deleteJson(route('api.components.destroy', $componentC))
5858
->assertStatusMessageIs('success');
5959

60-
$this->assertNull($componentA->fresh()->deleted_at, 'Component unexpectedly deleted');
61-
$this->assertNull($componentB->fresh()->deleted_at, 'Component unexpectedly deleted');
62-
$this->assertNotNull($componentC->fresh()->deleted_at, 'Component was not deleted');
60+
$this->assertNotSoftDeleted($componentA);
61+
$this->assertNotSoftDeleted($componentB);
62+
$this->assertSoftDeleted($componentC);
6363
}
6464
}

tests/Feature/Consumables/Api/DeleteConsumablesTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testCanDeleteConsumables()
2828
->deleteJson(route('api.consumables.destroy', $consumable))
2929
->assertStatusMessageIs('success');
3030

31-
$this->assertTrue($consumable->fresh()->trashed());
31+
$this->assertSoftDeleted($consumable);
3232
}
3333

3434
public function testAdheresToMultipleFullCompanySupportScoping()
@@ -57,8 +57,8 @@ public function testAdheresToMultipleFullCompanySupportScoping()
5757
->deleteJson(route('api.consumables.destroy', $consumableC))
5858
->assertStatusMessageIs('success');
5959

60-
$this->assertNull($consumableA->fresh()->deleted_at, 'Consumable unexpectedly deleted');
61-
$this->assertNull($consumableB->fresh()->deleted_at, 'Consumable unexpectedly deleted');
62-
$this->assertNotNull($consumableC->fresh()->deleted_at, 'Consumable was not deleted');
60+
$this->assertNotSoftDeleted($consumableA);
61+
$this->assertNotSoftDeleted($consumableB);
62+
$this->assertSoftDeleted($consumableC);
6363
}
6464
}

0 commit comments

Comments
 (0)