snipe-it/tests/Feature/Locations/Api/LocationsViewTest.php

45 lines
1.3 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Feature\Consumables\Api;
use App\Models\Location;
use App\Models\Asset;
use App\Models\User;
use Tests\TestCase;
class LocationsViewTest extends TestCase
{
2024-08-06 13:25:22 -07:00
public function testViewingLocationRequiresPermission(): void
{
$location = Location::factory()->create();
$this->actingAsForApi(User::factory()->create())
->getJson(route('api.locations.show', $location->id))
->assertForbidden();
}
2024-08-06 13:25:22 -07:00
public function testViewingLocationAssetIndexRequiresPermission(): void
{
$location = Location::factory()->create();
$this->actingAsForApi(User::factory()->create())
->getJson(route('api.locations.viewassets', $location->id))
->assertForbidden();
}
2024-08-06 13:25:22 -07:00
public function testViewingLocationAssetIndex(): void
{
$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,
]);
}
}