From 97775fb79036de3ac7e18c4e6aa78c546288096f Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 5 Jul 2024 08:29:00 +0100 Subject: [PATCH] Location test additions Signed-off-by: snipe --- .../Locations/Api/CreateLocationsTest.php | 22 +++++++---- .../Locations/Api/UpdateLocationsTest.php | 38 +++++++++++++++++++ 2 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 tests/Feature/Locations/Api/UpdateLocationsTest.php diff --git a/tests/Feature/Locations/Api/CreateLocationsTest.php b/tests/Feature/Locations/Api/CreateLocationsTest.php index f4ac09890c..600ae7c61f 100644 --- a/tests/Feature/Locations/Api/CreateLocationsTest.php +++ b/tests/Feature/Locations/Api/CreateLocationsTest.php @@ -6,25 +6,31 @@ use App\Models\Location; use App\Models\User; use Tests\TestCase; -class UpdateLocationsTest extends TestCase +class CreateLocationsTest extends TestCase { - public function testCanUpdateLocationViaPatchWithoutLocationType() + public function testRequiresPermissionToCreateLocation() + { + $this->actingAsForApi(User::factory()->create()) + ->postJson(route('api.departments.store')) + ->assertForbidden(); + } + + public function testCannotCreateNewLocationsWithTheSameName() { $location = Location::factory()->create(); + $location2 = Location::factory()->create(); $this->actingAsForApi(User::factory()->superuser()->create()) - ->patchJson(route('api.locations.update', $location), [ - 'name' => 'Test Location', + ->patchJson(route('api.locations.update', $location2), [ + 'name' => $location->name, ]) ->assertOk() - ->assertStatusMessageIs('success') + ->assertStatusMessageIs('error') ->assertStatus(200) ->json(); - $location->refresh(); - $this->assertEquals('Test Location', $location->name, 'Name was not updated'); } - + } diff --git a/tests/Feature/Locations/Api/UpdateLocationsTest.php b/tests/Feature/Locations/Api/UpdateLocationsTest.php new file mode 100644 index 0000000000..a3dd8c228c --- /dev/null +++ b/tests/Feature/Locations/Api/UpdateLocationsTest.php @@ -0,0 +1,38 @@ +actingAsForApi(User::factory()->create()) + ->postJson(route('api.locations.store', Location::factory()->create())) + ->assertForbidden(); + } + + public function testCanUpdateLocationViaPatch() + { + $location = Location::factory()->create(); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->patchJson(route('api.locations.update', $location), [ + 'name' => 'Test Location', + ]) + ->assertOk() + ->assertStatusMessageIs('success') + ->assertStatus(200) + ->json(); + + $location->refresh(); + $this->assertEquals('Test Location', $location->name, 'Name was not updated'); + + } + + +}