2024-07-24 12:53:58 -07:00
|
|
|
<?php
|
|
|
|
|
2024-08-06 13:21:36 -07:00
|
|
|
namespace Tests\Feature\Locations\Api;
|
2024-07-24 12:53:58 -07:00
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use App\Models\Asset;
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class LocationsViewTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testViewingLocationRequiresPermission()
|
|
|
|
{
|
|
|
|
$location = Location::factory()->create();
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->getJson(route('api.locations.show', $location->id))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testViewingLocationAssetIndexRequiresPermission()
|
2024-07-24 12:57:26 -07:00
|
|
|
{
|
|
|
|
$location = Location::factory()->create();
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->getJson(route('api.locations.viewassets', $location->id))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testViewingLocationAssetIndex()
|
2024-07-24 12:53:58 -07:00
|
|
|
{
|
|
|
|
$location = Location::factory()->create();
|
|
|
|
Asset::factory()->count(3)->assignedToLocation($location)->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
|
|
|
->getJson(route('api.locations.viewassets', $location->id))
|
|
|
|
->assertOk()
|
|
|
|
->assertJsonStructure([
|
|
|
|
'total',
|
|
|
|
'rows',
|
|
|
|
])
|
|
|
|
->assertJson([
|
|
|
|
'total' => 3,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|