diff --git a/app/Domains/Ticket/Models/Ticket.php b/app/Domains/Ticket/Models/Ticket.php index f93fac1..ee151aa 100644 --- a/app/Domains/Ticket/Models/Ticket.php +++ b/app/Domains/Ticket/Models/Ticket.php @@ -150,6 +150,51 @@ class Ticket extends Model return $this->allow_refund(); } + public function is_active(): bool + { + return $this->status === self::STATUS_ACTIVE; + } + + public function isActive(): bool + { + return $this->is_active(); + } + + public function getIsActiveAttribute(): bool + { + return $this->is_active(); + } + + public function can_cancel(): bool + { + return $this->is_active(); + } + + public function canCancel(): bool + { + return $this->can_cancel(); + } + + public function getCanCancelAttribute(): bool + { + return $this->can_cancel(); + } + + public function can_refund(): bool + { + return $this->is_active() && $this->allow_refund(); + } + + public function canRefund(): bool + { + return $this->can_refund(); + } + + public function getCanRefundAttribute(): bool + { + return $this->can_refund(); + } + /** @return BelongsTo */ public function user(): BelongsTo { diff --git a/app/Domains/Ticket/Resources/AdminApp/AdminAppTicketResource.php b/app/Domains/Ticket/Resources/AdminApp/AdminAppTicketResource.php index bef2479..cae2bd1 100644 --- a/app/Domains/Ticket/Resources/AdminApp/AdminAppTicketResource.php +++ b/app/Domains/Ticket/Resources/AdminApp/AdminAppTicketResource.php @@ -20,6 +20,9 @@ class AdminAppTicketResource extends TicketResource ...parent::toArray($request), ...$details, 'allow_refund' => $this->resource->allow_refund(), + 'is_active' => $this->resource->is_active(), + 'can_cancel' => $this->resource->can_cancel(), + 'can_refund' => $this->resource->can_refund(), 'values' => $rowService->values($this->resource, $details), ]; } diff --git a/tests/Feature/Ticket/AdminAppTicketControllerTest.php b/tests/Feature/Ticket/AdminAppTicketControllerTest.php index a959bba..284ea5f 100644 --- a/tests/Feature/Ticket/AdminAppTicketControllerTest.php +++ b/tests/Feature/Ticket/AdminAppTicketControllerTest.php @@ -74,6 +74,9 @@ class AdminAppTicketControllerTest extends TestCase ->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE) ->assertJsonPath('data.0.status_label', 'Activo') ->assertJsonPath('data.0.allow_refund', false) + ->assertJsonPath('data.0.is_active', true) + ->assertJsonPath('data.0.can_cancel', true) + ->assertJsonPath('data.0.can_refund', false) ->assertJsonMissingPath('data.0.values.ticket') ->assertJsonPath('data.0.values.date', '-') ->assertJsonPath('data.0.values.size', '-') @@ -93,13 +96,15 @@ class AdminAppTicketControllerTest extends TestCase // Default: neither total nor partial refund allowed $this->getJson('/api/v1/adminapp/tenant/tickets') ->assertOk() - ->assertJsonPath('data.0.allow_refund', false); + ->assertJsonPath('data.0.allow_refund', false) + ->assertJsonPath('data.0.can_refund', false); // Total refund allowed $tenant->update(['allow_ticket_total_refund' => true]); $this->getJson('/api/v1/adminapp/tenant/tickets') ->assertOk() - ->assertJsonPath('data.0.allow_refund', true); + ->assertJsonPath('data.0.allow_refund', true) + ->assertJsonPath('data.0.can_refund', true); // Partial refund allowed with percentage set $tenant->update([ @@ -109,7 +114,8 @@ class AdminAppTicketControllerTest extends TestCase ]); $this->getJson('/api/v1/adminapp/tenant/tickets') ->assertOk() - ->assertJsonPath('data.0.allow_refund', true); + ->assertJsonPath('data.0.allow_refund', true) + ->assertJsonPath('data.0.can_refund', true); // Partial refund enabled but percentage is 0 $tenant->update([ @@ -117,7 +123,8 @@ class AdminAppTicketControllerTest extends TestCase ]); $this->getJson('/api/v1/adminapp/tenant/tickets') ->assertOk() - ->assertJsonPath('data.0.allow_refund', false); + ->assertJsonPath('data.0.allow_refund', false) + ->assertJsonPath('data.0.can_refund', false); } public function test_it_cancels_a_ticket_from_the_authenticated_tenant(): void diff --git a/tests/Unit/Ticket/TicketTest.php b/tests/Unit/Ticket/TicketTest.php index a71541a..d473104 100644 --- a/tests/Unit/Ticket/TicketTest.php +++ b/tests/Unit/Ticket/TicketTest.php @@ -64,6 +64,24 @@ class TicketTest extends TestCase $this->assertSame(Ticket::STATUS_ACTIVE, $ticket->status); } + public function test_it_exposes_admin_action_capabilities(): void + { + $tenant = new Tenant([ + 'allow_ticket_total_refund' => true, + ]); + $active = (new Ticket)->setRelation('tenant', $tenant); + + $this->assertTrue($active->is_active()); + $this->assertTrue($active->can_cancel()); + $this->assertTrue($active->can_refund()); + + $active->used_at = now(); + + $this->assertFalse($active->is_active()); + $this->assertFalse($active->can_cancel()); + $this->assertFalse($active->can_refund()); + } + public function test_fixed_window_controls_ticket_validity(): void { Carbon::setTestNow('2026-07-21 10:00:00');