feat(purchase): refactor imports and add test for InsufficientStockException handling
This commit is contained in:
@@ -7,8 +7,8 @@ use App\Domains\Cart\Models\CartItem;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Catalog\Services\CatalogInventoryService;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Purchase\Exceptions\InsufficientStockException;
|
||||
use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Purchase\Services\UserPurchaseLimitService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Auth\Exceptions\AccountLockedException;
|
||||
use App\Domains\Ticket\Exceptions\TicketNotAvailableException;
|
||||
use App\Domains\Purchase\Exceptions\InsufficientStockException;
|
||||
use App\Domains\Ticket\Exceptions\TicketNotAvailableException;
|
||||
use App\Http\Middleware\EnsureAdminAppTenant;
|
||||
use App\Http\Middleware\EnsureScannerTenant;
|
||||
use App\Http\Middleware\EnsureTenantHasMenu;
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\ItemAttribute;
|
||||
use App\Domains\Catalog\Models\Variant;
|
||||
use App\Domains\Catalog\Models\VariantDefinition;
|
||||
use App\Domains\Purchase\Exceptions\InsufficientStockException;
|
||||
use App\Domains\Purchase\Services\Checkout\InsufficientStockMessageBuilder;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Support\Facades\App;
|
||||
@@ -16,6 +17,38 @@ use Tests\TestCase;
|
||||
|
||||
class InsufficientStockMessageBuilderTest extends TestCase
|
||||
{
|
||||
public function test_insufficient_stock_exception_exposes_every_conflicting_variant(): void
|
||||
{
|
||||
$exception = new InsufficientStockException([
|
||||
[
|
||||
'index' => 1,
|
||||
'catalog_item_id' => 10,
|
||||
'variant_id' => 102,
|
||||
'requested_quantity' => 1,
|
||||
'available_quantity' => 0,
|
||||
'message' => 'El asiento A2 ya no está disponible.',
|
||||
],
|
||||
[
|
||||
'index' => 3,
|
||||
'catalog_item_id' => 10,
|
||||
'variant_id' => 104,
|
||||
'requested_quantity' => 1,
|
||||
'available_quantity' => 0,
|
||||
'message' => 'El asiento B4 ya no está disponible.',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertSame(
|
||||
'El asiento A2 ya no está disponible. El asiento B4 ya no está disponible.',
|
||||
$exception->getMessage(),
|
||||
);
|
||||
$this->assertSame([
|
||||
'direct_items.1.cantidad' => ['El asiento A2 ya no está disponible.'],
|
||||
'direct_items.3.cantidad' => ['El asiento B4 ya no está disponible.'],
|
||||
], $exception->errors());
|
||||
$this->assertSame([102, 104], collect($exception->unavailableItems)->pluck('variant_id')->all());
|
||||
}
|
||||
|
||||
public function test_it_builds_a_localized_seat_message_from_the_variant_selection(): void
|
||||
{
|
||||
[$catalogItem, $variant] = $this->seatSelection();
|
||||
|
||||
Reference in New Issue
Block a user