feat(cart): expire abandoned stock reservations
This commit is contained in:
@@ -104,6 +104,55 @@ class CartControllerTest extends TestCase
|
||||
$this->travelBack();
|
||||
}
|
||||
|
||||
public function test_it_expires_abandoned_cart_reservations_and_removes_empty_carts(): void
|
||||
{
|
||||
config()->set('catalog.stock_reservation_expiration_minutes', 30);
|
||||
$tenant = $this->createTenant('acme');
|
||||
$item = $this->createDirectItem($tenant, 10, '49.90');
|
||||
|
||||
$response = $this->postJson('/api/tenants/acme/cart/items', [
|
||||
'catalog_item_id' => $item->id,
|
||||
'cantidad' => 2,
|
||||
])->assertOk();
|
||||
$cartId = $response->json('data.id');
|
||||
$cartItemId = $response->json('data.items.0.id');
|
||||
|
||||
$this->artisan('carts:expire')
|
||||
->expectsOutput('Expired cart items: 0')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->travel(31)->minutes();
|
||||
|
||||
$this->artisan('carts:expire')
|
||||
->expectsOutput('Expired cart items: 1')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('inventories', [
|
||||
'id' => $item->inventory_id,
|
||||
'real_stock' => 10,
|
||||
'reserved_stock' => 0,
|
||||
]);
|
||||
$this->assertDatabaseMissing('carrito_items', ['id' => $cartItemId]);
|
||||
$this->assertSoftDeleted('carritos', [
|
||||
'id' => $cartId,
|
||||
'status' => 'expired',
|
||||
]);
|
||||
$this->assertDatabaseHas('stock_reservations', [
|
||||
'inventory_id' => $item->inventory_id,
|
||||
'cart_item_id' => null,
|
||||
'purchase_id' => null,
|
||||
'quantity' => 0,
|
||||
'status' => 'expired',
|
||||
'expires_at' => null,
|
||||
]);
|
||||
|
||||
$this->artisan('carts:expire')
|
||||
->expectsOutput('Expired cart items: 0')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->travelBack();
|
||||
}
|
||||
|
||||
public function test_it_filters_item_images_when_the_tenant_disables_them(): void
|
||||
{
|
||||
$tenant = $this->createTenant('acme');
|
||||
|
||||
Reference in New Issue
Block a user