Skip to content

A free open source IT asset/license management system

Added location API index test

snipe6da6411f3baa
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 @@
+<?php
+
+namespace Tests\Feature\Locations\Api;
+
+use App\Models\Company;
+use App\Models\Location;
+use App\Models\User;
+use Illuminate\Testing\Fluent\AssertableJson;
+use Tests\TestCase;
+
+class LocationIndexTest extends TestCase
+{
+ public function testViewingLocationIndexRequiresAuthentication()
+ {
+ $this->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());
+ }
+
+}