feat: simplify cart restoration logic in ReleaseCheckoutService and SourceCartService
This commit is contained in:
@@ -412,7 +412,7 @@ class StorePurchaseTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_restores_the_source_cart_when_checkout_is_cancelled(): void
|
||||
public function test_it_releases_and_closes_the_checkout_cart_when_purchase_is_cancelled(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create();
|
||||
@@ -430,11 +430,10 @@ class StorePurchaseTest extends TestCase
|
||||
->assertOk()
|
||||
->assertJsonPath('data.status', Purchase::STATUS_CANCELLED);
|
||||
|
||||
$this->assertDatabaseHas('carritos', [
|
||||
$this->assertSoftDeleted('carritos', [
|
||||
'id' => $purchase->cart_id,
|
||||
'user_id' => $user->id,
|
||||
'status' => 'active',
|
||||
'deleted_at' => null,
|
||||
'status' => 'converted',
|
||||
]);
|
||||
$this->assertDatabaseHas('carrito_items', [
|
||||
'cart_id' => $purchase->cart_id,
|
||||
@@ -444,11 +443,16 @@ class StorePurchaseTest extends TestCase
|
||||
]);
|
||||
$this->assertDatabaseHas('inventories', [
|
||||
'id' => $variant->inventory_id,
|
||||
'reserved_stock' => 3,
|
||||
'reserved_stock' => 0,
|
||||
]);
|
||||
$this->assertDatabaseHas('stock_reservations', [
|
||||
'purchase_id' => $purchase->id,
|
||||
'quantity' => 0,
|
||||
'status' => 'released',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_merges_the_checkout_cart_when_the_user_created_another_active_cart(): void
|
||||
public function test_it_keeps_a_new_active_cart_separate_when_checkout_is_cancelled(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create();
|
||||
@@ -480,11 +484,15 @@ class StorePurchaseTest extends TestCase
|
||||
'cart_id' => $activeCartId,
|
||||
'catalog_item_id' => $variant->catalog_item_id,
|
||||
'variant_id' => $variant->id,
|
||||
'cantidad' => 3,
|
||||
'cantidad' => 1,
|
||||
]);
|
||||
$this->assertSoftDeleted('carritos', [
|
||||
'id' => $purchase->cart_id,
|
||||
'status' => 'converted',
|
||||
]);
|
||||
$this->assertDatabaseHas('inventories', [
|
||||
'id' => $variant->inventory_id,
|
||||
'reserved_stock' => 3,
|
||||
'reserved_stock' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -1069,7 +1077,7 @@ class StorePurchaseTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_it_expires_an_abandoned_purchase_and_restores_its_cart(): void
|
||||
public function test_it_expires_an_abandoned_purchase_and_releases_its_checkout_cart(): void
|
||||
{
|
||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||
$user = User::factory()->create();
|
||||
@@ -1095,21 +1103,20 @@ class StorePurchaseTest extends TestCase
|
||||
]);
|
||||
$this->assertDatabaseMissing('compra_items', ['compra_id' => $purchase->id]);
|
||||
$this->assertDatabaseHas('stock_reservations', [
|
||||
'purchase_id' => null,
|
||||
'quantity' => 3,
|
||||
'status' => 'active',
|
||||
'purchase_id' => $purchase->id,
|
||||
'quantity' => 0,
|
||||
'status' => 'expired',
|
||||
]);
|
||||
$this->assertDatabaseHas('inventories', [
|
||||
'id' => $variant->inventory_id,
|
||||
'real_stock' => 10,
|
||||
'reserved_stock' => 3,
|
||||
'reserved_stock' => 0,
|
||||
'sold_units' => 0,
|
||||
]);
|
||||
$this->assertDatabaseHas('carritos', [
|
||||
$this->assertSoftDeleted('carritos', [
|
||||
'id' => $purchase->cart_id,
|
||||
'user_id' => $user->id,
|
||||
'status' => 'active',
|
||||
'deleted_at' => null,
|
||||
'status' => 'converted',
|
||||
]);
|
||||
|
||||
$this->artisan('reservations:expire')
|
||||
|
||||
Reference in New Issue
Block a user