83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Forms;
|
|
|
|
use App\Domains\Auth\Models\User;
|
|
use App\Domains\Authorization\Enums\RoleCode;
|
|
use App\Domains\Event\Models\EventDate;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use App\Domains\Tenant\Models\WebsiteType;
|
|
use Database\Seeders\AuthorizationSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Laravel\Sanctum\Sanctum;
|
|
use Tests\TestCase;
|
|
|
|
class AdminAppEntryFormControllerTest 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/forms/fiesta-futbol-infantil/entry')
|
|
->assertUnauthorized();
|
|
}
|
|
|
|
public function test_it_returns_only_selectable_event_dates_for_the_tenant(): void
|
|
{
|
|
$tenant = $this->createTenant('fiesta');
|
|
$otherTenant = $this->createTenant('other');
|
|
$available = $this->createEventDate($tenant, '2026-10-09');
|
|
$rescheduled = $this->createEventDate($tenant, '2026-10-10');
|
|
$replacement = $this->createEventDate($tenant, '2026-10-11');
|
|
$rescheduled->update(['rescheduled_to_event_date_id' => $replacement->id]);
|
|
$this->createEventDate($tenant, '2026-10-12', ['suspended_at' => now()]);
|
|
$this->createEventDate($otherTenant, '2026-10-13');
|
|
|
|
Sanctum::actingAs(User::factory()->create([
|
|
'rol_codigo' => RoleCode::AdminApp->value,
|
|
'tenant_codigo' => $tenant->codigo,
|
|
]));
|
|
|
|
$this->getJson('/api/v1/adminapp/forms/fiesta-futbol-infantil/entry')
|
|
->assertOk()
|
|
->assertJsonCount(2, 'data.event_dates')
|
|
->assertJsonFragment(['id' => $available->id, 'date' => '2026-10-09'])
|
|
->assertJsonFragment(['id' => $replacement->id, 'date' => '2026-10-11'])
|
|
->assertJsonMissing(['date' => '2026-10-10'])
|
|
->assertJsonMissing(['date' => '2026-10-12'])
|
|
->assertJsonMissing(['date' => '2026-10-13']);
|
|
}
|
|
|
|
private function createTenant(string $code): Tenant
|
|
{
|
|
return Tenant::query()->create([
|
|
'codigo' => $code,
|
|
'nombre' => ucfirst($code),
|
|
'dominio' => "{$code}.test",
|
|
'website_type_code' => 'onticket',
|
|
]);
|
|
}
|
|
|
|
/** @param array<string, mixed> $overrides */
|
|
private function createEventDate(
|
|
Tenant $tenant,
|
|
string $date,
|
|
array $overrides = []
|
|
): EventDate {
|
|
return $tenant->eventDates()->create([
|
|
'date' => $date,
|
|
'time_start' => '00:00',
|
|
'time_end' => '23:59',
|
|
...$overrides,
|
|
]);
|
|
}
|
|
}
|