feat(catalog): add is_enabled attribute to categories and filter items accordingly
This commit is contained in:
@@ -372,6 +372,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,
|
||||
|
||||
Reference in New Issue
Block a user