mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-11 08:04:09 -08:00
49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Tests\Feature\Api\Locations;
|
||
|
|
||
|
use App\Models\Location;
|
||
|
use App\Models\User;
|
||
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||
|
use Tests\Support\InteractsWithSettings;
|
||
|
use Tests\TestCase;
|
||
|
|
||
|
class LocationsForSelectListTest extends TestCase
|
||
|
{
|
||
|
use InteractsWithSettings;
|
||
|
|
||
|
public function testGettingLocationListRequiresProperPermission()
|
||
|
{
|
||
|
$this->actingAsForApi(User::factory()->create())
|
||
|
->getJson(route('api.locations.selectlist'))
|
||
|
->assertForbidden();
|
||
|
}
|
||
|
|
||
|
public function testLocationsReturned()
|
||
|
{
|
||
|
Location::factory()->create();
|
||
|
|
||
|
// see the where the "view.selectlists" is defined in the AuthServiceProvider
|
||
|
// for info on why "createUsers()" is used here.
|
||
|
$this->actingAsForApi(User::factory()->createUsers()->create())
|
||
|
->getJson(route('api.locations.selectlist'))
|
||
|
->assertOk()
|
||
|
->assertJsonStructure([
|
||
|
'results',
|
||
|
'pagination',
|
||
|
'total_count',
|
||
|
'page',
|
||
|
'page_count',
|
||
|
])
|
||
|
->assertJson(fn(AssertableJson $json) => $json->has('results', 1)->etc());
|
||
|
}
|
||
|
|
||
|
public function testLocationsAreReturnedWhenUserIsUpdatingTheirProfileAndHasPermissionToUpdateLocation()
|
||
|
{
|
||
|
$this->actingAsForApi(User::factory()->canEditOwnLocation()->create())
|
||
|
->withHeader('referer', route('profile'))
|
||
|
->getJson(route('api.locations.selectlist'))
|
||
|
->assertOk();
|
||
|
}
|
||
|
}
|