refactor(reservations): unify expiration command
This commit is contained in:
@@ -117,13 +117,15 @@ class CartControllerTest extends TestCase
|
||||
$cartId = $response->json('data.id');
|
||||
$cartItemId = $response->json('data.items.0.id');
|
||||
|
||||
$this->artisan('carts:expire')
|
||||
$this->artisan('reservations:expire')
|
||||
->expectsOutput('Expired purchases: 0')
|
||||
->expectsOutput('Expired cart items: 0')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->travel(31)->minutes();
|
||||
|
||||
$this->artisan('carts:expire')
|
||||
$this->artisan('reservations:expire')
|
||||
->expectsOutput('Expired purchases: 0')
|
||||
->expectsOutput('Expired cart items: 1')
|
||||
->assertSuccessful();
|
||||
|
||||
@@ -146,7 +148,8 @@ class CartControllerTest extends TestCase
|
||||
'expires_at' => null,
|
||||
]);
|
||||
|
||||
$this->artisan('carts:expire')
|
||||
$this->artisan('reservations:expire')
|
||||
->expectsOutput('Expired purchases: 0')
|
||||
->expectsOutput('Expired cart items: 0')
|
||||
->assertSuccessful();
|
||||
|
||||
|
||||
@@ -850,8 +850,9 @@ class StorePurchaseTest extends TestCase
|
||||
|
||||
$this->travel(31)->minutes();
|
||||
|
||||
$this->artisan('purchases:expire')
|
||||
$this->artisan('reservations:expire')
|
||||
->expectsOutput('Expired purchases: 1')
|
||||
->expectsOutput('Expired cart items: 0')
|
||||
->assertSuccessful();
|
||||
|
||||
$this->assertDatabaseHas('compras', [
|
||||
@@ -877,8 +878,9 @@ class StorePurchaseTest extends TestCase
|
||||
'deleted_at' => null,
|
||||
]);
|
||||
|
||||
$this->artisan('purchases:expire')
|
||||
$this->artisan('reservations:expire')
|
||||
->expectsOutput('Expired purchases: 0')
|
||||
->expectsOutput('Expired cart items: 0')
|
||||
->assertSuccessful();
|
||||
}
|
||||
|
||||
|
||||
33
tests/Unit/Catalog/ExpireStockReservationsServiceTest.php
Normal file
33
tests/Unit/Catalog/ExpireStockReservationsServiceTest.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Catalog;
|
||||
|
||||
use App\Domains\Cart\Services\ExpireCartReservationsService;
|
||||
use App\Domains\Catalog\Services\ExpireStockReservationsService;
|
||||
use App\Domains\Purchase\Services\CheckoutService;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ExpireStockReservationsServiceTest extends TestCase
|
||||
{
|
||||
public function test_it_expires_purchases_before_abandoned_cart_items(): void
|
||||
{
|
||||
$checkout = \Mockery::mock(CheckoutService::class);
|
||||
$checkout->shouldReceive('expireOverduePurchases')
|
||||
->once()
|
||||
->ordered()
|
||||
->andReturn(2);
|
||||
|
||||
$carts = \Mockery::mock(ExpireCartReservationsService::class);
|
||||
$carts->shouldReceive('expireOverdue')
|
||||
->once()
|
||||
->ordered()
|
||||
->andReturn(3);
|
||||
|
||||
$result = (new ExpireStockReservationsService($checkout, $carts))->expireOverdue();
|
||||
|
||||
$this->assertSame([
|
||||
'purchases' => 2,
|
||||
'cart_items' => 3,
|
||||
], $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user