test(stock): cover propagated reservation expiration

This commit is contained in:
2026-08-25 16:10:14 -03:00
parent d69a6210f6
commit ace02a3133
2 changed files with 25 additions and 7 deletions

View File

@@ -227,7 +227,7 @@ class CartControllerTest extends TestCase
$this->assertDatabaseHas('carrito_items', ['id' => $cartItemId]);
$this->assertDatabaseHas('carritos', [
'id' => $cartId,
'status' => 'active',
'status' => Cart::STATUS_EXPIRED,
'current_stock_reservation_id' => $reservationId,
'deleted_at' => null,
]);
@@ -241,6 +241,11 @@ class CartControllerTest extends TestCase
'quantity' => 2,
]);
$this->getJson('/api/tenants/acme/cart')
->assertOk()
->assertJsonPath('data.id', $cartId)
->assertJsonPath('data.status', Cart::STATUS_EXPIRED);
$this->postJson('/api/tenants/acme/cart/items', [
'catalog_item_id' => $item->id,
'cantidad' => 1,
@@ -262,12 +267,12 @@ class CartControllerTest extends TestCase
$this->assertNotSame($cartId, $newCartId);
$this->assertDatabaseHas('carritos', [
'id' => $cartId,
'status' => 'abandoned',
'status' => Cart::STATUS_ABANDONED,
'current_stock_reservation_id' => $reservationId,
]);
$this->assertDatabaseHas('carritos', [
'id' => $newCartId,
'status' => 'active',
'status' => Cart::STATUS_ACTIVE,
'current_stock_reservation_id' => null,
]);

View File

@@ -668,7 +668,7 @@ class StorePurchaseTest extends TestCase
$this->assertSame(3, $remaining);
}
public function test_it_expires_the_purchase_without_mutating_the_active_cart(): void
public function test_it_expires_the_purchase_and_preserves_the_expired_cart_items(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
@@ -694,13 +694,24 @@ class StorePurchaseTest extends TestCase
$this->assertDatabaseHas('carritos', [
'id' => $activeCart->id,
'user_id' => $user->id,
'status' => 'active',
'status' => Cart::STATUS_EXPIRED,
'current_purchase_id' => null,
'current_stock_reservation_id' => $purchase->stock_reservation_id,
'deleted_at' => null,
]);
$this->assertPurchaseReservation($purchase->id, $variant->inventory_id, 3, 'expired');
$this->assertSame(1, $activeCart->items()->count());
$this->actingAs($user, 'sanctum')
->postJson('/api/tenants/sonder/compras/start-checkout', [
'cart_id' => $activeCart->id,
])
->assertUnprocessable()
->assertExactJson([
'code' => 'stock_reservation.expired',
'message' => __('api.cart.reservation_expired'),
]);
$this->actingAs($user, 'sanctum')
->postJson("/api/tenants/sonder/compras/{$purchase->id}/cancel")
->assertUnprocessable()
@@ -1024,7 +1035,7 @@ class StorePurchaseTest extends TestCase
]);
}
public function test_it_expires_an_abandoned_purchase_without_mutating_its_active_cart(): void
public function test_it_expires_a_purchase_and_its_associated_cart(): void
{
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
$user = User::factory()->create();
@@ -1066,7 +1077,9 @@ class StorePurchaseTest extends TestCase
$this->assertDatabaseHas('carritos', [
'id' => $activeCart->id,
'user_id' => $user->id,
'status' => 'active',
'status' => Cart::STATUS_EXPIRED,
'current_purchase_id' => null,
'current_stock_reservation_id' => $purchase->stock_reservation_id,
'deleted_at' => null,
]);
$this->assertSame(1, $activeCart->items()->count());