Refactor Catalog API: Remove Create Catalog Item Endpoint and Update Related Logic

- Removed the "Create Catalog" endpoint from the Postman collection.
- Updated the CatalogController to handle tenant-specific catalog items based on active events.
- Refactored CatalogItem model to automatically set event_id based on tenant's active_event_id during creation.
- Deleted StoreCatalogItemRequest and CatalogItemResource as they are no longer needed.
- Updated various services and controllers to utilize the new tenant-based catalog item retrieval logic.
- Added tests to ensure that catalog reads are limited to items associated with the active event.
This commit is contained in:
2026-09-18 13:51:13 -03:00
parent cdc17a13e2
commit 22ef5619f3
21 changed files with 107 additions and 482 deletions

View File

@@ -14,6 +14,7 @@ use App\Domains\Commerce\Catalog\Models\Category;
use App\Domains\Commerce\Catalog\Models\FeaturedGroup;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Models\Event;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
@@ -22,6 +23,41 @@ class CatalogControllerTest extends TestCase
{
use RefreshDatabase;
public function test_active_event_limits_catalog_reads_to_its_items(): void
{
$tenant = $this->createTenant('active-event-catalog');
$group = $this->createGroup($tenant, ProductLayout::Row, 'Events', groupLayout: GroupLayout::Simple);
$group->update(['source_type' => FeaturedGroupSource::All]);
$activeEvent = Event::query()->create(['tenant_code' => $tenant->codigo, 'title' => 'Active']);
$otherEvent = Event::query()->create(['tenant_code' => $tenant->codigo, 'title' => 'Other']);
$activeItem = $this->createItem($tenant, 'Active item', Inventory::query()->create(['real_stock' => 5]));
$activeItem->event_id = $activeEvent->id;
$activeItem->save();
$otherItem = $this->createItem($tenant, 'Other item', Inventory::query()->create(['real_stock' => 5]));
$otherItem->event_id = $otherEvent->id;
$otherItem->save();
$tenant->update(['active_event_id' => $activeEvent->id]);
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
->assertOk()
->assertJsonCount(1, '0.items')
->assertJsonPath('0.items.0.id', $activeItem->id)
->assertJsonMissing(['nombre' => 'Other item']);
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items?q=item")
->assertOk()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.id', $activeItem->id);
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$otherItem->id}")
->assertNotFound();
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$activeItem->id}")
->assertOk();
}
public function test_row_and_column_with_cart_return_item_details_variants_and_maximum_quantity(): void
{
$tenant = $this->createTenant('catalog-index');