Skip to content

Commit

Permalink
Add tests for delete location endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusmoore committed Sep 16, 2024
1 parent 60a54ce commit 50730fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ public function deleteCategories()
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']);
Expand Down
12 changes: 11 additions & 1 deletion tests/Feature/Locations/Api/DeleteLocationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class DeleteLocationsTest extends TestCase
{

public function testErrorReturnedViaApiIfLocationDoesNotExist()
{
$this->actingAsForApi(User::factory()->superuser()->create())
Expand Down Expand Up @@ -90,4 +89,15 @@ public function testDisallowUserDeletionViaApiIfStillHasAssetsAsLocation()
->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);
}
}

0 comments on commit 50730fc

Please sign in to comment.