diff --git a/app/Domains/Ticketing/Event/Models/Event.php b/app/Domains/Ticketing/Event/Models/Event.php index e31c9ca..5ca611e 100644 --- a/app/Domains/Ticketing/Event/Models/Event.php +++ b/app/Domains/Ticketing/Event/Models/Event.php @@ -2,9 +2,9 @@ namespace App\Domains\Ticketing\Event\Models; +use App\Domains\Commerce\Catalog\Models\CatalogItem; use App\Domains\Core\Tenant\Models\SocialMedia; use App\Domains\Core\Tenant\Models\Tenant; -use App\Domains\Commerce\Catalog\Models\CatalogItem; use App\Shared\Attachable\Models\Attachment; use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; diff --git a/app/Domains/Ticketing/Event/Resources/EventResource.php b/app/Domains/Ticketing/Event/Resources/EventResource.php index 29ff0b3..16f802a 100644 --- a/app/Domains/Ticketing/Event/Resources/EventResource.php +++ b/app/Domains/Ticketing/Event/Resources/EventResource.php @@ -2,8 +2,8 @@ namespace App\Domains\Ticketing\Event\Resources; -use App\Domains\Ticketing\Event\Services\EventDateGroupingService; use App\Domains\Ticketing\Event\Models\Event; +use App\Domains\Ticketing\Event\Services\EventDateGroupingService; use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; diff --git a/database/migrations/2026_09_22_010000_add_slugs_to_events.php b/database/migrations/2026_09_22_010000_add_slugs_to_events.php index 4fbb077..0b0781c 100644 --- a/database/migrations/2026_09_22_010000_add_slugs_to_events.php +++ b/database/migrations/2026_09_22_010000_add_slugs_to_events.php @@ -11,14 +11,14 @@ return new class extends Migration public function up(): void { Schema::table('events', function (Blueprint $table): void { - $table->string('slug')->nullable()->after('tenant_code'); + $table->string('slug')->nullable(); }); $usedSlugsByTenant = []; foreach (DB::table('events')->orderBy('tenant_code')->orderBy('id')->get() as $event) { $baseSlug = Str::slug((string) $event->title); - $baseSlug = $baseSlug !== '' ? mb_substr($baseSlug, 0, 240) : 'evento-'.$event->id; + $baseSlug = $baseSlug !== '' ? substr($baseSlug, 0, 240) : 'evento-'.$event->id; $slug = $baseSlug; $suffix = 2; diff --git a/tests/Feature/Event/PublicEventControllerTest.php b/tests/Feature/Event/PublicEventControllerTest.php new file mode 100644 index 0000000..0511204 --- /dev/null +++ b/tests/Feature/Event/PublicEventControllerTest.php @@ -0,0 +1,88 @@ +seed(WebsiteTypeSeeder::class); + $firstTenant = $this->createTenant('first'); + $secondTenant = $this->createTenant('second'); + + Event::query()->create([ + 'tenant_code' => $firstTenant->codigo, + 'slug' => 'gran-fiesta', + 'title' => 'Fiesta del primer tenant', + 'published_at' => now()->subMinute(), + ]); + Event::query()->create([ + 'tenant_code' => $secondTenant->codigo, + 'slug' => 'gran-fiesta', + 'title' => 'Fiesta del segundo tenant', + 'published_at' => now()->subMinute(), + ]); + + $this->getJson('/api/tenants/second/events/gran-fiesta') + ->assertOk() + ->assertJsonPath('data.slug', 'gran-fiesta') + ->assertJsonPath('data.title', 'Fiesta del segundo tenant'); + } + + public function test_it_does_not_resolve_the_old_numeric_event_url(): void + { + $this->seed(WebsiteTypeSeeder::class); + $tenant = $this->createTenant('acme'); + $event = Event::query()->create([ + 'tenant_code' => $tenant->codigo, + 'slug' => 'gran-fiesta', + 'title' => 'Gran Fiesta', + 'published_at' => now()->subMinute(), + ]); + + $this->getJson("/api/tenants/acme/events/{$event->id}")->assertNotFound(); + } + + private function createTenant(string $code): Tenant + { + $header = $this->createAttachment($code.'-header'); + $footer = $this->createAttachment($code.'-footer'); + + return Tenant::query()->create([ + 'codigo' => $code, + 'nombre' => ucfirst($code), + 'dominio' => $code.'.test', + 'storefront_website_type_code' => 'onticket_multi_event', + 'primary_color' => '#000000', + 'secondary_color' => '#000000', + 'danger_color' => '#000000', + 'success_color' => '#000000', + 'header_bg_color' => '#000000', + 'footer_bg_color' => '#000000', + 'header_logo_id' => $header->id, + 'footer_logo_id' => $footer->id, + ]); + } + + private function createAttachment(string $name): Attachment + { + return Attachment::query()->create([ + 'key' => (string) Str::uuid(), + 'path' => 'test/'.$name.'.png', + 'filename' => $name.'.png', + 'type' => AttachmentType::Image, + 'mime_type' => 'image/png', + ]); + } +} diff --git a/tests/Feature/Migrations/AddSlugsToEventsTest.php b/tests/Feature/Migrations/AddSlugsToEventsTest.php new file mode 100644 index 0000000..00328dc --- /dev/null +++ b/tests/Feature/Migrations/AddSlugsToEventsTest.php @@ -0,0 +1,37 @@ +id(); + $table->string('tenant_code'); + $table->string('title'); + }); + + DB::table('events')->insert([ + ['id' => 1, 'tenant_code' => 'acme', 'title' => 'Gran Fiesta'], + ['id' => 2, 'tenant_code' => 'acme', 'title' => 'Gran Fiesta'], + ['id' => 3, 'tenant_code' => 'other', 'title' => 'Gran Fiesta'], + ['id' => 4, 'tenant_code' => 'acme', 'title' => '---'], + ]); + + $migration = require database_path('migrations/2026_09_22_010000_add_slugs_to_events.php'); + $migration->up(); + + $this->assertSame([ + 1 => 'gran-fiesta', + 2 => 'gran-fiesta-2', + 3 => 'gran-fiesta', + 4 => 'evento-4', + ], DB::table('events')->orderBy('id')->pluck('slug', 'id')->all()); + } +}