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

@@ -247,24 +247,14 @@ class BundleCatalogItemTest extends TestCase
]);
}
public function test_catalog_api_creates_and_returns_bundle_details(): void
public function test_catalog_api_returns_bundle_details_created_by_the_service(): void
{
$component = $this->createStandardItem('api-component', 8);
$bundle = $this->createBundle('api-bundle', [
['catalog_item_id' => $component->id, 'quantity' => 2],
], '75.00');
$bundleId = $this->postJson("/api/tenants/{$this->tenant->codigo}/catalog-items", [
'type' => CatalogItemType::Bundle->value,
'slug' => 'api-bundle',
'nombre' => 'API Bundle',
'precio' => 75,
'components' => [
['catalog_item_id' => $component->id, 'quantity' => 2],
],
])
->assertCreated()
->assertJsonPath('data.type', CatalogItemType::Bundle->value)
->json('data.id');
$this->getJson("/api/tenants/{$this->tenant->codigo}/catalog-items/{$bundleId}")
$this->getJson("/api/tenants/{$this->tenant->codigo}/catalog-items/{$bundle->id}")
->assertOk()
->assertJsonPath('data.type', CatalogItemType::Bundle->value)
->assertJsonPath('data.maximum_addable_quantity', 4)
@@ -274,7 +264,9 @@ class BundleCatalogItemTest extends TestCase
->assertJsonPath('data.components.0.variant_id', null)
->assertJsonPath('data.components.0.quantity', 2);
$this->postJson("/api/tenants/{$this->tenant->codigo}/catalog-items", [
$this->expectException(ValidationException::class);
$this->catalogService->create([
'tenant_code' => $this->tenant->codigo,
'type' => CatalogItemType::Bundle->value,
'slug' => 'bundle-with-stock',
'nombre' => 'Invalid Bundle',
@@ -283,9 +275,7 @@ class BundleCatalogItemTest extends TestCase
'components' => [
['catalog_item_id' => $component->id, 'quantity' => 1],
],
])
->assertUnprocessable()
->assertJsonValidationErrors(['real_stock']);
]);
}
public function test_bundle_components_are_preserved_when_the_bundle_is_soft_deleted(): void