feat(tickets): group user tickets by event

This commit is contained in:
2026-09-22 12:26:16 -03:00
parent 6efe8439c7
commit 3401c934b2
12 changed files with 289 additions and 20 deletions

View File

@@ -2,18 +2,20 @@
namespace Tests\Feature\Ticket;
use App\Shared\Attachable\Enums\AttachmentType;
use App\Shared\Attachable\Models\Attachment;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Commerce\Catalog\Models\Attribute;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Models\Inventory;
use App\Domains\Core\Auth\Models\User;
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Events\EventDateRescheduled;
use App\Domains\Ticketing\Event\Events\EventDateSuspended;
use App\Domains\Ticketing\Event\Models\Event as TicketEvent;
use App\Domains\Ticketing\Event\Models\EventDate;
use App\Domains\Ticketing\Event\Services\EventService;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Ticket\Models\Ticket;
use App\Shared\Attachable\Enums\AttachmentType;
use App\Shared\Attachable\Models\Attachment;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Str;
@@ -164,6 +166,59 @@ class TicketControllerTest extends TestCase
->assertJsonPath('data.0.id', $visibleTicket->id);
}
public function test_a_multi_event_user_can_list_only_events_with_their_tickets(): void
{
StorefrontWebsiteType::query()->create([
'codigo' => 'onticket_multi_event',
'nombre' => 'OnTicket multi event',
'header_type' => 'standard',
]);
$tenant = $this->createTenant('multi');
$tenant->update(['storefront_website_type_code' => 'onticket_multi_event']);
$otherTenant = $this->createTenant('other');
$user = User::factory()->create();
$otherUser = User::factory()->create();
$firstEvent = $this->createEvent($tenant, 'First event');
$secondEvent = $this->createEvent($tenant, 'Second event');
$eventWithoutTickets = $this->createEvent($tenant, 'No tickets');
$otherTenantEvent = $this->createEvent($otherTenant, 'Other tenant event');
$this->createTicket($tenant, $user, 'First ticket')->update(['event_id' => $firstEvent->id]);
$this->createTicket($tenant, $user, 'Second ticket')->update(['event_id' => $secondEvent->id]);
$this->createTicket($tenant, $otherUser, 'Other user')->update(['event_id' => $eventWithoutTickets->id]);
$this->createTicket($otherTenant, $user, 'Other tenant')->update(['event_id' => $otherTenantEvent->id]);
$this->actingAs($user, 'sanctum')
->getJson("/api/tenants/{$tenant->codigo}/tickets/events")
->assertOk()
->assertJsonCount(2, 'data')
->assertJsonPath('data.0.id', $secondEvent->id)
->assertJsonPath('data.0.title', 'Second event')
->assertJsonPath('data.1.id', $firstEvent->id)
->assertJsonMissing(['title' => 'No tickets'])
->assertJsonMissing(['title' => 'Other tenant event']);
}
public function test_a_user_can_filter_their_tickets_by_event(): void
{
$tenant = $this->createTenant('multi');
$user = User::factory()->create();
$firstEvent = $this->createEvent($tenant, 'First event');
$secondEvent = $this->createEvent($tenant, 'Second event');
$visibleTicket = $this->createTicket($tenant, $user, 'Visible ticket');
$visibleTicket->update(['event_id' => $firstEvent->id]);
$hiddenTicket = $this->createTicket($tenant, $user, 'Hidden ticket');
$hiddenTicket->update(['event_id' => $secondEvent->id]);
$this->actingAs($user, 'sanctum')
->getJson("/api/tenants/{$tenant->codigo}/tickets?event_id={$firstEvent->id}")
->assertOk()
->assertJsonCount(1, 'data')
->assertJsonPath('data.0.id', $visibleTicket->id)
->assertJsonPath('data.0.event_id', $firstEvent->id)
->assertJsonMissing(['id' => $hiddenTicket->id]);
}
public function test_authentication_is_required_to_list_tickets(): void
{
$tenant = $this->createTenant('current');
@@ -248,6 +303,16 @@ class TicketControllerTest extends TestCase
]);
}
private function createEvent(Tenant $tenant, string $title): TicketEvent
{
return TicketEvent::query()->create([
'tenant_code' => $tenant->codigo,
'slug' => Str::slug($title).'-'.Str::lower(Str::random(8)),
'title' => $title,
'published_at' => now(),
]);
}
private function createAttachment(string $name): Attachment
{
return Attachment::query()->create([