feat(category): add banner functionality to categories with related resource and migration tests

This commit is contained in:
2026-10-01 14:29:31 -03:00
parent 675d76fcb0
commit 5ddc304435
7 changed files with 212 additions and 5 deletions

View File

@@ -8,6 +8,8 @@ use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Models\Category;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Shared\Attachable\Models\Attachment;
use App\Shared\Storage\Services\TemporaryUrlService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
@@ -72,6 +74,39 @@ class CategoryDetailTest extends TestCase
->assertJsonCount(0, 'data');
}
public function test_it_returns_the_banner_url_only_when_a_banner_exists_and_is_enabled(): void
{
$tenant = $this->createTenant('category-banner');
$category = $this->createCategory($tenant, 'Remeras');
$banner = Attachment::query()->create([
'path' => 'categories/banner.jpg',
'filename' => 'banner.jpg',
'type' => 'image',
'mime_type' => 'image/jpeg',
'extension' => 'jpg',
'size' => 100,
]);
$this->mock(TemporaryUrlService::class, function ($mock): void {
$mock->shouldReceive('generate')->once()
->with('categories/banner.jpg', 1440)
->andReturn([
'temporary_url' => 'https://example.com/banner.jpg',
'temporary_url_expires_at' => now()->addDay()->toIso8601String(),
]);
});
$url = "/api/tenants/{$tenant->codigo}/categories/{$category->id}";
$category->update(['banner_enabled' => true]);
$this->getJson($url)->assertOk()->assertJsonPath('category.banner_url', null);
$category->update(['banner_id' => $banner->id, 'banner_enabled' => false]);
$this->getJson($url)->assertOk()->assertJsonPath('category.banner_url', null);
$category->update(['banner_enabled' => true]);
$this->getJson($url)->assertOk()
->assertJsonPath('category.banner_url', 'https://example.com/banner.jpg');
}
public function test_it_includes_products_from_all_descendant_categories(): void
{
$tenant = $this->createTenant('category-descendants');