feat(purchase): implement purchase limit enforcement and custom exception handling
This commit is contained in:
@@ -241,7 +241,15 @@ class CartControllerTest extends TestCase
|
||||
'cantidad' => 2,
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('cantidad');
|
||||
->assertJsonValidationErrors('cantidad')
|
||||
->assertJsonPath('code', 'purchase.limit_exceeded')
|
||||
->assertJsonPath('catalog_item_id', $item->id)
|
||||
->assertJsonPath('catalog_item_name', $item->nombre)
|
||||
->assertJsonPath('maximum_addable_quantity', 1)
|
||||
->assertJsonPath(
|
||||
'message',
|
||||
"Podés agregar hasta 1 unidad más de “{$item->nombre}”.",
|
||||
);
|
||||
|
||||
$this->assertDatabaseHas('carrito_items', [
|
||||
'catalog_item_id' => $item->id,
|
||||
|
||||
@@ -267,7 +267,8 @@ class BundleCatalogItemTest extends TestCase
|
||||
$this->getJson("/api/tenants/{$this->tenant->codigo}/catalog-items/{$bundleId}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.type', CatalogItemType::Bundle->value)
|
||||
->assertJsonPath('data.stock_tecnico', 4)
|
||||
->assertJsonPath('data.maximum_addable_quantity', 4)
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
->assertJsonCount(1, 'data.components')
|
||||
->assertJsonPath('data.components.0.catalog_item_id', $component->id)
|
||||
->assertJsonPath('data.components.0.variant_id', null)
|
||||
|
||||
@@ -22,7 +22,7 @@ class CatalogControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_row_and_column_with_cart_return_item_details_variants_and_technical_stock(): void
|
||||
public function test_row_and_column_with_cart_return_item_details_variants_and_maximum_quantity(): void
|
||||
{
|
||||
$tenant = $this->createTenant('catalog-index');
|
||||
$row = $this->createGroup($tenant, ProductLayout::Row, 'Row', 2);
|
||||
@@ -72,16 +72,14 @@ class CatalogControllerTest extends TestCase
|
||||
->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)
|
||||
->assertJsonPath('0.items.0.maximum_addable_quantity', 7)
|
||||
->assertJsonCount(2, '0.items.0.variants')
|
||||
->assertJsonPath('0.items.0.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 4)
|
||||
->assertJsonPath('0.items.0.variants.1.stock_tecnico', 3)
|
||||
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 3)
|
||||
->assertJsonMissing(['id' => $unavailableVariant->id, 'stock_tecnico' => 0])
|
||||
->assertJsonMissing(['id' => $unavailableVariant->id])
|
||||
->assertJsonPath('1.title', 'Row')
|
||||
->assertJsonPath('1.items.data.0.stock_tecnico', 8)
|
||||
->assertJsonPath('1.items.data.0.maximum_addable_quantity', 8)
|
||||
->assertJsonMissingPath('1.items.data.0.stock_tecnico')
|
||||
->assertJsonCount(0, '1.items.data.0.variants');
|
||||
}
|
||||
|
||||
@@ -116,10 +114,10 @@ class CatalogControllerTest extends TestCase
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson("/api/tenants/{$tenant->codigo}/catalog")
|
||||
->assertOk()
|
||||
->assertJsonPath('0.items.0.variants.0.stock_tecnico', 8)
|
||||
->assertJsonPath('0.items.0.variants.0.maximum_addable_quantity', 2)
|
||||
->assertJsonPath('0.items.0.variants.1.stock_tecnico', 9)
|
||||
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 2);
|
||||
->assertJsonPath('0.items.0.variants.1.maximum_addable_quantity', 2)
|
||||
->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
|
||||
|
||||
@@ -40,7 +40,8 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJsonPath('data.stock_tecnico', 7)
|
||||
->assertJsonPath('data.maximum_addable_quantity', 7)
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
->assertJsonCount(0, 'data.variants')
|
||||
->assertJsonCount(1, 'data.images');
|
||||
$response->assertJsonMissingPath('data.selected_variant');
|
||||
@@ -71,7 +72,8 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertJsonCount(1, 'data.variants')
|
||||
->assertJsonPath('data.variants.0.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', 6)
|
||||
->assertJsonPath('data.selected_variant.maximum_addable_quantity', 6)
|
||||
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
||||
->assertJsonCount(1, 'data.selected_variant.images');
|
||||
$response
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
@@ -125,11 +127,11 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
$response
|
||||
->assertOk()
|
||||
->assertJsonPath('data.variants.0.id', $firstVariant->id)
|
||||
->assertJsonPath('data.variants.0.stock_tecnico', 4)
|
||||
->assertJsonPath('data.variants.0.maximum_addable_quantity', 4)
|
||||
->assertJsonPath('data.variants.0.values.size.value', 'S')
|
||||
->assertJsonPath('data.variants.0.values.size.label', 'Small')
|
||||
->assertJsonPath('data.variants.1.id', $secondVariant->id)
|
||||
->assertJsonPath('data.variants.1.stock_tecnico', 7)
|
||||
->assertJsonPath('data.variants.1.maximum_addable_quantity', 7)
|
||||
->assertJsonPath('data.variants.1.values.size.value', 'M')
|
||||
->assertJsonPath('data.variants.1.values.size.label', 'Medium')
|
||||
->assertJsonPath('data.attributes.0.codigo', 'size')
|
||||
@@ -137,7 +139,7 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
->assertJsonPath('data.attributes.0.options.1.value', 'M')
|
||||
->assertJsonCount(2, 'data.attributes.0.options')
|
||||
->assertJsonPath('data.selected_variant.id', $secondVariant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', 7)
|
||||
->assertJsonPath('data.selected_variant.maximum_addable_quantity', 7)
|
||||
->assertJsonPath('data.selected_variant.values.size.value', 'M')
|
||||
->assertJsonPath('data.selected_variant.values.size.label', 'Medium')
|
||||
->assertJsonCount(1, 'data.selected_variant.images');
|
||||
@@ -177,9 +179,11 @@ class CatalogItemDetailControllerTest extends TestCase
|
||||
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items/{$item->id}")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.selected_variant.id', $variant->id)
|
||||
->assertJsonPath('data.selected_variant.stock_tecnico', null)
|
||||
->assertJsonPath('data.selected_variant.maximum_addable_quantity', null)
|
||||
->assertJsonMissingPath('data.stock_tecnico')
|
||||
->assertJsonPath('data.variants.0.stock_tecnico', null);
|
||||
->assertJsonPath('data.variants.0.maximum_addable_quantity', null)
|
||||
->assertJsonMissingPath('data.selected_variant.stock_tecnico')
|
||||
->assertJsonMissingPath('data.variants.0.stock_tecnico');
|
||||
}
|
||||
|
||||
public function test_it_exposes_event_dates_as_a_dynamic_variant_attribute(): void
|
||||
|
||||
@@ -340,7 +340,11 @@ class StorePurchaseTest extends TestCase
|
||||
],
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('direct_items');
|
||||
->assertJsonValidationErrors('direct_items')
|
||||
->assertJsonPath('code', 'purchase.limit_exceeded')
|
||||
->assertJsonPath('catalog_item_id', $variant->catalog_item_id)
|
||||
->assertJsonPath('catalog_item_name', $variant->catalogItem->nombre)
|
||||
->assertJsonPath('maximum_addable_quantity', 1);
|
||||
|
||||
$this->actingAs($otherUser, 'sanctum')
|
||||
->postJson('/api/tenants/sonder/compras/start-checkout', [
|
||||
|
||||
Reference in New Issue
Block a user