feat(catalog): enhance featured groups with paginated and carousel layouts, update seeder and tests
This commit is contained in:
@@ -58,14 +58,13 @@ class CatalogControllerTest extends TestCase
|
||||
->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')
|
||||
->assertJsonPath('0.items.data.0.precio', '100.00')
|
||||
->assertJsonPath('0.items.data.0.stock_tecnico', 7)
|
||||
->assertJsonCount(2, '0.items.data.0.variants')
|
||||
->assertJsonPath('0.items.data.0.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('0.items.data.0.variants.1.stock_tecnico', 3)
|
||||
->assertJsonPath('0.items.0.nombre', 'Variants')
|
||||
->assertJsonPath('0.items.0.descripcion', 'Variants description')
|
||||
->assertJsonPath('0.items.0.precio', '100.00')
|
||||
->assertJsonPath('0.items.0.stock_tecnico', 7)
|
||||
->assertJsonCount(2, '0.items.0.variants')
|
||||
->assertJsonPath('0.items.0.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('0.items.0.variants.1.stock_tecnico', 3)
|
||||
->assertJsonPath('1.title', 'Row')
|
||||
->assertJsonPath('1.items.data.0.stock_tecnico', 8)
|
||||
->assertJsonCount(0, '1.items.data.0.variants');
|
||||
@@ -145,6 +144,60 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonPath('data.0.nombre', 'Item 13');
|
||||
}
|
||||
|
||||
public function test_non_paginated_group_layouts_return_all_items_as_a_plain_array(): void
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-simple-layouts');
|
||||
$layouts = [
|
||||
GroupLayout::Simple,
|
||||
GroupLayout::SimpleVertical,
|
||||
GroupLayout::Carousel,
|
||||
];
|
||||
|
||||
foreach ($layouts as $order => $groupLayout) {
|
||||
$group = $this->createGroup(
|
||||
$tenant,
|
||||
ProductLayout::Row,
|
||||
$groupLayout->value,
|
||||
$order,
|
||||
$groupLayout,
|
||||
);
|
||||
|
||||
foreach (range(1, 13) as $number) {
|
||||
$item = $this->createItem($tenant, "{$groupLayout->value} Item {$number}");
|
||||
$group->featuredItems()->create([
|
||||
'catalog_item_id' => $item->id,
|
||||
'order' => $number,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$response = $this->getJson("/api/tenants/{$tenant->codigo}/catalog")->assertOk();
|
||||
$groups = $response->json();
|
||||
|
||||
foreach ($layouts as $index => $groupLayout) {
|
||||
$this->assertSame($groupLayout->value, $groups[$index]['group_layout']);
|
||||
$this->assertCount(13, $groups[$index]['items']);
|
||||
$this->assertSame(
|
||||
"{$groupLayout->value} Item 1",
|
||||
$groups[$index]['items'][0]['nombre'],
|
||||
);
|
||||
$this->assertArrayNotHasKey('data', $groups[$index]['items']);
|
||||
$this->assertArrayNotHasKey('meta', $groups[$index]['items']);
|
||||
}
|
||||
|
||||
$carouselGroup = FeaturedGroup::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('group_layout', GroupLayout::Carousel)
|
||||
->sole();
|
||||
|
||||
$this->getJson(
|
||||
"/api/tenants/{$tenant->codigo}/catalog/featured-groups/{$carouselGroup->id}/items?page=2"
|
||||
)
|
||||
->assertOk()
|
||||
->assertJsonCount(13)
|
||||
->assertJsonPath('0.nombre', 'carousel Item 1');
|
||||
}
|
||||
|
||||
private function createGroup(
|
||||
Tenant $tenant,
|
||||
ProductLayout $layout,
|
||||
|
||||
Reference in New Issue
Block a user