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

@@ -0,0 +1,37 @@
<?php
namespace Tests\Unit\Catalog;
use App\Domains\Commerce\Catalog\Models\Category;
use App\Domains\Commerce\Catalog\Resources\CategoryResource;
use App\Shared\Attachable\Models\Attachment;
use App\Shared\Storage\Services\TemporaryUrlService;
use Tests\TestCase;
class CategoryResourceTest extends TestCase
{
public function test_it_returns_the_banner_url_only_when_the_banner_exists_and_is_enabled(): void
{
$category = new Category(['nombre' => 'Remeras', 'banner_enabled' => true]);
$category->setRelation('banner', null);
$this->assertNull(CategoryResource::make($category)->resolve()['banner_url']);
$category->setRelation('banner', new Attachment(['path' => 'categories/banner.jpg']));
$category->banner_enabled = false;
$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(),
]);
});
$this->assertNull(CategoryResource::make($category)->resolve()['banner_url']);
$category->banner_enabled = true;
$this->assertSame(
'https://example.com/banner.jpg',
CategoryResource::make($category)->resolve()['banner_url'],
);
}
}