From 6da6411f3baa1b44c040f7481347882c064467e3 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 5 Jul 2024 01:46:36 +0100 Subject: [PATCH] Added location API index test Signed-off-by: snipe --- .../Locations/Api/IndexLocationsTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/Feature/Locations/Api/IndexLocationsTest.php diff --git a/tests/Feature/Locations/Api/IndexLocationsTest.php b/tests/Feature/Locations/Api/IndexLocationsTest.php new file mode 100644 index 0000000000..38857a7607 --- /dev/null +++ b/tests/Feature/Locations/Api/IndexLocationsTest.php @@ -0,0 +1,45 @@ +getJson(route('api.locations.index'))->assertRedirect(); + } + + public function testViewingLocationIndexRequiresPermission() + { + $this->actingAsForApi(User::factory()->create()) + ->getJson(route('api.locations.index')) + ->assertForbidden(); + } + + public function testLocationIndexReturnsExpectedLocations() + { + Location::factory()->count(3)->create(); + + $this->actingAsForApi(User::factory()->superuser()->create()) + ->getJson( + route('api.locations.index', [ + 'sort' => 'name', + 'order' => 'asc', + 'offset' => '0', + 'limit' => '20', + ])) + ->assertOk() + ->assertJsonStructure([ + 'total', + 'rows', + ]) + ->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc()); + } + +}