snipe-it/tests/Feature/AssetModels/Api/IndexAssetModelsTest.php
snipe 1d65781d8d More type-hinting
Signed-off-by: snipe <snipe@snipe.net>
2024-07-05 07:07:20 +01:00

68 lines
2 KiB
PHP

<?php
namespace Tests\Feature\AssetModels\Api;
use App\Models\Company;
use App\Models\AssetModel;
use App\Models\User;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
class IndexAssetModelsTest extends TestCase
{
public function testViewingAssetModelIndexRequiresAuthentication()
{
$this->getJson(route('api.models.index'))->assertRedirect();
}
public function testViewingAssetModelIndexRequiresPermission()
{
$this->actingAsForApi(User::factory()->create())
->getJson(route('api.models.index'))
->assertForbidden();
}
public function testAssetModelIndexReturnsExpectedAssetModels()
{
AssetModel::factory()->count(3)->create();
$this->actingAsForApi(User::factory()->superuser()->create())
->getJson(
route('api.models.index', [
'sort' => 'name',
'order' => 'asc',
'offset' => '0',
'limit' => '20',
]))
->assertOk()
->assertJsonStructure([
'total',
'rows',
])
->assertJson(fn(AssertableJson $json) => $json->has('rows', 3)->etc());
}
public function testAssetModelIndexSearchReturnsExpectedAssetModels()
{
AssetModel::factory()->count(3)->create();
AssetModel::factory()->count(1)->create(['name' => 'Test Model']);
$this->actingAsForApi(User::factory()->superuser()->create())
->getJson(
route('api.models.index', [
'search' => 'Test Model',
'sort' => 'id',
'order' => 'asc',
'offset' => '0',
'limit' => '20',
]))
->assertOk()
->assertJsonStructure([
'total',
'rows',
])
->assertJson(fn(AssertableJson $json) => $json->has('rows', 1)->etc());
}
}