test(checkout): cover source cart restoration

This commit is contained in:
2026-08-20 16:29:59 -03:00
parent 9d870be294
commit 0510c1aa12

View File

@@ -412,7 +412,7 @@ class StorePurchaseTest extends TestCase
]);
}
public function test_it_releases_and_closes_the_checkout_cart_when_purchase_is_cancelled(): void
public function test_it_restores_the_source_cart_when_checkout_is_cancelled(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
@@ -430,10 +430,11 @@ class StorePurchaseTest extends TestCase
->assertOk()
->assertJsonPath('data.status', Purchase::STATUS_CANCELLED);
$this->assertSoftDeleted('carritos', [
$this->assertDatabaseHas('carritos', [
'id' => $purchase->cart_id,
'user_id' => $user->id,
'status' => 'converted',
'status' => 'active',
'deleted_at' => null,
]);
$this->assertDatabaseHas('carrito_items', [
'cart_id' => $purchase->cart_id,
@@ -443,16 +444,11 @@ class StorePurchaseTest extends TestCase
]);
$this->assertDatabaseHas('inventories', [
'id' => $variant->inventory_id,
'reserved_stock' => 0,
]);
$this->assertDatabaseHas('stock_reservations', [
'purchase_id' => $purchase->id,
'quantity' => 0,
'status' => 'released',
'reserved_stock' => 3,
]);
}
public function test_it_keeps_a_new_active_cart_separate_when_checkout_is_cancelled(): void
public function test_it_merges_the_checkout_cart_when_the_user_created_another_active_cart(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
@@ -484,15 +480,11 @@ class StorePurchaseTest extends TestCase
'cart_id' => $activeCartId,
'catalog_item_id' => $variant->catalog_item_id,
'variant_id' => $variant->id,
'cantidad' => 1,
]);
$this->assertSoftDeleted('carritos', [
'id' => $purchase->cart_id,
'status' => 'converted',
'cantidad' => 3,
]);
$this->assertDatabaseHas('inventories', [
'id' => $variant->inventory_id,
'reserved_stock' => 1,
'reserved_stock' => 3,
]);
}