feat(forms): add desfile entry reservation form
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Shared\Forms\Controllers\AdminApp;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Shared\Forms\Resources\DesfileEntryReservationFormResource;
|
||||||
|
use App\Shared\Forms\Services\DesfileEntryReservationFormService;
|
||||||
|
|
||||||
|
class DesfileEntryReservationFormController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly DesfileEntryReservationFormService $formService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function __invoke(): DesfileEntryReservationFormResource
|
||||||
|
{
|
||||||
|
return DesfileEntryReservationFormResource::make($this->formService->get());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Shared\Forms\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class DesfileEntryReservationFormResource extends JsonResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'payment_types' => $this->resource['payment_types'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Shared\Forms\Services;
|
||||||
|
|
||||||
|
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
||||||
|
|
||||||
|
class DesfileEntryReservationFormService
|
||||||
|
{
|
||||||
|
/** @return array{payment_types: list<array{value: string, label: string}>} */
|
||||||
|
public function get(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'payment_types' => EntryReservationPaymentType::options(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Shared\Forms\Controllers\AdminApp\DesfileEntryReservationFormController;
|
||||||
use App\Shared\Forms\Controllers\AdminApp\EntryFormController;
|
use App\Shared\Forms\Controllers\AdminApp\EntryFormController;
|
||||||
use App\Shared\Forms\Controllers\AdminApp\EventFormController;
|
use App\Shared\Forms\Controllers\AdminApp\EventFormController;
|
||||||
use App\Shared\Forms\Controllers\AdminApp\FoodFormController;
|
use App\Shared\Forms\Controllers\AdminApp\FoodFormController;
|
||||||
@@ -14,6 +15,11 @@ Route::prefix('v1/adminapp/forms')
|
|||||||
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
->middleware(['auth:sanctum', 'adminapp.tenant'])
|
||||||
->group(function (): void {
|
->group(function (): void {
|
||||||
Route::get('event', EventFormController::class);
|
Route::get('event', EventFormController::class);
|
||||||
|
Route::get(
|
||||||
|
'desfile/entry-reservation',
|
||||||
|
DesfileEntryReservationFormController::class
|
||||||
|
)->middleware('tenant.menu:adminapp.desfile.reservas')
|
||||||
|
->name('adminapp.forms.desfile.entry-reservation');
|
||||||
Route::get('sale', SaleFormController::class);
|
Route::get('sale', SaleFormController::class);
|
||||||
Route::get('staff', StaffFormController::class);
|
Route::get('staff', StaffFormController::class);
|
||||||
Route::get('tickets-filter', TicketFilterFormController::class)
|
Route::get('tickets-filter', TicketFilterFormController::class)
|
||||||
|
|||||||
@@ -130,6 +130,12 @@ class MenuSeeder extends Seeder
|
|||||||
'parent_menu_code' => 'main.adminapp',
|
'parent_menu_code' => 'main.adminapp',
|
||||||
'route' => '/admin/desfile/entradas',
|
'route' => '/admin/desfile/entradas',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'code' => 'adminapp.desfile.reservas',
|
||||||
|
'label' => 'Reserva de Tickets',
|
||||||
|
'parent_menu_code' => 'main.adminapp',
|
||||||
|
'route' => '/admin/desfile/reservas',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'code' => 'account',
|
'code' => 'account',
|
||||||
'label' => 'Mi cuenta',
|
'label' => 'Mi cuenta',
|
||||||
@@ -306,6 +312,7 @@ class MenuSeeder extends Seeder
|
|||||||
];
|
];
|
||||||
$desfileMenuCodes = [
|
$desfileMenuCodes = [
|
||||||
'adminapp.desfile.entradas',
|
'adminapp.desfile.entradas',
|
||||||
|
'adminapp.desfile.reservas',
|
||||||
];
|
];
|
||||||
$onTicketMenuCodes = [
|
$onTicketMenuCodes = [
|
||||||
'event.index',
|
'event.index',
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Forms;
|
||||||
|
|
||||||
|
use App\Domains\Core\Auth\Models\User;
|
||||||
|
use App\Domains\Core\Authorization\Enums\RoleCode;
|
||||||
|
use App\Domains\Core\Menu\Models\Menu;
|
||||||
|
use App\Domains\Core\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\AuthorizationSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AdminAppDesfileEntryReservationFormControllerTest 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/desfile/entry-reservation')
|
||||||
|
->assertUnauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_the_tenant_must_have_the_reservations_menu(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('without_reservations');
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/forms/desfile/entry-reservation')
|
||||||
|
->assertNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_only_returns_the_available_payment_types(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('desfile_pura_tendencia');
|
||||||
|
$this->grantReservationsMenu($tenant);
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
$this->getJson('/api/v1/adminapp/forms/desfile/entry-reservation')
|
||||||
|
->assertOk()
|
||||||
|
->assertExactJson([
|
||||||
|
'data' => [
|
||||||
|
'payment_types' => [
|
||||||
|
['value' => 'sin_cargo', 'label' => 'Sin cargo'],
|
||||||
|
['value' => 'otro_metodo', 'label' => 'Otro método'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => str($code)->headline(),
|
||||||
|
'dominio' => "{$code}.test",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAdminAppUser(Tenant $tenant): User
|
||||||
|
{
|
||||||
|
return User::factory()->create([
|
||||||
|
'rol_codigo' => RoleCode::AdminApp->value,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function grantReservationsMenu(Tenant $tenant): void
|
||||||
|
{
|
||||||
|
$menu = Menu::query()->create([
|
||||||
|
'code' => 'adminapp.desfile.reservas',
|
||||||
|
'label' => 'Reserva de Tickets',
|
||||||
|
'route' => '/admin/desfile/reservas',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tenant->menues()->attach($menu->code);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user