feat(catalog): add is_enabled attribute to categories and filter items accordingly
This commit is contained in:
@@ -367,6 +367,53 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonPath('1.items.meta.total', 2);
|
||||
}
|
||||
|
||||
public function test_index_excludes_items_from_disabled_categories(): void
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-disabled-category');
|
||||
$group = $this->createGroup(
|
||||
$tenant,
|
||||
ProductLayout::Row,
|
||||
'All products',
|
||||
groupLayout: GroupLayout::Simple,
|
||||
);
|
||||
$enabledCategory = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Enabled',
|
||||
]);
|
||||
$disabledCategory = Category::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'nombre' => 'Disabled',
|
||||
'is_enabled' => false,
|
||||
]);
|
||||
|
||||
$enabledItem = $this->createItem($tenant, 'Enabled item');
|
||||
$enabledItem->category()->associate($enabledCategory)->save();
|
||||
$disabledItem = $this->createItem($tenant, 'Disabled item');
|
||||
$disabledItem->category()->associate($disabledCategory)->save();
|
||||
$uncategorizedItem = $this->createItem($tenant, 'Uncategorized item');
|
||||
|
||||
foreach ([$enabledItem, $disabledItem, $uncategorizedItem] as $order => $item) {
|
||||
$group->featuredItems()->create([
|
||||
'catalog_item_id' => $item->id,
|
||||
'order' => $order,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||
->assertOk()
|
||||
->assertJsonCount(2, '0.items')
|
||||
->assertJsonPath('0.items.0.nombre', 'Enabled item')
|
||||
->assertJsonPath('0.items.1.nombre', 'Uncategorized item')
|
||||
->assertJsonMissing(['nombre' => 'Disabled item']);
|
||||
|
||||
$this->getJson(
|
||||
"/api/tenants/{$tenant->codigo}/catalog/featured-groups/{$group->id}/items"
|
||||
)
|
||||
->assertOk()
|
||||
->assertJsonCount(2)
|
||||
->assertJsonMissing(['nombre' => 'Disabled item']);
|
||||
}
|
||||
|
||||
private function createGroup(
|
||||
Tenant $tenant,
|
||||
ProductLayout $layout,
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Catalog;
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
@@ -15,6 +16,21 @@ class CatalogSchemaTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_categories_are_enabled_by_default(): void
|
||||
{
|
||||
$this->assertTrue(Schema::hasColumn('categorias', 'is_enabled'));
|
||||
|
||||
$category = Category::query()->create([
|
||||
'nombre' => 'Enabled category',
|
||||
]);
|
||||
|
||||
$this->assertTrue($category->is_enabled);
|
||||
$this->assertDatabaseHas('categorias', [
|
||||
'id' => $category->id,
|
||||
'is_enabled' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_legacy_product_tables_are_replaced_by_catalog_tables(): void
|
||||
{
|
||||
$this->assertFalse(Schema::hasTable('productos'));
|
||||
|
||||
Reference in New Issue
Block a user