2024-07-04 16:21:58 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Categories\Api;
|
|
|
|
|
|
|
|
use App\Models\Category;
|
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Testing\Fluent\AssertableJson;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
2024-07-04 16:26:28 -07:00
|
|
|
class IndexCategoriesTest extends TestCase
|
2024-07-04 16:21:58 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
public function testViewingCategoryIndexRequiresPermission()
|
|
|
|
{
|
|
|
|
$this->actingAsForApi(User::factory()->create())
|
|
|
|
->getJson(route('api.departments.index'))
|
|
|
|
->assertForbidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCategoryIndexReturnsExpectedSearchResults()
|
|
|
|
{
|
|
|
|
Category::factory()->count(10)->create();
|
|
|
|
Category::factory()->count(1)->forAssets()->create(['name' => 'My Test Category']);
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
|
|
|
->getJson(
|
|
|
|
route('api.categories.index', [
|
|
|
|
'search' => 'My Test Category',
|
|
|
|
'sort' => 'name',
|
|
|
|
'order' => 'asc',
|
|
|
|
'offset' => '0',
|
|
|
|
'limit' => '20',
|
|
|
|
]))
|
|
|
|
->assertOk()
|
|
|
|
->assertJsonStructure([
|
|
|
|
'total',
|
|
|
|
'rows',
|
|
|
|
])
|
|
|
|
->assertJson([
|
|
|
|
'total' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testCategoryIndexReturnsExpectedCategories()
|
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Not sure why the category factory is generating one more than expected here.');
|
|
|
|
Category::factory()->count(3)->create();
|
|
|
|
|
|
|
|
$this->actingAsForApi(User::factory()->superuser()->create())
|
|
|
|
->getJson(
|
|
|
|
route('api.categories.index', [
|
|
|
|
'sort' => 'id',
|
|
|
|
'order' => 'asc',
|
|
|
|
'offset' => '0',
|
|
|
|
'limit' => '20',
|
|
|
|
]))
|
|
|
|
->assertOk()
|
|
|
|
->assertJsonStructure([
|
|
|
|
'total',
|
|
|
|
'rows',
|
|
|
|
])
|
|
|
|
->assertJson([
|
|
|
|
'total' => 3,
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|