89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Event;
|
|
|
|
use App\Domains\Core\Tenant\Models\Tenant;
|
|
use App\Domains\Ticketing\Event\Models\Event;
|
|
use App\Shared\Attachable\Enums\AttachmentType;
|
|
use App\Shared\Attachable\Models\Attachment;
|
|
use Database\Seeders\WebsiteTypeSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Str;
|
|
use Tests\TestCase;
|
|
|
|
class PublicEventControllerTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_it_resolves_an_event_by_slug_within_its_tenant(): void
|
|
{
|
|
$this->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',
|
|
]);
|
|
}
|
|
}
|