feat(catalog): add GroupLayout enum and integrate into FeaturedGroup model, migrations, and seeders
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Tests\Feature\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
@@ -21,7 +22,13 @@ class CatalogControllerTest extends TestCase
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-index');
|
||||
$row = $this->createGroup($tenant, ProductLayout::Row, 'Row', 2);
|
||||
$cart = $this->createGroup($tenant, ProductLayout::ColumnWithCart, 'Cart', 1);
|
||||
$cart = $this->createGroup(
|
||||
$tenant,
|
||||
ProductLayout::ColumnWithCart,
|
||||
'Cart',
|
||||
1,
|
||||
GroupLayout::SimpleVertical,
|
||||
);
|
||||
|
||||
$directInventory = Inventory::query()->create([
|
||||
'real_stock' => 10,
|
||||
@@ -50,6 +57,7 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonCount(2)
|
||||
->assertJsonPath('0.title', 'Cart')
|
||||
->assertJsonPath('0.layout', ProductLayout::ColumnWithCart->value)
|
||||
->assertJsonPath('0.group_layout', GroupLayout::SimpleVertical->value)
|
||||
->assertJsonPath('0.items.meta.current_page', 1)
|
||||
->assertJsonPath('0.items.data.0.nombre', 'Variants')
|
||||
->assertJsonPath('0.items.data.0.descripcion', 'Variants description')
|
||||
@@ -142,10 +150,12 @@ class CatalogControllerTest extends TestCase
|
||||
ProductLayout $layout,
|
||||
string $name,
|
||||
int $order = 0,
|
||||
GroupLayout $groupLayout = GroupLayout::Paginated,
|
||||
): FeaturedGroup {
|
||||
return FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'product_layout' => $layout,
|
||||
'group_layout' => $groupLayout,
|
||||
'group_name' => $name,
|
||||
'group_order' => $order,
|
||||
]);
|
||||
|
||||
@@ -78,6 +78,7 @@ class CatalogSchemaTest extends TestCase
|
||||
'id',
|
||||
'tenant_code',
|
||||
'product_layout',
|
||||
'group_layout',
|
||||
'group_name',
|
||||
'group_order',
|
||||
], Schema::getColumnListing('featured_groups'));
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Seeders;
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
@@ -133,6 +134,10 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
||||
->with('featuredItems.catalogItem')
|
||||
->orderBy('group_order')
|
||||
->get()
|
||||
->each(fn (FeaturedGroup $group) => $this->assertSame(
|
||||
GroupLayout::Paginated,
|
||||
$group->group_layout,
|
||||
))
|
||||
->mapWithKeys(fn (FeaturedGroup $group): array => [
|
||||
$group->group_name => $group->featuredItems->pluck('catalogItem.slug')->all(),
|
||||
])
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
@@ -58,6 +59,7 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
||||
|
||||
$this->assertSame('Productos', $group->group_name);
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||
$this->assertSame(GroupLayout::Paginated, $group->group_layout);
|
||||
$this->assertSame(0, $group->group_order);
|
||||
$this->assertSame(
|
||||
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('id')->pluck('slug')->all(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
use App\Domains\Catalog\Enums\ProductLayout;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
@@ -25,6 +26,16 @@ use Tests\TestCase;
|
||||
|
||||
class CatalogModelsTest extends TestCase
|
||||
{
|
||||
public function test_group_layout_has_all_supported_values(): void
|
||||
{
|
||||
$this->assertSame([
|
||||
'paginated',
|
||||
'simple',
|
||||
'simple_vertical',
|
||||
'carousel',
|
||||
], GroupLayout::values());
|
||||
}
|
||||
|
||||
public function test_attribute_maps_its_values_and_relations(): void
|
||||
{
|
||||
$attribute = new Attribute;
|
||||
@@ -83,6 +94,7 @@ class CatalogModelsTest extends TestCase
|
||||
$group = new FeaturedGroup;
|
||||
$group->setRawAttributes([
|
||||
'product_layout' => ProductLayout::ColumnWithImage->value,
|
||||
'group_layout' => GroupLayout::SimpleVertical->value,
|
||||
'group_order' => '2',
|
||||
]);
|
||||
$featuredItem = new FeaturedItem;
|
||||
@@ -95,6 +107,7 @@ class CatalogModelsTest extends TestCase
|
||||
$this->assertSame('featured_groups', $group->getTable());
|
||||
$this->assertFalse($group->usesTimestamps());
|
||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||
$this->assertSame(GroupLayout::SimpleVertical, $group->group_layout);
|
||||
$this->assertSame(2, $group->group_order);
|
||||
$this->assertInstanceOf(Tenant::class, $group->tenant()->getRelated());
|
||||
$this->assertInstanceOf(FeaturedItem::class, $group->featuredItems()->getRelated());
|
||||
|
||||
Reference in New Issue
Block a user