feat: Introduce source type for featured groups; add category association and implement FeaturedGroupService for item sourcing

This commit is contained in:
2026-08-04 13:17:00 -03:00
parent 8aa3a26ee7
commit 84e45bb964
13 changed files with 260 additions and 136 deletions

View File

@@ -4,9 +4,11 @@ namespace Tests\Feature\Catalog;
use App\Domains\Attachable\Enums\AttachmentType;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Catalog\Enums\FeaturedGroupSource;
use App\Domains\Catalog\Enums\GroupLayout;
use App\Domains\Catalog\Enums\ProductLayout;
use App\Domains\Catalog\Models\CatalogItem;
use App\Domains\Catalog\Models\Category;
use App\Domains\Catalog\Models\FeaturedGroup;
use App\Domains\Catalog\Models\Inventory;
use App\Domains\Tenant\Models\Tenant;
@@ -198,6 +200,46 @@ class CatalogControllerTest extends TestCase
->assertJsonPath('0.nombre', 'carousel Item 1');
}
public function test_groups_can_source_items_from_a_category_or_the_entire_catalog(): void
{
$tenant = $this->createTenant('catalog-sources');
$category = Category::query()->create([
'tenant_code' => $tenant->codigo,
'nombre' => 'Food',
]);
FeaturedGroup::query()->create([
'tenant_code' => $tenant->codigo,
'source_type' => FeaturedGroupSource::Category,
'category_id' => $category->id,
'product_layout' => ProductLayout::Row,
'group_layout' => GroupLayout::Simple,
'group_name' => 'Food',
'group_order' => 0,
]);
FeaturedGroup::query()->create([
'tenant_code' => $tenant->codigo,
'source_type' => FeaturedGroupSource::All,
'product_layout' => ProductLayout::Row,
'group_layout' => GroupLayout::Paginated,
'group_name' => 'All products',
'group_order' => 1,
]);
$food = $this->createItem($tenant, 'Hamburger');
$food->category()->associate($category)->save();
$this->createItem($tenant, 'Parking');
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
->assertOk()
->assertJsonPath('0.title', 'Food')
->assertJsonCount(1, '0.items')
->assertJsonPath('0.items.0.nombre', 'Hamburger')
->assertJsonPath('1.title', 'All products')
->assertJsonCount(2, '1.items.data')
->assertJsonPath('1.items.meta.total', 2);
}
private function createGroup(
Tenant $tenant,
ProductLayout $layout,