test(stock): cover terminal reservation lifecycle

This commit is contained in:
2026-08-25 15:58:47 -03:00
parent f6f138e180
commit ec67623b7b
2 changed files with 118 additions and 6 deletions

View File

@@ -208,6 +208,10 @@ class CartControllerTest extends TestCase
->expectsOutput('Expired cart reservations: 0')
->assertSuccessful();
$this->postJson('/api/tenants/acme/cart/restart')
->assertUnprocessable()
->assertJsonValidationErrors('cart');
$this->travel(31)->minutes();
$this->artisan('reservations:expire')
@@ -224,10 +228,11 @@ class CartControllerTest extends TestCase
$this->assertDatabaseHas('carritos', [
'id' => $cartId,
'status' => 'active',
'current_stock_reservation_id' => null,
'current_stock_reservation_id' => $reservationId,
'deleted_at' => null,
]);
$this->assertDatabaseHas('stock_reservations', [
'id' => $reservationId,
'status' => 'expired',
'expires_at' => null,
]);
@@ -236,6 +241,36 @@ class CartControllerTest extends TestCase
'quantity' => 2,
]);
$this->postJson('/api/tenants/acme/cart/items', [
'catalog_item_id' => $item->id,
'cantidad' => 1,
])
->assertUnprocessable()
->assertExactJson([
'code' => 'stock_reservation.expired',
'message' => __('api.cart.reservation_expired'),
]);
$restart = $this->postJson('/api/tenants/acme/cart/restart')
->assertOk()
->assertJsonPath('code', 'cart.restarted')
->assertJsonPath('data.items', [])
->assertJsonMissingPath('data.stock_reservation')
->assertJsonMissingPath('data.current_stock_reservation_id');
$newCartId = $restart->json('data.id');
$this->assertNotSame($cartId, $newCartId);
$this->assertDatabaseHas('carritos', [
'id' => $cartId,
'status' => 'abandoned',
'current_stock_reservation_id' => $reservationId,
]);
$this->assertDatabaseHas('carritos', [
'id' => $newCartId,
'status' => 'active',
'current_stock_reservation_id' => null,
]);
$this->artisan('reservations:expire')
->expectsOutput('Expired purchases: 0')
->expectsOutput('Expired cart reservations: 0')