feat(ticket): add refundable terminal states

This commit is contained in:
2026-09-10 16:10:08 -03:00
parent 1564985259
commit 18f739b712
5 changed files with 208 additions and 3 deletions

View File

@@ -31,6 +31,9 @@ class TicketTest extends TestCase
'source_catalog_item_id' => '20',
'source_variant_id' => '30',
'used_at' => null,
'disabled_at' => '2026-09-10 10:00:00',
'cancelled_at' => null,
'refunded_at' => null,
'scanner_user_id' => '15',
'user_id' => '10',
]);
@@ -40,6 +43,9 @@ class TicketTest extends TestCase
$this->assertSame(20, $ticket->source_catalog_item_id);
$this->assertSame(30, $ticket->source_variant_id);
$this->assertNull($ticket->used_at);
$this->assertSame('2026-09-10 10:00:00', $ticket->disabled_at->format('Y-m-d H:i:s'));
$this->assertNull($ticket->cancelled_at);
$this->assertNull($ticket->refunded_at);
$this->assertSame(15, $ticket->scanner_user_id);
$this->assertSame(10, $ticket->user_id);
$this->assertInstanceOf(Tenant::class, $ticket->tenant()->getRelated());
@@ -154,6 +160,48 @@ class TicketTest extends TestCase
$this->assertSame(Ticket::STATUS_USED, $ticket->status);
}
public function test_persisted_terminal_statuses_make_the_ticket_invalid(): void
{
foreach ([
'disabled_at' => Ticket::STATUS_DISABLED,
'cancelled_at' => Ticket::STATUS_CANCELLED,
'refunded_at' => Ticket::STATUS_REFUNDED,
] as $timestamp => $status) {
$ticket = new Ticket([$timestamp => now()]);
$this->assertSame($status, $ticket->status);
$this->assertFalse($ticket->is_valid);
$this->assertFalse($ticket->is_expired);
}
}
public function test_it_exposes_every_supported_status(): void
{
$this->assertSame([
Ticket::STATUS_ACTIVE,
Ticket::STATUS_USED,
Ticket::STATUS_EXPIRED,
Ticket::STATUS_DISABLED,
Ticket::STATUS_CANCELLED,
Ticket::STATUS_REFUNDED,
], Ticket::statuses());
$this->assertSame('Inhabilitado', Ticket::statusLabel(Ticket::STATUS_DISABLED));
$this->assertSame('Cancelado', Ticket::statusLabel(Ticket::STATUS_CANCELLED));
$this->assertSame('Reembolsado', Ticket::statusLabel(Ticket::STATUS_REFUNDED));
}
public function test_refunded_has_priority_when_multiple_state_timestamps_exist(): void
{
$ticket = new Ticket([
'disabled_at' => now()->subHours(2),
'cancelled_at' => now()->subHour(),
'refunded_at' => now(),
]);
$this->assertSame(Ticket::STATUS_REFUNDED, $ticket->status);
}
public function test_all_validity_times_in_the_same_group_must_be_active(): void
{
Carbon::setTestNow('2026-08-20 13:00:00');