feat(ticket): enhance ticket name resolution to follow event date reschedules
This commit is contained in:
@@ -5,12 +5,17 @@ namespace Tests\Feature\Ticket;
|
||||
use App\Domains\Attachable\Enums\AttachmentType;
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Auth\Models\User;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Inventory;
|
||||
use App\Domains\Event\Events\EventDateRescheduled;
|
||||
use App\Domains\Event\Events\EventDateSuspended;
|
||||
use App\Domains\Event\Models\EventDate;
|
||||
use App\Domains\Event\Services\EventService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Models\Ticket;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Str;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -18,6 +23,72 @@ class TicketControllerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_ticket_names_follow_reschedules_without_changing_variant_selections(): void
|
||||
{
|
||||
Event::fake([EventDateRescheduled::class, EventDateSuspended::class]);
|
||||
$tenant = $this->createTenant('rescheduled');
|
||||
$user = User::factory()->create();
|
||||
$ticket = $this->createTicket($tenant, $user, 'COMIDA');
|
||||
$item = $ticket->sourceCatalogItem;
|
||||
$attribute = Attribute::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'service',
|
||||
'nombre' => 'Servicio',
|
||||
'type' => 'string',
|
||||
]);
|
||||
$itemAttribute = $item->itemAttributes()->create([
|
||||
'attribute_id' => $attribute->id,
|
||||
'ticket_label' => 'Servicio',
|
||||
]);
|
||||
$source = $tenant->eventDates()->create([
|
||||
'date' => '2026-10-29',
|
||||
'time_start' => '08:00:00',
|
||||
'time_end' => '10:00:00',
|
||||
]);
|
||||
$variant = $item->variants()->create([
|
||||
'event_date_id' => $source->id,
|
||||
'inventory_id' => Inventory::query()->create()->id,
|
||||
]);
|
||||
$variant->definitions()->create([
|
||||
'item_attribute_id' => $itemAttribute->id,
|
||||
'value' => 'COMEDOR',
|
||||
]);
|
||||
$ticket->update(['source_variant_id' => $variant->id]);
|
||||
|
||||
foreach (['29/10/2026', '02/11/2026', '05/11/2026'] as $step => $expectedDate) {
|
||||
if ($step > 0) {
|
||||
$previous = $step === 1 ? $source : $tenant->eventDates()->whereDate('date', '2026-11-02')->firstOrFail();
|
||||
app(EventService::class)->rescheduleDateForTenant($tenant, $previous, [
|
||||
'date' => $step === 1 ? '2026-11-02' : '2026-11-05',
|
||||
]);
|
||||
}
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson("/api/tenants/{$tenant->codigo}/tickets")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.name', "COMIDA ({$expectedDate}, Servicio COMEDOR)")
|
||||
->assertJsonPath('data.0.ticket', $ticket->ticket);
|
||||
}
|
||||
|
||||
$destination = $tenant->eventDates()->whereDate('date', '2026-11-05')->firstOrFail();
|
||||
$variant->eventDates()->sync([$source->id, $destination->id]);
|
||||
$this->assertSame('COMIDA (05/11/2026, Servicio COMEDOR)', $ticket->fresh()->name);
|
||||
$this->assertSame('29/10/2026', $variant->fresh()->selectionOptions()->get('event_date')[0]['label']);
|
||||
$this->assertSame($source->id, $variant->fresh()->event_date_id);
|
||||
|
||||
app(EventService::class)->suspendDateForTenant($tenant, $destination);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson("/api/tenants/{$tenant->codigo}/tickets")
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.name', 'COMIDA (05/11/2026, Servicio COMEDOR)')
|
||||
->assertJsonPath('data.0.status', 'disabled')
|
||||
->assertJsonPath('data.0.is_valid', false)
|
||||
->assertJsonPath('data.0.starts_at', null)
|
||||
->assertJsonPath('data.0.expires_at', null)
|
||||
->assertJsonPath('data.0.ticket', $ticket->ticket);
|
||||
}
|
||||
|
||||
public function test_an_authenticated_user_can_list_their_tickets_for_the_tenant(): void
|
||||
{
|
||||
$tenant = $this->createTenant('current');
|
||||
|
||||
Reference in New Issue
Block a user