fix(cart): reconcile expired cart mutations
This commit is contained in:
@@ -186,7 +186,7 @@ class CartControllerTest extends TestCase
|
||||
$this->travelBack();
|
||||
}
|
||||
|
||||
public function test_it_expires_abandoned_cart_reservations_without_deleting_the_cart(): void
|
||||
public function test_it_expires_a_cart_reservation_and_automatically_replaces_the_cart(): void
|
||||
{
|
||||
config()->set('catalog.stock_reservation_expiration_minutes', 30);
|
||||
$tenant = $this->createTenant('acme');
|
||||
@@ -208,10 +208,6 @@ 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')
|
||||
@@ -241,28 +237,13 @@ class CartControllerTest extends TestCase
|
||||
'quantity' => 2,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/tenants/acme/cart')
|
||||
$currentCart = $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,
|
||||
])
|
||||
->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.status', Cart::STATUS_ACTIVE)
|
||||
->assertJsonPath('data.items', [])
|
||||
->assertJsonMissingPath('data.stock_reservation')
|
||||
->assertJsonMissingPath('data.current_stock_reservation_id');
|
||||
$newCartId = $restart->json('data.id');
|
||||
$newCartId = $currentCart->json('data.id');
|
||||
|
||||
$this->assertNotSame($cartId, $newCartId);
|
||||
$this->assertDatabaseHas('carritos', [
|
||||
@@ -276,6 +257,14 @@ class CartControllerTest extends TestCase
|
||||
'current_stock_reservation_id' => null,
|
||||
]);
|
||||
|
||||
$this->postJson('/api/tenants/acme/cart/items', [
|
||||
'catalog_item_id' => $item->id,
|
||||
'cantidad' => 1,
|
||||
])
|
||||
->assertOk()
|
||||
->assertJsonPath('data.id', $newCartId)
|
||||
->assertJsonPath('data.items.0.cantidad', 1);
|
||||
|
||||
$this->artisan('reservations:expire')
|
||||
->expectsOutput('Expired purchases: 0')
|
||||
->expectsOutput('Expired cart reservations: 0')
|
||||
|
||||
Reference in New Issue
Block a user