feat(tickets): add TicketFormController, TicketFormService, and TicketFormResource with related routes and tests
This commit is contained in:
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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -8,17 +8,22 @@ use RuntimeException;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Boot the application only when the test database is explicitly isolated.
|
||||
*/
|
||||
public function createApplication(): Application
|
||||
{
|
||||
$app = parent::createApplication();
|
||||
$connection = (string) $app['config']->get('database.default');
|
||||
$database = (string) $app['config']->get("database.connections.{$connection}.database");
|
||||
$usesInMemorySqlite = $connection === 'sqlite' && $database === ':memory:';
|
||||
|
||||
if (! $usesInMemorySqlite && ! str_ends_with(strtolower($database), '_test')) {
|
||||
throw new RuntimeException(
|
||||
"Unsafe test database [{$database}]. Tests may only use an in-memory SQLite database or a database ending in _test.",
|
||||
);
|
||||
$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;
|
||||
|
||||
Reference in New Issue
Block a user