feat(tenant): add categories relationship and structure to tenant resource and controller
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Tests\Feature\Tenant;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Menu\Models\Menu;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -95,6 +96,45 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.dominio', 'acme.com');
|
||||
}
|
||||
|
||||
public function test_it_returns_only_the_tenant_categories_in_the_bootstrap(): void
|
||||
{
|
||||
$tenant = $this->createTenant();
|
||||
$otherTenant = $this->createTenant([
|
||||
'codigo' => 'globex',
|
||||
'nombre' => 'Globex',
|
||||
'dominio' => 'globex.com',
|
||||
]);
|
||||
|
||||
$parent = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Remeras',
|
||||
]);
|
||||
Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'categoria_id' => $parent->id,
|
||||
'nombre' => 'Manga corta',
|
||||
]);
|
||||
Category::query()->create([
|
||||
'tenant_code' => $otherTenant->codigo,
|
||||
'nombre' => 'Otra categoría',
|
||||
]);
|
||||
Category::query()->create([
|
||||
'tenant_code' => null,
|
||||
'nombre' => 'Global',
|
||||
]);
|
||||
|
||||
$this->getJson('/api/tenants/bootstrap/acme.com')
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data.categories')
|
||||
->assertJsonPath('data.categories.0.nombre', 'Remeras')
|
||||
->assertJsonCount(1, 'data.categories.0.subcategories')
|
||||
->assertJsonPath('data.categories.0.subcategories.0.nombre', 'Manga corta')
|
||||
->assertJsonPath('data.categories.0.subcategories.0.subcategories', [])
|
||||
->assertJsonMissingPath('data.categories.0.categoria_id')
|
||||
->assertJsonMissing(['nombre' => 'Otra categoría'])
|
||||
->assertJsonMissing(['nombre' => 'Global']);
|
||||
}
|
||||
|
||||
public function test_it_returns_not_found_when_the_domain_does_not_exist(): void
|
||||
{
|
||||
$response = $this->getJson('/api/tenants/bootstrap/missing.example');
|
||||
|
||||
Reference in New Issue
Block a user