3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-19 08:35:43 +00:00
Files
snipe-it/tests/Feature/Users/Api/IndexUsersTest.php
2025-06-09 12:55:09 -07:00

61 lines
1.9 KiB
PHP

<?php
namespace Tests\Feature\Users\Api;
use App\Models\Location;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
class IndexUsersTest extends TestCase
{
public function testRequiresPermission()
{
$this->actingAsForApi(User::factory()->create())
->getJson(route('api.users.index'))
->assertForbidden();
}
public function testReturnsManagedUsersCountCorrectly()
{
$manager = User::factory()->create(['first_name' => 'Manages Users']);
User::factory()->create(['first_name' => 'Does Not Manage Users']);
User::factory()->create(['manager_id' => $manager->id]);
User::factory()->create(['manager_id' => $manager->id]);
$response = $this->actingAsForApi(User::factory()->viewUsers()->create())
->getJson(route('api.users.index', [
'manages_users_count' => 2,
]))
->assertOk();
$response->assertJson(function (AssertableJson $json) {
$json->has('rows', 1)
->where('rows.0.first_name', 'Manages Users')
->etc();
});
}
public function testReturnsManagedLocationsCountCorrectly()
{
$manager = User::factory()->create(['first_name' => 'Manages Locations']);
User::factory()->create(['first_name' => 'Does Not Manage Locations']);
Location::factory()->create(['manager_id' => $manager->id]);
Location::factory()->create(['manager_id' => $manager->id]);
$response = $this->actingAsForApi(User::factory()->viewUsers()->create())
->getJson(route('api.users.index', [
'manages_locations_count' => 2,
]))
->assertOk();
$response->assertJson(function (AssertableJson $json) {
$json->has('rows', 1)
->where('rows.0.first_name', 'Manages Locations')
->etc();
});
}
}