test(events): add explicit OnTicket demo event seeder

This commit is contained in:
2026-09-18 14:33:35 -03:00
parent f6e8716218
commit 801d25b218
5 changed files with 152 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
<?php
namespace Database\Seeders;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Shared\Attachable\Services\AttachmentService;
use Illuminate\Database\Seeder;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use RuntimeException;
class TestEventsSeeder extends Seeder
{
public function __construct(private readonly AttachmentService $attachmentService) {}
public function run(): void
{
$tenant = Tenant::query()->where('codigo', 'onticket')->firstOrFail();
$events = [
[
'title' => '[Prueba] Noche de Música en Vivo',
'subtitle' => 'Una noche para cantar y bailar',
'description' => 'Evento de prueba para explorar la cartelera de OnTicket.',
'location' => 'Teatro Broadway, Rosario',
'image' => 'live-music.png',
'weeks_from_now' => [2],
'time_start' => '21:00:00',
'time_end' => '23:30:00',
],
[
'title' => '[Prueba] Festival de Sabores',
'subtitle' => 'Gastronomía y música para toda la familia',
'description' => 'Evento de prueba con dos jornadas disponibles.',
'location' => 'Parque de España, Rosario',
'image' => 'food-festival.png',
'weeks_from_now' => [3, 3],
'day_offsets' => [0, 1],
'time_start' => '12:00:00',
'time_end' => '20:00:00',
],
[
'title' => '[Prueba] Stand Up en el Centro',
'subtitle' => 'Humor para compartir',
'description' => 'Evento de prueba para visualizar distintas propuestas.',
'location' => 'Centro Cultural La Comedia, Rosario',
'image' => 'stand-up.png',
'weeks_from_now' => [4],
'time_start' => '20:30:00',
'time_end' => '22:00:00',
],
];
DB::transaction(function () use ($tenant, $events): void {
foreach ($events as $definition) {
$event = $tenant->events()->firstOrCreate(
['title' => $definition['title']],
[
'subtitle' => $definition['subtitle'],
'description' => $definition['description'],
'location' => $definition['location'],
'published_at' => now(),
],
);
if ($event->attachment_id === null) {
$path = public_path('images/tennants/onticket/test-events/'.$definition['image']);
if (! is_file($path)) {
throw new RuntimeException("Image not found at path: {$path}");
}
$attachment = $this->attachmentService->store(
new UploadedFile($path, $definition['image'], 'image/png', null, true),
'tenants/onticket/events',
);
$event->update(['attachment_id' => $attachment->id]);
}
if ($event->dates()->exists()) {
continue;
}
foreach ($definition['weeks_from_now'] as $index => $weeks) {
$date = now()->startOfDay()->addWeeks($weeks)
->addDays($definition['day_offsets'][$index] ?? 0);
$event->dates()->create([
'tenant_code' => $tenant->codigo,
'date' => $date->toDateString(),
'time_start' => $definition['time_start'],
'time_end' => $definition['time_end'],
]);
}
}
});
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@@ -0,0 +1,54 @@
<?php
namespace Tests\Feature\Seeders;
use App\Domains\Core\Tenant\Models\Tenant;
use Database\Seeders\SocialMediaSeeder;
use Database\Seeders\TenantSeeder;
use Database\Seeders\TestEventsSeeder;
use Database\Seeders\WebsiteTypeSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
class TestEventsSeederTest extends TestCase
{
use RefreshDatabase;
public function test_it_creates_published_future_events_only_when_run_explicitly_and_does_not_duplicate_them(): void
{
Storage::fake('s3');
$this->seed([WebsiteTypeSeeder::class, SocialMediaSeeder::class, TenantSeeder::class]);
$tenant = Tenant::query()->where('codigo', 'onticket')->sole();
$this->assertCount(0, $tenant->events);
$this->seed(TestEventsSeeder::class);
$events = $tenant->events()->with('dates.validityTime')->get();
$this->assertCount(3, $events);
$this->assertSame(4, $events->sum(fn ($event): int => $event->dates->count()));
foreach ($events as $event) {
$this->assertTrue($event->published_at->isPast());
$this->assertNotNull($event->date_text);
$this->assertNotNull($event->attachment_id);
Storage::disk('s3')->assertExists($event->attachment->path);
foreach ($event->dates as $date) {
$this->assertTrue($date->startsAt()->isFuture());
$this->assertNotNull($date->validityTime);
}
}
$this->seed(TestEventsSeeder::class);
$this->assertCount(3, $tenant->events()->get());
$this->assertCount(4, $tenant->eventDates()->get());
$this->assertSame(
$events->pluck('attachment_id')->all(),
$tenant->events()->orderBy('id')->pluck('attachment_id')->all(),
);
}
}