feat(catalog): add scope to filter available variants and update related queries; enhance seeder and tests for stock validation

This commit is contained in:
2026-08-11 09:10:26 -03:00
parent 6f63a87af5
commit 19b506a465
8 changed files with 70 additions and 8 deletions

View File

@@ -80,6 +80,39 @@ class CatalogControllerTest extends TestCase
->assertJsonCount(0, '1.items.data.0.variants');
}
public function test_it_excludes_items_when_all_of_their_variants_are_out_of_stock(): void
{
$tenant = $this->createTenant('catalog-available-variants');
$group = $this->createGroup(
$tenant,
ProductLayout::ColumnWithCart,
'Available variants',
groupLayout: GroupLayout::SimpleVertical,
);
$unavailableItem = $this->createItem($tenant, 'Unavailable');
$unavailableInventory = Inventory::query()->create([
'real_stock' => 4,
'reserved_stock' => 4,
]);
$unavailableItem->variants()->create(['inventory_id' => $unavailableInventory->id]);
$group->featuredItems()->create(['catalog_item_id' => $unavailableItem->id]);
$availableItem = $this->createItem($tenant, 'Available');
$availableInventory = Inventory::query()->create([
'real_stock' => 4,
'reserved_stock' => 3,
]);
$availableItem->variants()->create(['inventory_id' => $availableInventory->id]);
$group->featuredItems()->create(['catalog_item_id' => $availableItem->id]);
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
->assertOk()
->assertJsonCount(1, '0.items')
->assertJsonPath('0.items.0.nombre', 'Available')
->assertJsonMissing(['nombre' => 'Unavailable']);
}
public function test_column_with_image_uses_item_image_then_variant_image_then_null(): void
{
Storage::fake('s3');