From 50730fc4fba2519fb13799bc93ab682c10092c25 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 16 Sep 2024 12:37:18 -0700 Subject: [PATCH] Add tests for delete location endpoint --- database/factories/UserFactory.php | 5 +++++ tests/Feature/Locations/Api/DeleteLocationsTest.php | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 598de7c39c..747aef0164 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -311,6 +311,11 @@ class UserFactory extends Factory return $this->appendPermission(['categories.delete' => '1']); } + public function deleteLocations() + { + return $this->appendPermission(['locations.delete' => '1']); + } + public function canEditOwnLocation() { return $this->appendPermission(['self.edit_location' => '1']); diff --git a/tests/Feature/Locations/Api/DeleteLocationsTest.php b/tests/Feature/Locations/Api/DeleteLocationsTest.php index 270582c901..c023b4b3ad 100644 --- a/tests/Feature/Locations/Api/DeleteLocationsTest.php +++ b/tests/Feature/Locations/Api/DeleteLocationsTest.php @@ -9,7 +9,6 @@ use Tests\TestCase; class DeleteLocationsTest extends TestCase { - public function testErrorReturnedViaApiIfLocationDoesNotExist() { $this->actingAsForApi(User::factory()->superuser()->create()) @@ -90,4 +89,15 @@ class DeleteLocationsTest extends TestCase ->json(); } + public function testCanDeleteLocation() + { + $location = Location::factory()->create(); + + $this->actingAsForApi(User::factory()->deleteLocations()->create()) + ->deleteJson(route('api.locations.destroy', $location->id)) + ->assertOk() + ->assertStatusMessageIs('success'); + + $this->assertSoftDeleted($location); + } }