feat(refund): add support for event date suspension in cart invalidation process
This commit is contained in:
@@ -6,10 +6,12 @@ use App\Domains\Cart\Models\Cart;
|
||||
use App\Domains\Cart\Services\InvalidateEventDateCartsService;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Catalog\Models\StockReservation;
|
||||
use App\Domains\Catalog\Services\StockReservationService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InvalidateEventDateCartsServiceTest extends TestCase
|
||||
@@ -82,7 +84,16 @@ class InvalidateEventDateCartsServiceTest extends TestCase
|
||||
DB::table('variant_event_dates')->insert(['variant_id' => 3, 'event_date_id' => 1]);
|
||||
}
|
||||
|
||||
public function test_invalidates_whole_cart_and_releases_all_its_stock_only_once(): void
|
||||
public static function releaseReasons(): array
|
||||
{
|
||||
return [
|
||||
[StockReservationService::REASON_EVENT_DATE_RESCHEDULED],
|
||||
[StockReservationService::REASON_EVENT_DATE_SUSPENDED],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('releaseReasons')]
|
||||
public function test_invalidates_whole_cart_and_releases_all_its_stock_only_once(string $reason): void
|
||||
{
|
||||
$cart = $this->cart(1);
|
||||
$otherInventory = DB::table('inventories')->insertGetId([]);
|
||||
@@ -93,8 +104,8 @@ class InvalidateEventDateCartsServiceTest extends TestCase
|
||||
'quantity' => 2,
|
||||
]);
|
||||
$reservationId = $cart->current_stock_reservation_id;
|
||||
$this->invalidate();
|
||||
$this->invalidate();
|
||||
$this->invalidate($reason);
|
||||
$this->invalidate($reason);
|
||||
|
||||
$this->assertSame(Cart::STATUS_EXPIRED, $cart->fresh()->status);
|
||||
$this->assertNull($cart->fresh()->current_stock_reservation_id);
|
||||
@@ -102,7 +113,7 @@ class InvalidateEventDateCartsServiceTest extends TestCase
|
||||
$this->assertSame(20, (int) Inventory::query()->sum('real_stock'));
|
||||
$this->assertDatabaseHas('stock_reservations', [
|
||||
'id' => $reservationId, 'status' => StockReservation::STATUS_RELEASED,
|
||||
'release_reason' => 'event_date_rescheduled',
|
||||
'release_reason' => $reason,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -138,9 +149,9 @@ class InvalidateEventDateCartsServiceTest extends TestCase
|
||||
$this->assertSame(2, (int) Inventory::query()->sum('reserved_stock'));
|
||||
}
|
||||
|
||||
private function invalidate(): void
|
||||
private function invalidate(string $reason = StockReservationService::REASON_EVENT_DATE_RESCHEDULED): void
|
||||
{
|
||||
app(InvalidateEventDateCartsService::class)->invalidate(new Tenant(['codigo' => 'acme']), collect([1]));
|
||||
app(InvalidateEventDateCartsService::class)->invalidate(new Tenant(['codigo' => 'acme']), collect([1]), $reason);
|
||||
}
|
||||
|
||||
private function cart(int $variantId, string $tenantCode = 'acme'): Cart
|
||||
|
||||
Reference in New Issue
Block a user