feat(ticket): add action capability helpers and expose them in admin resource
This commit is contained in:
parent
5d00dc439e
commit
2ddb046c26
|
|
@ -150,6 +150,51 @@ class Ticket extends Model
|
||||||
return $this->allow_refund();
|
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<User, $this> */
|
/** @return BelongsTo<User, $this> */
|
||||||
public function user(): BelongsTo
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,9 @@ class AdminAppTicketResource extends TicketResource
|
||||||
...parent::toArray($request),
|
...parent::toArray($request),
|
||||||
...$details,
|
...$details,
|
||||||
'allow_refund' => $this->resource->allow_refund(),
|
'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),
|
'values' => $rowService->values($this->resource, $details),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,9 @@ class AdminAppTicketControllerTest extends TestCase
|
||||||
->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE)
|
->assertJsonPath('data.0.values.status', Ticket::STATUS_ACTIVE)
|
||||||
->assertJsonPath('data.0.status_label', 'Activo')
|
->assertJsonPath('data.0.status_label', 'Activo')
|
||||||
->assertJsonPath('data.0.allow_refund', false)
|
->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')
|
->assertJsonMissingPath('data.0.values.ticket')
|
||||||
->assertJsonPath('data.0.values.date', '-')
|
->assertJsonPath('data.0.values.date', '-')
|
||||||
->assertJsonPath('data.0.values.size', '-')
|
->assertJsonPath('data.0.values.size', '-')
|
||||||
|
|
@ -93,13 +96,15 @@ class AdminAppTicketControllerTest extends TestCase
|
||||||
// Default: neither total nor partial refund allowed
|
// Default: neither total nor partial refund allowed
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.0.allow_refund', false);
|
->assertJsonPath('data.0.allow_refund', false)
|
||||||
|
->assertJsonPath('data.0.can_refund', false);
|
||||||
|
|
||||||
// Total refund allowed
|
// Total refund allowed
|
||||||
$tenant->update(['allow_ticket_total_refund' => true]);
|
$tenant->update(['allow_ticket_total_refund' => true]);
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
->assertOk()
|
->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
|
// Partial refund allowed with percentage set
|
||||||
$tenant->update([
|
$tenant->update([
|
||||||
|
|
@ -109,7 +114,8 @@ class AdminAppTicketControllerTest extends TestCase
|
||||||
]);
|
]);
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
->assertOk()
|
->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
|
// Partial refund enabled but percentage is 0
|
||||||
$tenant->update([
|
$tenant->update([
|
||||||
|
|
@ -117,7 +123,8 @@ class AdminAppTicketControllerTest extends TestCase
|
||||||
]);
|
]);
|
||||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||||
->assertOk()
|
->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
|
public function test_it_cancels_a_ticket_from_the_authenticated_tenant(): void
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,24 @@ class TicketTest extends TestCase
|
||||||
$this->assertSame(Ticket::STATUS_ACTIVE, $ticket->status);
|
$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
|
public function test_fixed_window_controls_ticket_validity(): void
|
||||||
{
|
{
|
||||||
Carbon::setTestNow('2026-07-21 10:00:00');
|
Carbon::setTestNow('2026-07-21 10:00:00');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue