feat(catalog): expose product unavailability messages
This commit is contained in:
@@ -73,10 +73,15 @@ class CatalogControllerTest extends TestCase
|
||||
->assertJsonPath('0.items.0.descripcion', 'Variants description')
|
||||
->assertJsonPath('0.items.0.precio', '100.00')
|
||||
->assertJsonPath('0.items.0.maximum_addable_quantity', 7)
|
||||
->assertJsonCount(2, '0.items.0.variants')
|
||||
->assertJsonCount(3, '0.items.0.variants')
|
||||
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 4)
|
||||
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 3)
|
||||
->assertJsonMissing(['id' => $unavailableVariant->id])
|
||||
->assertJsonPath('0.items.0.variants.2.id', $unavailableVariant->id)
|
||||
->assertJsonPath('0.items.0.variants.2.maximum_addable_quantity', 0)
|
||||
->assertJsonPath(
|
||||
'0.items.0.variants.2.unavailable_message',
|
||||
'Este producto no tiene stock disponible.',
|
||||
)
|
||||
->assertJsonPath('1.title', 'Row')
|
||||
->assertJsonPath('1.items.data.0.maximum_addable_quantity', 8)
|
||||
->assertJsonMissingPath('1.items.data.0.stock_tecnico')
|
||||
@@ -94,7 +99,7 @@ class CatalogControllerTest extends TestCase
|
||||
);
|
||||
$user = User::factory()->create();
|
||||
$item = $this->createItem($tenant, 'Limited variants');
|
||||
$item->update(['max_units_per_user' => 5]);
|
||||
$item->update(['max_units_per_user' => 3]);
|
||||
$firstVariant = $item->variants()->create([
|
||||
'inventory_id' => Inventory::query()->create(['real_stock' => 10])->id,
|
||||
]);
|
||||
@@ -114,13 +119,21 @@ class CatalogControllerTest extends TestCase
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||
->assertOk()
|
||||
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 2)
|
||||
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 2)
|
||||
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 0)
|
||||
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 0)
|
||||
->assertJsonPath(
|
||||
'0.items.0.variants.0.unavailable_message',
|
||||
'Alcanzaste el cupo máximo permitido para este producto.',
|
||||
)
|
||||
->assertJsonPath(
|
||||
'0.items.0.variants.1.unavailable_message',
|
||||
'Alcanzaste el cupo máximo permitido para este producto.',
|
||||
)
|
||||
->assertJsonMissingPath('0.items.0.variants.0.stock_tecnico')
|
||||
->assertJsonMissingPath('0.items.0.variants.1.stock_tecnico');
|
||||
}
|
||||
|
||||
public function test_it_excludes_items_when_all_of_their_variants_are_out_of_stock(): void
|
||||
public function test_it_includes_out_of_stock_items_with_an_unavailable_message(): void
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-available-variants');
|
||||
$group = $this->createGroup(
|
||||
@@ -148,9 +161,15 @@ class CatalogControllerTest extends TestCase
|
||||
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||
->assertOk()
|
||||
->assertJsonCount(1, '0.items')
|
||||
->assertJsonPath('0.items.0.nombre', 'Available')
|
||||
->assertJsonMissing(['nombre' => 'Unavailable']);
|
||||
->assertJsonCount(2, '0.items')
|
||||
->assertJsonPath('0.items.0.nombre', 'Unavailable')
|
||||
->assertJsonPath('0.items.0.maximum_addable_quantity', 0)
|
||||
->assertJsonPath(
|
||||
'0.items.0.unavailable_message',
|
||||
'Este producto no tiene stock disponible.',
|
||||
)
|
||||
->assertJsonPath('0.items.1.nombre', 'Available')
|
||||
->assertJsonPath('0.items.1.unavailable_message', null);
|
||||
}
|
||||
|
||||
public function test_column_with_image_uses_item_image_then_variant_image_then_null(): void
|
||||
|
||||
@@ -48,7 +48,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
$this->assertStringContainsString($itemImage->path, $response->json('data.images.0'));
|
||||
}
|
||||
|
||||
public function test_it_filters_unavailable_variants_and_selects_the_first_available_one(): void
|
||||
public function test_it_lists_unavailable_variants_and_selects_the_first_available_one(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
$tenant = $this->createTenant('detail-default');
|
||||
@@ -69,8 +69,14 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJsonCount(1, 'data.variants')
|
||||
->assertJsonPath('data.variants.0.id', $secondVariant->id)
|
||||
->assertJsonCount(2, 'data.variants')
|
||||
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
||||
->assertJsonPath('data.variants.0.maximum_addable_quantity', 0)
|
||||
->assertJsonPath(
|
||||
'data.variants.0.unavailable_message',
|
||||
'Este producto no tiene stock disponible.',
|
||||
)
|
||||
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.maximum_addable_quantity', 6)
|
||||
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
||||
|
||||
43
tests/Unit/Catalog/CatalogItemAllowanceServiceTest.php
Normal file
43
tests/Unit/Catalog/CatalogItemAllowanceServiceTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Catalog\Services\CatalogItemAllowanceService;
|
||||
use ReflectionClass;
|
||||
use Tests\TestCase;
|
||||
|
||||
class CatalogItemAllowanceServiceTest extends TestCase
|
||||
{
|
||||
private CatalogItemAllowanceService $service;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->service = (new ReflectionClass(CatalogItemAllowanceService::class))
|
||||
->newInstanceWithoutConstructor();
|
||||
}
|
||||
|
||||
public function test_it_returns_the_user_quota_message_with_priority_over_stock(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
'Alcanzaste el cupo máximo permitido para este producto.',
|
||||
$this->service->unavailableMessage(0, 0),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_returns_the_out_of_stock_message(): void
|
||||
{
|
||||
$this->assertSame(
|
||||
'Este producto no tiene stock disponible.',
|
||||
$this->service->unavailableMessage(0, null),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_it_returns_no_message_when_the_item_is_available(): void
|
||||
{
|
||||
$this->assertNull($this->service->unavailableMessage(1, null));
|
||||
$this->assertNull($this->service->unavailableMessage(null, 1));
|
||||
$this->assertNull($this->service->unavailableMessage(null, null));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user