Compare commits
24 Commits
fix/simpli
...
b1f42775d6
| Author | SHA1 | Date | |
|---|---|---|---|
| b1f42775d6 | |||
| 0f6f39cce7 | |||
| 1ec7ab3e35 | |||
| ba0e2dd00c | |||
| c792e7d306 | |||
| 6ee3f22e41 | |||
| 899bf12457 | |||
| a460743ae0 | |||
| a4d7b1b789 | |||
| 10655b8c07 | |||
| adc7b21ab8 | |||
| ba1355448a | |||
| 1c76e56f2d | |||
| daa74845b7 | |||
| 05944cec9c | |||
| c820741e5f | |||
| adc4cc9595 | |||
| c67dfcc1a1 | |||
| f61b7e4dee | |||
| e53fa949cf | |||
| c51e24311f | |||
| a650de79c1 | |||
| 8f4fc39858 | |||
| 09554b9f80 |
@@ -5,9 +5,6 @@ APP_DEBUG=false
|
|||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
PURCHASE_CHECKOUT_EXPIRATION_MINUTES=30
|
PURCHASE_CHECKOUT_EXPIRATION_MINUTES=30
|
||||||
PURCHASE_QR_EXPIRATION_MINUTES=15
|
|
||||||
PURCHASE_TELEPAGOS_EXPIRATION_MINUTES=30
|
|
||||||
PURCHASE_TRANSFER_EXPIRATION_MINUTES=1440
|
|
||||||
STOCK_RESERVATION_EXPIRATION_MINUTES=30
|
STOCK_RESERVATION_EXPIRATION_MINUTES=30
|
||||||
FRONTEND_URLS=http://localhost:4200
|
FRONTEND_URLS=http://localhost:4200
|
||||||
|
|
||||||
|
|||||||
@@ -343,9 +343,9 @@ class StockReservationService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refreshForPurchase(Purchase $purchase, ?Carbon $expiresAt): void
|
public function clearExpirationForReview(Purchase $purchase): void
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($purchase, $expiresAt): void {
|
DB::transaction(function () use ($purchase): void {
|
||||||
/** @var Purchase $purchase */
|
/** @var Purchase $purchase */
|
||||||
$purchase = Purchase::query()->lockForUpdate()->findOrFail($purchase->getKey());
|
$purchase = Purchase::query()->lockForUpdate()->findOrFail($purchase->getKey());
|
||||||
if ($purchase->stock_reservation_id === null) {
|
if ($purchase->stock_reservation_id === null) {
|
||||||
@@ -363,7 +363,7 @@ class StockReservationService
|
|||||||
throw new StockReservationExpiredException;
|
throw new StockReservationExpiredException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reservation->update(['expires_at' => $expiresAt]);
|
$reservation->update(['expires_at' => null]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Controllers\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Forms\Resources\TicketFormResource;
|
||||||
|
use App\Domains\Forms\Services\TicketFormService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class TicketFormController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(protected TicketFormService $ticketFormService) {}
|
||||||
|
|
||||||
|
public function __invoke(Request $request): TicketFormResource
|
||||||
|
{
|
||||||
|
return TicketFormResource::make(
|
||||||
|
$this->ticketFormService->get(
|
||||||
|
$request->user('sanctum')->tenant()->firstOrFail()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
app/Domains/Forms/Resources/TicketFormResource.php
Normal file
18
app/Domains/Forms/Resources/TicketFormResource.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class TicketFormResource extends JsonResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'statuses' => $this->resource['statuses'],
|
||||||
|
'categories' => $this->resource['categories'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
234
app/Domains/Forms/Services/TicketFormService.php
Normal file
234
app/Domains/Forms/Services/TicketFormService.php
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Forms\Services;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
|
||||||
|
class TicketFormService
|
||||||
|
{
|
||||||
|
private const PRODUCT = 'product';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, array{label: string|null, product: string, type: string|null, order: int}>
|
||||||
|
*/
|
||||||
|
private const CATEGORY_PRESENTATIONS = [
|
||||||
|
'entradas' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => self::PRODUCT,
|
||||||
|
'type' => null,
|
||||||
|
'order' => 1,
|
||||||
|
],
|
||||||
|
'alojamientos' => [
|
||||||
|
'label' => 'Camping',
|
||||||
|
'product' => 'tipo_alojamiento',
|
||||||
|
'type' => null,
|
||||||
|
'order' => 2,
|
||||||
|
],
|
||||||
|
'camping' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => 'tipo_alojamiento',
|
||||||
|
'type' => null,
|
||||||
|
'order' => 2,
|
||||||
|
],
|
||||||
|
'comidas' => [
|
||||||
|
'label' => 'Comida',
|
||||||
|
'product' => 'event_date',
|
||||||
|
'type' => 'horario',
|
||||||
|
'order' => 3,
|
||||||
|
],
|
||||||
|
'comida' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => 'event_date',
|
||||||
|
'type' => 'horario',
|
||||||
|
'order' => 3,
|
||||||
|
],
|
||||||
|
'merchandising' => [
|
||||||
|
'label' => null,
|
||||||
|
'product' => self::PRODUCT,
|
||||||
|
'type' => 'color',
|
||||||
|
'order' => 4,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{
|
||||||
|
* statuses: list<array{value: string, label: string}>,
|
||||||
|
* categories: list<array{
|
||||||
|
* value: string,
|
||||||
|
* label: string,
|
||||||
|
* products: list<array{
|
||||||
|
* value: string,
|
||||||
|
* label: string,
|
||||||
|
* types: list<array{value: string, label: string}>
|
||||||
|
* }>
|
||||||
|
* }>
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public function get(Tenant $tenant): array
|
||||||
|
{
|
||||||
|
$categories = [];
|
||||||
|
|
||||||
|
$items = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->where('has_tickets', true)
|
||||||
|
->whereHas('category')
|
||||||
|
->with([
|
||||||
|
'category',
|
||||||
|
'itemAttributes.attribute.options',
|
||||||
|
'variants.definitions.itemAttribute.attribute.options',
|
||||||
|
'variants.eventDates',
|
||||||
|
'variants.eventDate',
|
||||||
|
])
|
||||||
|
->orderBy('group_order')
|
||||||
|
->orderBy('nombre')
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$sourceCategory = trim((string) $item->category?->nombre);
|
||||||
|
$categoryValue = mb_strtolower($sourceCategory);
|
||||||
|
$presentation = self::CATEGORY_PRESENTATIONS[$categoryValue] ?? [
|
||||||
|
'label' => null,
|
||||||
|
'product' => self::PRODUCT,
|
||||||
|
'type' => null,
|
||||||
|
'order' => PHP_INT_MAX,
|
||||||
|
];
|
||||||
|
|
||||||
|
$categories[$categoryValue] ??= [
|
||||||
|
'value' => $categoryValue,
|
||||||
|
'label' => $presentation['label'] ?? $sourceCategory,
|
||||||
|
'order' => $presentation['order'],
|
||||||
|
'products' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($this->products($item, $presentation['product'], $presentation['type']) as $product) {
|
||||||
|
$productValue = $product['value'];
|
||||||
|
$existingProduct = $categories[$categoryValue]['products'][$productValue] ?? [
|
||||||
|
'value' => $productValue,
|
||||||
|
'label' => $product['label'],
|
||||||
|
'types' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($product['types'] as $type) {
|
||||||
|
$existingProduct['types'][$type['value']] = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
$categories[$categoryValue]['products'][$productValue] = $existingProduct;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uasort($categories, fn (array $left, array $right): int => $left['order'] <=> $right['order']
|
||||||
|
?: $left['label'] <=> $right['label']);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'statuses' => [
|
||||||
|
['value' => Ticket::STATUS_ACTIVE, 'label' => 'Activo'],
|
||||||
|
['value' => Ticket::STATUS_USED, 'label' => 'Usado'],
|
||||||
|
['value' => Ticket::STATUS_EXPIRED, 'label' => 'Vencido'],
|
||||||
|
],
|
||||||
|
'categories' => array_values(array_map(
|
||||||
|
fn (array $category): array => [
|
||||||
|
'value' => $category['value'],
|
||||||
|
'label' => $category['label'],
|
||||||
|
'products' => array_values(array_map(
|
||||||
|
fn (array $product): array => [
|
||||||
|
'value' => $product['value'],
|
||||||
|
'label' => $product['label'],
|
||||||
|
'types' => array_values($product['types']),
|
||||||
|
],
|
||||||
|
$category['products'],
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
$categories,
|
||||||
|
)),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{
|
||||||
|
* value: string,
|
||||||
|
* label: string,
|
||||||
|
* types: list<array{value: string, label: string}>
|
||||||
|
* }>
|
||||||
|
*/
|
||||||
|
private function products(CatalogItem $item, string $productCode, ?string $typeCode): array
|
||||||
|
{
|
||||||
|
if ($productCode === self::PRODUCT) {
|
||||||
|
return [[
|
||||||
|
'value' => $item->slug,
|
||||||
|
'label' => $item->nombre,
|
||||||
|
'types' => $this->types($item, $typeCode),
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
|
||||||
|
$products = [];
|
||||||
|
|
||||||
|
foreach ($item->variants as $variant) {
|
||||||
|
foreach ($this->variantOptions($variant, $productCode) as $productOption) {
|
||||||
|
$productValue = $productOption['value'];
|
||||||
|
$products[$productValue] ??= [
|
||||||
|
'value' => $productValue,
|
||||||
|
'label' => $this->optionLabel($productOption['label'], $productCode),
|
||||||
|
'types' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
||||||
|
$products[$productValue]['types'][$typeOption['value']] = $typeOption;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values(array_map(
|
||||||
|
fn (array $product): array => [
|
||||||
|
'value' => $product['value'],
|
||||||
|
'label' => $product['label'],
|
||||||
|
'types' => array_values($product['types']),
|
||||||
|
],
|
||||||
|
$products,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<array{value: string, label: string}> */
|
||||||
|
private function types(CatalogItem $item, ?string $typeCode): array
|
||||||
|
{
|
||||||
|
$types = [];
|
||||||
|
|
||||||
|
foreach ($item->variants as $variant) {
|
||||||
|
foreach ($this->variantOptions($variant, $typeCode) as $typeOption) {
|
||||||
|
$types[$typeOption['value']] = $typeOption;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values($types);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<array{value: string, label: string}> */
|
||||||
|
private function variantOptions(Variant $variant, ?string $attributeCode): array
|
||||||
|
{
|
||||||
|
if ($attributeCode === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$selection = $variant->selectionOptions($variant->catalogItem->itemAttributes)
|
||||||
|
->get($attributeCode);
|
||||||
|
|
||||||
|
if ($selection === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_is_list($selection) ? $selection : [$selection];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function optionLabel(string $label, string $attributeCode): string
|
||||||
|
{
|
||||||
|
if ($attributeCode !== 'event_date') {
|
||||||
|
return $label;
|
||||||
|
}
|
||||||
|
|
||||||
|
[$day, $month] = array_pad(explode('/', $label), 2, null);
|
||||||
|
|
||||||
|
return $day !== null && $month !== null ? "{$day}/{$month}" : $label;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ Provee catálogos y opciones auxiliares para construir formularios del panel adm
|
|||||||
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
- `EventFormService`: devuelve redes sociales disponibles y las URL configuradas para el tenant.
|
||||||
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
- `SaleFormService`: expone los estados admitidos para compras con sus etiquetas de presentación.
|
||||||
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
- `StaffFormService`: lista categorías raíz que pueden asignarse al personal del tenant.
|
||||||
|
- `TicketFormService`: expone estados y opciones anidadas de categoría, producto y tipo para los tickets de Fiesta Fútbol Infantil.
|
||||||
|
|
||||||
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
Cada servicio tiene un controlador invocable y un `JsonResource` específico. `SocialMediaOptionResource` representa las opciones de redes sociales.
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ Bajo `/v1/adminapp/forms`, con `auth:sanctum` y `adminapp.tenant`:
|
|||||||
- `GET /event`.
|
- `GET /event`.
|
||||||
- `GET /sale`.
|
- `GET /sale`.
|
||||||
- `GET /staff`.
|
- `GET /staff`.
|
||||||
|
- `GET /fiesta-futbol-infantil/ticket`: estados y jerarquía categoría → producto → tipo para filtros de tickets.
|
||||||
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
- `GET /fiesta-futbol-infantil/merchandise`: opciones de color y talle del tenant para merchandising.
|
||||||
|
|
||||||
## Dependencias
|
## Dependencias
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use App\Domains\Forms\Controllers\AdminApp\FoodFormController;
|
|||||||
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
use App\Domains\Forms\Controllers\AdminApp\MerchandiseFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
use App\Domains\Forms\Controllers\AdminApp\SaleFormController;
|
||||||
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
use App\Domains\Forms\Controllers\AdminApp\StaffFormController;
|
||||||
|
use App\Domains\Forms\Controllers\AdminApp\TicketFormController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::prefix('v1/adminapp/forms')
|
Route::prefix('v1/adminapp/forms')
|
||||||
@@ -13,6 +14,10 @@ Route::prefix('v1/adminapp/forms')
|
|||||||
Route::get('event', EventFormController::class);
|
Route::get('event', EventFormController::class);
|
||||||
Route::get('sale', SaleFormController::class);
|
Route::get('sale', SaleFormController::class);
|
||||||
Route::get('staff', StaffFormController::class);
|
Route::get('staff', StaffFormController::class);
|
||||||
|
Route::get(
|
||||||
|
'fiesta-futbol-infantil/ticket',
|
||||||
|
TicketFormController::class
|
||||||
|
);
|
||||||
Route::get(
|
Route::get(
|
||||||
'fiesta-futbol-infantil/merchandise',
|
'fiesta-futbol-infantil/merchandise',
|
||||||
MerchandiseFormController::class
|
MerchandiseFormController::class
|
||||||
|
|||||||
@@ -93,7 +93,6 @@ class PurchaseController extends Controller
|
|||||||
PaymentIntentRequest $request,
|
PaymentIntentRequest $request,
|
||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
Purchase $compra,
|
Purchase $compra,
|
||||||
CheckoutService $checkoutService,
|
|
||||||
PurchaseStateGuard $purchaseState,
|
PurchaseStateGuard $purchaseState,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
||||||
@@ -103,7 +102,6 @@ class PurchaseController extends Controller
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
$updated = DB::transaction(function () use (
|
$updated = DB::transaction(function () use (
|
||||||
$checkoutService,
|
|
||||||
$compra,
|
$compra,
|
||||||
$method,
|
$method,
|
||||||
$purchaseState,
|
$purchaseState,
|
||||||
@@ -142,12 +140,6 @@ class PurchaseController extends Controller
|
|||||||
$purchaseUpdate['transfer_payer_dni'] = $transferPayerDni;
|
$purchaseUpdate['transfer_payer_dni'] = $transferPayerDni;
|
||||||
}
|
}
|
||||||
$purchase->update($purchaseUpdate);
|
$purchase->update($purchaseUpdate);
|
||||||
$checkoutService->refreshReservationExpiration(
|
|
||||||
$purchase,
|
|
||||||
now()->addMinutes(
|
|
||||||
max(1, (int) config("purchase.payment_expiration_minutes.{$method}", 30)),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ class PurchaseResource extends JsonResource
|
|||||||
*/
|
*/
|
||||||
public function toArray(Request $request): array
|
public function toArray(Request $request): array
|
||||||
{
|
{
|
||||||
|
$serverTime = now();
|
||||||
|
$expiresAt = $this->stockReservation?->expires_at;
|
||||||
$items = $this->resource->relationLoaded('items')
|
$items = $this->resource->relationLoaded('items')
|
||||||
? $this->resource->getRelation('items')
|
? $this->resource->getRelation('items')
|
||||||
: collect();
|
: collect();
|
||||||
@@ -48,7 +50,11 @@ class PurchaseResource extends JsonResource
|
|||||||
'created_at' => $this->created_at,
|
'created_at' => $this->created_at,
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'payment_method' => $this->payment_method,
|
'payment_method' => $this->payment_method,
|
||||||
'expires_at' => $this->stockReservation?->expires_at,
|
'expires_at' => $expiresAt,
|
||||||
|
'expires_in_seconds' => $expiresAt === null
|
||||||
|
? null
|
||||||
|
: max(0, $expiresAt->getTimestamp() - $serverTime->getTimestamp()),
|
||||||
|
'server_time' => $serverTime,
|
||||||
'dni' => $this->dni,
|
'dni' => $this->dni,
|
||||||
'transfer_payer_dni' => $this->transfer_payer_dni,
|
'transfer_payer_dni' => $this->transfer_payer_dni,
|
||||||
'telefono' => $this->telefono,
|
'telefono' => $this->telefono,
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class CompleteCheckoutService
|
|||||||
$purchase->update([
|
$purchase->update([
|
||||||
'status' => Purchase::STATUS_IN_REVIEW,
|
'status' => Purchase::STATUS_IN_REVIEW,
|
||||||
]);
|
]);
|
||||||
$this->reservations->refreshForPurchase($purchase, null);
|
$this->reservations->clearExpirationForReview($purchase);
|
||||||
|
|
||||||
return $this->loadPurchase($purchase);
|
return $this->loadPurchase($purchase);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,14 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Domains\Purchase\Services;
|
namespace App\Domains\Purchase\Services;
|
||||||
|
|
||||||
use App\Domains\Catalog\Services\StockReservationService;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Services\Checkout\CompleteCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\CompleteCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\StartCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\StartCheckoutService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +22,6 @@ class CheckoutService
|
|||||||
private readonly EditCheckoutService $editor,
|
private readonly EditCheckoutService $editor,
|
||||||
private readonly CompleteCheckoutService $completer,
|
private readonly CompleteCheckoutService $completer,
|
||||||
private readonly ReleaseCheckoutService $releaser,
|
private readonly ReleaseCheckoutService $releaser,
|
||||||
private readonly StockReservationService $reservations,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
/** @param array<string, mixed> $purchaseData */
|
/** @param array<string, mixed> $purchaseData */
|
||||||
@@ -78,9 +75,4 @@ class CheckoutService
|
|||||||
{
|
{
|
||||||
return $this->releaser->expire($purchase);
|
return $this->releaser->expire($purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function refreshReservationExpiration(Purchase $purchase, ?Carbon $expiresAt): void
|
|
||||||
{
|
|
||||||
$this->reservations->refreshForPurchase($purchase, $expiresAt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
22
app/Domains/Ticket/Controllers/AdminApp/TicketController.php
Normal file
22
app/Domains/Ticket/Controllers/AdminApp/TicketController.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Controllers\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Requests\AdminAppTicketIndexRequest;
|
||||||
|
use App\Domains\Ticket\Resources\AdminApp\AdminAppTicketCollection;
|
||||||
|
use App\Domains\Ticket\Services\AdminAppTicketService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class TicketController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(private readonly AdminAppTicketService $ticketService) {}
|
||||||
|
|
||||||
|
public function index(AdminAppTicketIndexRequest $request): AdminAppTicketCollection
|
||||||
|
{
|
||||||
|
$tenant = $request->user()->tenant()->firstOrFail();
|
||||||
|
|
||||||
|
return new AdminAppTicketCollection(
|
||||||
|
$this->ticketService->search($tenant, $request->validated())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
app/Domains/Ticket/Requests/AdminAppTicketIndexRequest.php
Normal file
23
app/Domains/Ticket/Requests/AdminAppTicketIndexRequest.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class AdminAppTicketIndexRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, list<string>> */
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'q' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
|
'page' => ['sometimes', 'integer', 'min:1'],
|
||||||
|
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Resources\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Services\AdminAppTicketResult;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class AdminAppTicketCollection extends ResourceCollection
|
||||||
|
{
|
||||||
|
/** @var class-string<AdminAppTicketResource> */
|
||||||
|
public $collects = AdminAppTicketResource::class;
|
||||||
|
|
||||||
|
private readonly int $scannedTickets;
|
||||||
|
|
||||||
|
private readonly int $totalTickets;
|
||||||
|
|
||||||
|
public function __construct(AdminAppTicketResult $result)
|
||||||
|
{
|
||||||
|
parent::__construct($result->tickets);
|
||||||
|
|
||||||
|
$this->scannedTickets = $result->scannedTickets;
|
||||||
|
$this->totalTickets = $result->totalTickets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{scanned_tickets: int, total_tickets: int} */
|
||||||
|
public function with(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'scanned_tickets' => $this->scannedTickets,
|
||||||
|
'total_tickets' => $this->totalTickets,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Resources\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Models\ItemAttribute;
|
||||||
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use App\Domains\Ticket\Resources\TicketResource;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
/** @mixin Ticket */
|
||||||
|
class AdminAppTicketResource extends TicketResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
$purchaseItem = $this->sourcePurchaseItem();
|
||||||
|
|
||||||
|
return [
|
||||||
|
...parent::toArray($request),
|
||||||
|
'source_purchase_id' => $this->source_purchase_id,
|
||||||
|
'order_number' => $this->source_purchase_id,
|
||||||
|
'product' => $purchaseItem?->item_nombre
|
||||||
|
?? $this->sourceCatalogItem?->nombre
|
||||||
|
?? $this->name,
|
||||||
|
'amount' => $purchaseItem?->precio_unitario,
|
||||||
|
'client' => $this->sourcePurchase?->nombre_apellido ?? $this->user?->nombre_apellido,
|
||||||
|
'date' => $this->sourcePurchase?->created_at,
|
||||||
|
'status' => $this->status,
|
||||||
|
'scanned_by' => $this->scannerUser?->nombre_apellido,
|
||||||
|
'variant_properties' => $this->variantProperties(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sourcePurchaseItem(): ?PurchaseItem
|
||||||
|
{
|
||||||
|
return $this->sourcePurchase?->items->first(function (PurchaseItem $item): bool {
|
||||||
|
if ($this->source_variant_id !== null) {
|
||||||
|
return $item->source_variant_id === $this->source_variant_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $item->source_catalog_item_id === $this->source_catalog_item_id
|
||||||
|
&& $item->source_variant_id === null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<array{
|
||||||
|
* code: string,
|
||||||
|
* label: string,
|
||||||
|
* values: list<array{value: string, label: string}>
|
||||||
|
* }>
|
||||||
|
*/
|
||||||
|
private function variantProperties(): array
|
||||||
|
{
|
||||||
|
$variant = $this->sourceVariant;
|
||||||
|
|
||||||
|
if ($variant === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$itemAttributes = $variant->definitions
|
||||||
|
->map(fn ($definition) => $definition->itemAttribute)
|
||||||
|
->filter()
|
||||||
|
->merge($variant->catalogItem?->itemAttributes ?? collect())
|
||||||
|
->unique('id')
|
||||||
|
->values();
|
||||||
|
|
||||||
|
return $variant->selectionOptions($itemAttributes)
|
||||||
|
->map(function (array $selection, string $attributeCode) use ($itemAttributes): array {
|
||||||
|
$itemAttribute = $itemAttributes->first(
|
||||||
|
fn (ItemAttribute $itemAttribute): bool => $itemAttribute->attribute?->codigo
|
||||||
|
=== $attributeCode,
|
||||||
|
);
|
||||||
|
$values = array_is_list($selection) ? $selection : [$selection];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'code' => $attributeCode,
|
||||||
|
'label' => $itemAttribute?->attribute?->nombre
|
||||||
|
?? ($attributeCode === 'event_date' ? 'Fecha' : $attributeCode),
|
||||||
|
'values' => array_values($values),
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/Domains/Ticket/Services/AdminAppTicketResult.php
Normal file
16
app/Domains/Ticket/Services/AdminAppTicketResult.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Services;
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
|
||||||
|
final readonly class AdminAppTicketResult
|
||||||
|
{
|
||||||
|
/** @param LengthAwarePaginator<Ticket> $tickets */
|
||||||
|
public function __construct(
|
||||||
|
public LengthAwarePaginator $tickets,
|
||||||
|
public int $scannedTickets,
|
||||||
|
public int $totalTickets,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
58
app/Domains/Ticket/Services/AdminAppTicketService.php
Normal file
58
app/Domains/Ticket/Services/AdminAppTicketService.php
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Ticket\Services;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class AdminAppTicketService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param array{q?: string|null, page?: int, per_page?: int} $filters
|
||||||
|
*/
|
||||||
|
public function search(Tenant $tenant, array $filters = []): AdminAppTicketResult
|
||||||
|
{
|
||||||
|
$query = $this->baseQuery($tenant, $filters);
|
||||||
|
|
||||||
|
$tickets = (clone $query)
|
||||||
|
->with([
|
||||||
|
...TicketValidityResolver::RELATIONS,
|
||||||
|
...TicketPresentationResolver::RELATIONS,
|
||||||
|
'user',
|
||||||
|
'scannerUser',
|
||||||
|
'sourceCatalogItem.category',
|
||||||
|
'sourcePurchase.items',
|
||||||
|
])
|
||||||
|
->orderByDesc('id')
|
||||||
|
->paginateFromRequest()
|
||||||
|
->withQueryString();
|
||||||
|
|
||||||
|
return new AdminAppTicketResult(
|
||||||
|
tickets: $tickets,
|
||||||
|
scannedTickets: (clone $query)->whereNotNull('used_at')->count(),
|
||||||
|
totalTickets: $tickets->total(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array{q?: string|null, page?: int, per_page?: int} $filters
|
||||||
|
* @return Builder<Ticket>
|
||||||
|
*/
|
||||||
|
private function baseQuery(Tenant $tenant, array $filters): Builder
|
||||||
|
{
|
||||||
|
$search = trim((string) ($filters['q'] ?? ''));
|
||||||
|
|
||||||
|
return Ticket::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->when($search !== '', function (Builder $query) use ($search): void {
|
||||||
|
$query->when(
|
||||||
|
ctype_digit($search),
|
||||||
|
fn (Builder $searchQuery): Builder => $searchQuery
|
||||||
|
->where('tickets.id', (int) $search),
|
||||||
|
fn (Builder $searchQuery): Builder => $searchQuery
|
||||||
|
->where('ticket', 'like', "%{$search}%"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,12 @@ Bajo `/tenants/{tenant:codigo}`, protegidos por `auth:sanctum`:
|
|||||||
- `GET /tickets`.
|
- `GET /tickets`.
|
||||||
- `POST /tickets/pdf`.
|
- `POST /tickets/pdf`.
|
||||||
|
|
||||||
|
Bajo `/v1/adminapp/tenant`, protegido por `auth:sanctum`, `adminapp.tenant` y el menú
|
||||||
|
`adminapp.tickets`:
|
||||||
|
|
||||||
|
- `GET /tickets`, paginado y con búsqueda opcional mediante `q`. La respuesta incluye
|
||||||
|
`scanned_tickets` y `total_tickets` para el tenant autenticado.
|
||||||
|
|
||||||
`TicketPdfService` genera la descarga y `TicketResource`/`ValidityTimeResource` definen las respuestas.
|
`TicketPdfService` genera la descarga y `TicketResource`/`ValidityTimeResource` definen las respuestas.
|
||||||
|
|
||||||
## Dependencias y reglas
|
## Dependencias y reglas
|
||||||
|
|||||||
12
app/Domains/Ticket/routes/adminapp.php
Normal file
12
app/Domains/Ticket/routes/adminapp.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Ticket\Controllers\AdminApp\TicketController;
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::prefix('v1/adminapp/tenant')
|
||||||
|
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||||
|
->group(function (): void {
|
||||||
|
Route::get('tickets', [TicketController::class, 'index'])
|
||||||
|
->middleware('tenant.menu:adminapp.tickets')
|
||||||
|
->name('adminapp.tickets.index');
|
||||||
|
});
|
||||||
@@ -11,3 +11,4 @@ Route::prefix('tenants/{tenant:codigo}')
|
|||||||
});
|
});
|
||||||
|
|
||||||
require __DIR__.'/scanner.php';
|
require __DIR__.'/scanner.php';
|
||||||
|
require __DIR__.'/adminapp.php';
|
||||||
|
|||||||
@@ -2,10 +2,4 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'checkout_expiration_minutes' => (int) env('PURCHASE_CHECKOUT_EXPIRATION_MINUTES', 30),
|
'checkout_expiration_minutes' => (int) env('PURCHASE_CHECKOUT_EXPIRATION_MINUTES', 30),
|
||||||
|
|
||||||
'payment_expiration_minutes' => [
|
|
||||||
'qr' => (int) env('PURCHASE_QR_EXPIRATION_MINUTES', 15),
|
|
||||||
'telepagos' => (int) env('PURCHASE_TELEPAGOS_EXPIRATION_MINUTES', 30),
|
|
||||||
'transfer' => (int) env('PURCHASE_TRANSFER_EXPIRATION_MINUTES', 1440),
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
private const MENU_CODE = 'adminapp.tickets';
|
||||||
|
|
||||||
|
private const TENANT_CODE = 'fiesta_futbol_infantil';
|
||||||
|
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (! DB::table('menues')->where('code', 'main.adminapp')->exists()) {
|
||||||
|
// Reference data is added by seeders on fresh installations.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = now();
|
||||||
|
|
||||||
|
DB::transaction(function () use ($now): void {
|
||||||
|
DB::table('menues')->updateOrInsert(
|
||||||
|
['code' => self::MENU_CODE],
|
||||||
|
[
|
||||||
|
'label' => 'Tickets',
|
||||||
|
'parent_menu_code' => 'main.adminapp',
|
||||||
|
'content_type' => 'dynamic',
|
||||||
|
'static_content_schema' => null,
|
||||||
|
'route' => '/admin/tickets',
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
DB::table('tenants_menues')
|
||||||
|
->where('menu_code', self::MENU_CODE)
|
||||||
|
->where('tenant_code', '!=', self::TENANT_CODE)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
if (DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) {
|
||||||
|
DB::table('tenants_menues')->updateOrInsert(
|
||||||
|
[
|
||||||
|
'tenant_code' => self::TENANT_CODE,
|
||||||
|
'menu_code' => self::MENU_CODE,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'static_content' => null,
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('roles')
|
||||||
|
->whereIn('codigo', ['admin', 'adminapp'])
|
||||||
|
->pluck('codigo')
|
||||||
|
->each(function (string $roleCode): void {
|
||||||
|
DB::table('roles_menues')->updateOrInsert([
|
||||||
|
'rol_codigo' => $roleCode,
|
||||||
|
'menu_codigo' => self::MENU_CODE,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
DB::transaction(function (): void {
|
||||||
|
DB::table('tenants_menues')
|
||||||
|
->where('menu_code', self::MENU_CODE)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
DB::table('roles_menues')
|
||||||
|
->where('menu_codigo', self::MENU_CODE)
|
||||||
|
->delete();
|
||||||
|
|
||||||
|
DB::table('menues')
|
||||||
|
->where('code', self::MENU_CODE)
|
||||||
|
->delete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -78,6 +78,12 @@ class MenuSeeder extends Seeder
|
|||||||
'parent_menu_code' => 'main.adminapp',
|
'parent_menu_code' => 'main.adminapp',
|
||||||
'route' => '/admin/staff',
|
'route' => '/admin/staff',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'code' => 'adminapp.tickets',
|
||||||
|
'label' => 'Tickets',
|
||||||
|
'parent_menu_code' => 'main.adminapp',
|
||||||
|
'route' => '/admin/tickets',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
||||||
'label' => 'Entradas',
|
'label' => 'Entradas',
|
||||||
@@ -270,6 +276,7 @@ class MenuSeeder extends Seeder
|
|||||||
'fiesta_futbol_infantil',
|
'fiesta_futbol_infantil',
|
||||||
];
|
];
|
||||||
$fiestaCategoryMenuCodes = [
|
$fiestaCategoryMenuCodes = [
|
||||||
|
'adminapp.tickets',
|
||||||
'adminapp.fiesta-futbol-infantil.entradas',
|
'adminapp.fiesta-futbol-infantil.entradas',
|
||||||
'adminapp.fiesta-futbol-infantil.alojamientos',
|
'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||||
'adminapp.fiesta-futbol-infantil.merchandising',
|
'adminapp.fiesta-futbol-infantil.merchandising',
|
||||||
|
|||||||
@@ -18,7 +18,8 @@
|
|||||||
</include>
|
</include>
|
||||||
</source>
|
</source>
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing" force="true"/>
|
||||||
|
<env name="DB_DATABASE" value="shopit_test" force="true"/>
|
||||||
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
|
||||||
<env name="APP_CONFIG_CACHE" value="bootstrap/cache/phpunit-config.php"/>
|
<env name="APP_CONFIG_CACHE" value="bootstrap/cache/phpunit-config.php"/>
|
||||||
<env name="APP_EVENTS_CACHE" value="bootstrap/cache/phpunit-events.php"/>
|
<env name="APP_EVENTS_CACHE" value="bootstrap/cache/phpunit-events.php"/>
|
||||||
|
|||||||
155
tests/Feature/Forms/AdminAppTicketFormControllerTest.php
Normal file
155
tests/Feature/Forms/AdminAppTicketFormControllerTest.php
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Forms;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\AttributeSeeder;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Database\Seeders\FiestaFutbolInfantilProductSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminAppTicketFormControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->seed(AuthorizationSeeder::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_authentication_is_required(): void
|
||||||
|
{
|
||||||
|
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket')
|
||||||
|
->assertUnauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_nested_ticket_options_using_the_frontend_presentation_mapping(): void
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment('header.png');
|
||||||
|
$footerLogo = $this->createAttachment('footer.png');
|
||||||
|
$tenant = Tenant::query()->create([
|
||||||
|
'codigo' => 'fiesta_futbol_infantil',
|
||||||
|
'nombre' => 'Fiesta Fútbol Infantil',
|
||||||
|
'dominio' => 'fiesta-futbol-infantil.test',
|
||||||
|
'primary_color' => '#00973F',
|
||||||
|
'secondary_color' => '#A0A0A0',
|
||||||
|
'danger_color' => '#FF8888',
|
||||||
|
'success_color' => '#198754',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#015327',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
$this->seed([AttributeSeeder::class, FiestaFutbolInfantilProductSeeder::class]);
|
||||||
|
|
||||||
|
Sanctum::actingAs(User::factory()->create([
|
||||||
|
'rol_codigo' => RoleCode::AdminApp->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
]));
|
||||||
|
|
||||||
|
$response = $this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/ticket')
|
||||||
|
->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'data' => [
|
||||||
|
'statuses' => [
|
||||||
|
['value' => 'active', 'label' => 'Activo'],
|
||||||
|
['value' => 'used', 'label' => 'Usado'],
|
||||||
|
['value' => 'expired', 'label' => 'Vencido'],
|
||||||
|
],
|
||||||
|
'categories' => [
|
||||||
|
[
|
||||||
|
'value' => 'entradas',
|
||||||
|
'label' => 'Entradas',
|
||||||
|
'products' => [[
|
||||||
|
'value' => 'abono',
|
||||||
|
'label' => 'Abono',
|
||||||
|
'types' => [],
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'alojamientos',
|
||||||
|
'label' => 'Camping',
|
||||||
|
'products' => [
|
||||||
|
['value' => 'Carpa', 'label' => 'Carpa', 'types' => []],
|
||||||
|
['value' => 'Motorhome', 'label' => 'Motorhome', 'types' => []],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'comidas',
|
||||||
|
'label' => 'Comida',
|
||||||
|
'products' => [
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[0]->id,
|
||||||
|
'label' => '09/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[1]->id,
|
||||||
|
'label' => '10/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[2]->id,
|
||||||
|
'label' => '11/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => (string) $tenant->eventDates[3]->id,
|
||||||
|
'label' => '12/10',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Desayuno', 'label' => 'Desayuno'],
|
||||||
|
['value' => 'Almuerzo', 'label' => 'Almuerzo'],
|
||||||
|
['value' => 'Cena', 'label' => 'Cena'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'value' => 'merchandising',
|
||||||
|
'label' => 'Merchandising',
|
||||||
|
'products' => [[
|
||||||
|
'value' => 'camiseta',
|
||||||
|
'label' => 'Camiseta',
|
||||||
|
'types' => [
|
||||||
|
['value' => 'Verde', 'label' => 'Verde'],
|
||||||
|
['value' => 'Blanco', 'label' => 'Blanco'],
|
||||||
|
],
|
||||||
|
]],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertJsonMissingPath('data.categories.0.products.0.category');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "tests/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,9 +60,9 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
->assertJsonValidationErrors(['transfer_payer_dni']);
|
->assertJsonValidationErrors(['transfer_payer_dni']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_transfer_payment_intent_persists_transfer_payer_dni_without_replacing_customer_dni(): void
|
public function test_transfer_payment_intent_persists_data_without_extending_checkout_expiration(): void
|
||||||
{
|
{
|
||||||
config()->set('purchase.payment_expiration_minutes.transfer', 60);
|
config()->set('purchase.checkout_expiration_minutes', 30);
|
||||||
$now = now()->startOfSecond();
|
$now = now()->startOfSecond();
|
||||||
$this->travelTo($now);
|
$this->travelTo($now);
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
$this->assertDatabaseHas('stock_reservations', [
|
$this->assertDatabaseHas('stock_reservations', [
|
||||||
'id' => $purchase->stock_reservation_id,
|
'id' => $purchase->stock_reservation_id,
|
||||||
'status' => 'active',
|
'status' => 'active',
|
||||||
'expires_at' => $now->copy()->addMinutes(60)->toDateTimeString(),
|
'expires_at' => $now->copy()->addMinutes(30)->toDateTimeString(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->travelBack();
|
$this->travelBack();
|
||||||
|
|||||||
@@ -796,12 +796,18 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_updates_customer_data_for_a_pending_payment_purchase(): void
|
public function test_it_updates_customer_data_for_a_pending_payment_purchase(): void
|
||||||
{
|
{
|
||||||
|
config()->set('purchase.checkout_expiration_minutes', 30);
|
||||||
|
$now = now()->startOfSecond();
|
||||||
|
$this->travelTo($now);
|
||||||
|
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
|
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
|
||||||
$purchase->update(['status' => Purchase::STATUS_PENDING_PAYMENT]);
|
$purchase->update(['status' => Purchase::STATUS_PENDING_PAYMENT]);
|
||||||
|
|
||||||
|
$this->travel(10)->minutes();
|
||||||
|
|
||||||
$this->actingAs($user, 'sanctum')
|
$this->actingAs($user, 'sanctum')
|
||||||
->patchJson("/api/tenants/sonder/compras/{$purchase->id}/customer-data", [
|
->patchJson("/api/tenants/sonder/compras/{$purchase->id}/customer-data", [
|
||||||
'dni' => '987654321',
|
'dni' => '987654321',
|
||||||
@@ -818,6 +824,12 @@ class StorePurchaseTest extends TestCase
|
|||||||
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
'dni' => '987654321',
|
'dni' => '987654321',
|
||||||
]);
|
]);
|
||||||
|
$this->assertDatabaseHas('stock_reservations', [
|
||||||
|
'id' => $purchase->stock_reservation_id,
|
||||||
|
'expires_at' => $now->copy()->addMinutes(30)->toDateTimeString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->travelBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_checkout_items_are_immutable_and_editing_routes_are_unavailable(): void
|
public function test_checkout_items_are_immutable_and_editing_routes_are_unavailable(): void
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class MenuSeederTest extends TestCase
|
|||||||
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
'adminapp.ventas' => ['Ventas', '/admin/ventas'],
|
||||||
];
|
];
|
||||||
$fiestaCategoryMenus = [
|
$fiestaCategoryMenus = [
|
||||||
|
'adminapp.tickets' => ['Tickets', '/admin/tickets'],
|
||||||
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
'adminapp.fiesta-futbol-infantil.entradas' => ['Entradas', '/admin/entradas'],
|
||||||
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
'adminapp.fiesta-futbol-infantil.alojamientos' => ['Alojamientos', '/admin/alojamientos'],
|
||||||
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
'adminapp.fiesta-futbol-infantil.merchandising' => ['Merchandising', '/admin/merchandising'],
|
||||||
@@ -49,7 +50,11 @@ class MenuSeederTest extends TestCase
|
|||||||
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $adminApp->content_type);
|
||||||
$this->assertSame('/', $adminApp->route);
|
$this->assertSame('/', $adminApp->route);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
array_keys([...$expectedMenus, ...$fiestaCategoryMenus]),
|
collect(array_keys([
|
||||||
|
...$expectedMenus,
|
||||||
|
...$fiestaCategoryMenus,
|
||||||
|
'adminapp.desfile.entradas' => ['Entradas', '/admin/desfile/entradas'],
|
||||||
|
]))->sort()->values()->all(),
|
||||||
$adminApp->children->pluck('code')->sort()->values()->all()
|
$adminApp->children->pluck('code')->sort()->values()->all()
|
||||||
);
|
);
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
|
|||||||
250
tests/Feature/Ticket/AdminAppTicketControllerTest.php
Normal file
250
tests/Feature/Ticket/AdminAppTicketControllerTest.php
Normal file
@@ -0,0 +1,250 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Ticket;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Catalog\Models\Attribute;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
|
use App\Domains\Shared\Enums\FieldType;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Tenant\Models\WebsiteType;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminAppTicketControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->seed(AuthorizationSeeder::class);
|
||||||
|
WebsiteType::query()->create(['codigo' => 'onticket', 'nombre' => 'OnTicket']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_authentication_is_required(): void
|
||||||
|
{
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')->assertUnauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_tenant_must_have_the_tickets_menu(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')->assertNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_lists_only_tickets_from_the_authenticated_tenant(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$otherTenant = $this->createTenant('other');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$otherUser = $this->createAdminAppUser($otherTenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$ticket = $this->createTicket($tenant, $admin);
|
||||||
|
$this->createTicket($otherTenant, $otherUser);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $ticket->id)
|
||||||
|
->assertJsonPath('data.0.tenant_code', $tenant->codigo)
|
||||||
|
->assertJsonPath('meta.total', 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_supports_id_and_uuid_search(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$matching = $this->createTicket($tenant, $admin);
|
||||||
|
$this->createTicket($tenant, $admin);
|
||||||
|
|
||||||
|
$this->getJson("/api/v1/adminapp/tenant/tickets?q={$matching->id}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $matching->id);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?q='.substr($matching->ticket, 0, 8))
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data')
|
||||||
|
->assertJsonPath('data.0.ticket', $matching->ticket);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_includes_tenant_scanned_and_total_ticket_counts(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$otherTenant = $this->createTenant('other');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$otherUser = $this->createAdminAppUser($otherTenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$this->createTicket($tenant, $admin)->update(['used_at' => now()]);
|
||||||
|
$this->createTicket($tenant, $admin);
|
||||||
|
$this->createTicket($otherTenant, $otherUser)->update(['used_at' => now()]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets?q=does-not-match')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(0, 'data')
|
||||||
|
->assertJsonPath('scanned_tickets', 0)
|
||||||
|
->assertJsonPath('total_tickets', 0);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('scanned_tickets', 1)
|
||||||
|
->assertJsonPath('total_tickets', 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_structured_variant_properties(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$admin = $this->createAdminAppUser($tenant);
|
||||||
|
$this->grantTicketsMenu($tenant);
|
||||||
|
Sanctum::actingAs($admin);
|
||||||
|
|
||||||
|
$item = CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'slug' => 'remera',
|
||||||
|
'nombre' => 'Remera',
|
||||||
|
'precio' => '8000.00',
|
||||||
|
'has_tickets' => true,
|
||||||
|
]);
|
||||||
|
$attribute = Attribute::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'codigo' => 'size',
|
||||||
|
'nombre' => 'Talle',
|
||||||
|
'type' => FieldType::Select,
|
||||||
|
]);
|
||||||
|
$attribute->options()->create(['value' => 'xl', 'label' => 'XL']);
|
||||||
|
$itemAttribute = $item->itemAttributes()->create([
|
||||||
|
'attribute_id' => $attribute->id,
|
||||||
|
'sort_order' => 1,
|
||||||
|
]);
|
||||||
|
$variant = Variant::query()->create([
|
||||||
|
'catalog_item_id' => $item->id,
|
||||||
|
'inventory_id' => Inventory::query()->create()->id,
|
||||||
|
]);
|
||||||
|
$variant->definitions()->create([
|
||||||
|
'item_attribute_id' => $itemAttribute->id,
|
||||||
|
'value' => 'xl',
|
||||||
|
]);
|
||||||
|
$purchase = Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'user_id' => $admin->id,
|
||||||
|
'status' => Purchase::STATUS_PAID,
|
||||||
|
'nombre_apellido' => 'Nombre Apellido',
|
||||||
|
'total' => '8000.00',
|
||||||
|
]);
|
||||||
|
PurchaseItem::query()->create([
|
||||||
|
'compra_id' => $purchase->id,
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
'source_variant_id' => $variant->id,
|
||||||
|
'nombre' => 'Remera',
|
||||||
|
'descripcion' => '',
|
||||||
|
'slug' => 'remera',
|
||||||
|
'item_nombre' => 'Remera',
|
||||||
|
'cantidad' => 1,
|
||||||
|
'precio_unitario' => '8000.00',
|
||||||
|
'total' => '8000.00',
|
||||||
|
]);
|
||||||
|
$ticket = $this->createTicket($tenant, $admin, [
|
||||||
|
'source_purchase_id' => $purchase->id,
|
||||||
|
'source_catalog_item_id' => $item->id,
|
||||||
|
'source_variant_id' => $variant->id,
|
||||||
|
'scanner_user_id' => $admin->id,
|
||||||
|
'used_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.0.id', $ticket->id)
|
||||||
|
->assertJsonPath('data.0.order_number', $purchase->id)
|
||||||
|
->assertJsonPath('data.0.product', 'Remera')
|
||||||
|
->assertJsonPath('data.0.amount', '8000.00')
|
||||||
|
->assertJsonPath('data.0.status', Ticket::STATUS_USED)
|
||||||
|
->assertJsonPath('data.0.scanned_by', $admin->nombre_apellido)
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.code', 'size')
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.label', 'Talle')
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.values.0.value', 'xl')
|
||||||
|
->assertJsonPath('data.0.variant_properties.0.values.0.label', 'XL');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment("{$code}-header.png");
|
||||||
|
$footerLogo = $this->createAttachment("{$code}-footer.png");
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => ucfirst($code),
|
||||||
|
'dominio' => "{$code}.test",
|
||||||
|
'website_type_code' => 'onticket',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAdminAppUser(Tenant $tenant): User
|
||||||
|
{
|
||||||
|
return User::factory()->create([
|
||||||
|
'rol_codigo' => RoleCode::AdminApp->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function grantTicketsMenu(Tenant $tenant): void
|
||||||
|
{
|
||||||
|
$menu = Menu::query()->create([
|
||||||
|
'code' => 'adminapp.tickets',
|
||||||
|
'label' => 'Tickets',
|
||||||
|
'route' => '/admin/tickets',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tenant->menues()->attach($menu->code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param array<string, mixed> $attributes */
|
||||||
|
private function createTicket(Tenant $tenant, User $user, array $attributes = []): Ticket
|
||||||
|
{
|
||||||
|
return Ticket::query()->create(array_merge([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'ticket' => (string) Str::uuid(),
|
||||||
|
'user_id' => $user->id,
|
||||||
|
], $attributes));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,30 @@
|
|||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
use RuntimeException;
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
//
|
/**
|
||||||
|
* Boot the application only when the test database is explicitly isolated.
|
||||||
|
*/
|
||||||
|
public function createApplication(): Application
|
||||||
|
{
|
||||||
|
$app = parent::createApplication();
|
||||||
|
|
||||||
|
$database = (string) $app['config']->get(
|
||||||
|
'database.connections.'.$app['config']->get('database.default').'.database'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! preg_match('/^shopit_(?:test|testing)(?:_\d+)?$/', $database)) {
|
||||||
|
throw new RuntimeException(sprintf(
|
||||||
|
'Refusing to run tests against database [%s]. Use [shopit_test] or [shopit_testing].',
|
||||||
|
$database !== '' ? $database : '(empty)'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $app;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
69
tests/Unit/Purchase/PurchaseResourceTest.php
Normal file
69
tests/Unit/Purchase/PurchaseResourceTest.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit\Purchase;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Models\StockReservation;
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Purchase\Resources\PurchaseResource;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class PurchaseResourceTest extends TestCase
|
||||||
|
{
|
||||||
|
public function test_it_exposes_the_remaining_checkout_time_using_the_server_clock(): void
|
||||||
|
{
|
||||||
|
$now = now()->startOfSecond();
|
||||||
|
$this->travelTo($now);
|
||||||
|
$expiresAt = $now->copy()->addMinutes(12);
|
||||||
|
|
||||||
|
$resource = $this->resourceFor(Purchase::STATUS_PENDING_PAYMENT, $expiresAt);
|
||||||
|
|
||||||
|
$this->assertTrue($expiresAt->equalTo($resource['expires_at']));
|
||||||
|
$this->assertSame(720, $resource['expires_in_seconds']);
|
||||||
|
$this->assertTrue($now->equalTo($resource['server_time']));
|
||||||
|
|
||||||
|
$this->travelBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_clamps_an_overdue_checkout_to_zero_seconds(): void
|
||||||
|
{
|
||||||
|
$now = now()->startOfSecond();
|
||||||
|
$this->travelTo($now);
|
||||||
|
|
||||||
|
$resource = $this->resourceFor(
|
||||||
|
Purchase::STATUS_CREATED,
|
||||||
|
$now->copy()->subSecond(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(0, $resource['expires_in_seconds']);
|
||||||
|
|
||||||
|
$this->travelBack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_exposes_null_expiration_after_the_purchase_enters_review(): void
|
||||||
|
{
|
||||||
|
$resource = $this->resourceFor(
|
||||||
|
Purchase::STATUS_IN_REVIEW,
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertNull($resource['expires_at']);
|
||||||
|
$this->assertNull($resource['expires_in_seconds']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
private function resourceFor(string $status, ?Carbon $expiresAt): array
|
||||||
|
{
|
||||||
|
$purchase = (new Purchase)->forceFill([
|
||||||
|
'status' => $status,
|
||||||
|
'total' => '0.00',
|
||||||
|
]);
|
||||||
|
$purchase->setRelation('stockReservation', (new StockReservation)->forceFill([
|
||||||
|
'status' => StockReservation::STATUS_ACTIVE,
|
||||||
|
'expires_at' => $expiresAt,
|
||||||
|
]));
|
||||||
|
|
||||||
|
return (new PurchaseResource($purchase))->toArray(Request::create('/'));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user