feat(tenant): add master toggle for ticket refunds

This commit is contained in:
2026-09-11 16:22:27 -03:00
parent b4da6e3747
commit c0c19c9c01
9 changed files with 102 additions and 11 deletions

View File

@@ -18,12 +18,14 @@ class TenantRefundConfigurationTest extends TestCase
{
$tenant = $this->createTenant('refund-defaults');
$this->assertFalse($tenant->allow_ticket_refund);
$this->assertFalse($tenant->allow_ticket_total_refund);
$this->assertFalse($tenant->allow_ticket_partial_refund);
$this->assertSame('0.00', $tenant->ticket_partial_refund_percentage);
$this->getJson("/api/tenants/{$tenant->codigo}")
->assertOk()
->assertJsonPath('data.allow_ticket_refund', false)
->assertJsonPath('data.allow_ticket_total_refund', false)
->assertJsonPath('data.allow_ticket_partial_refund', false)
->assertJsonPath('data.ticket_partial_refund_percentage', '0.00');
@@ -34,17 +36,20 @@ class TenantRefundConfigurationTest extends TestCase
$tenant = $this->createTenant('refund-update');
$this->putJson("/api/tenants/{$tenant->codigo}", [
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 25.50,
])
->assertOk()
->assertJsonPath('data.allow_ticket_refund', true)
->assertJsonPath('data.allow_ticket_total_refund', true)
->assertJsonPath('data.allow_ticket_partial_refund', true)
->assertJsonPath('data.ticket_partial_refund_percentage', '25.50');
$this->assertDatabaseHas('tenants', [
'id' => $tenant->id,
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 25.50,
@@ -64,6 +69,7 @@ class TenantRefundConfigurationTest extends TestCase
public function test_tenant_allow_refund_logic(): void
{
$tenant = new Tenant([
'allow_ticket_refund' => false,
'allow_ticket_total_refund' => false,
'allow_ticket_partial_refund' => false,
'ticket_partial_refund_percentage' => 0,
@@ -83,6 +89,10 @@ class TenantRefundConfigurationTest extends TestCase
// Partial refund enabled and percentage is set
$tenant->ticket_partial_refund_percentage = 25.50;
$this->assertFalse($tenant->allow_refund());
$this->assertFalse($tenant->allow_partial_refund());
$tenant->allow_ticket_refund = true;
$this->assertTrue($tenant->allow_refund());
$this->assertTrue($tenant->allowRefund());
$this->assertTrue($tenant->allow_refund);
@@ -101,6 +111,13 @@ class TenantRefundConfigurationTest extends TestCase
$tenant->ticket_partial_refund_percentage = 50.00;
$this->assertTrue($tenant->allow_refund());
$this->assertTrue($tenant->allow_partial_refund());
$tenant->allow_ticket_refund = false;
$this->assertFalse($tenant->allow_refund());
$this->assertFalse($tenant->allow_partial_refund());
$this->assertTrue($tenant->allow_ticket_total_refund);
$this->assertTrue($tenant->allow_ticket_partial_refund);
$this->assertSame('50.00', $tenant->ticket_partial_refund_percentage);
}
private function createTenant(string $code): Tenant

View File

@@ -100,7 +100,10 @@ class AdminAppTicketControllerTest extends TestCase
->assertJsonPath('data.0.can_refund', false);
// Total refund allowed
$tenant->update(['allow_ticket_total_refund' => true]);
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
]);
$this->getJson('/api/v1/adminapp/tenant/tickets')
->assertOk()
->assertJsonPath('data.0.allow_refund', true)
@@ -108,6 +111,7 @@ class AdminAppTicketControllerTest extends TestCase
// Partial refund allowed with percentage set
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => false,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 20.00,
@@ -117,6 +121,17 @@ class AdminAppTicketControllerTest extends TestCase
->assertJsonPath('data.0.allow_refund', true)
->assertJsonPath('data.0.can_refund', true);
// Master toggle disabled while preserving the partial refund preference
$tenant->update(['allow_ticket_refund' => false]);
$this->getJson('/api/v1/adminapp/tenant/tickets')
->assertOk()
->assertJsonPath('data.0.allow_refund', false)
->assertJsonPath('data.0.can_refund', false);
$this->assertTrue($tenant->fresh()->allow_ticket_partial_refund);
$this->assertSame('20.00', $tenant->fresh()->ticket_partial_refund_percentage);
$tenant->update(['allow_ticket_refund' => true]);
// Partial refund enabled but percentage is 0
$tenant->update([
'ticket_partial_refund_percentage' => 0,
@@ -162,7 +177,10 @@ class AdminAppTicketControllerTest extends TestCase
public function test_it_totally_refunds_a_ticket_when_the_tenant_allows_it(): void
{
$tenant = $this->createTenant('ticket-total-refund');
$tenant->update(['allow_ticket_total_refund' => true]);
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
]);
$admin = $this->createAdminAppUser($tenant);
$this->grantTicketsMenu($tenant);
Sanctum::actingAs($admin);
@@ -184,6 +202,7 @@ class AdminAppTicketControllerTest extends TestCase
{
$tenant = $this->createTenant('ticket-partial-refund');
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 25.50,
]);
@@ -239,6 +258,7 @@ class AdminAppTicketControllerTest extends TestCase
{
$tenant = $this->createTenant('ticket-calc-both');
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 30.00,
@@ -258,6 +278,7 @@ class AdminAppTicketControllerTest extends TestCase
{
$tenant = $this->createTenant('ticket-calc-total');
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => false,
]);
@@ -276,6 +297,7 @@ class AdminAppTicketControllerTest extends TestCase
{
$tenant = $this->createTenant('ticket-calc-insufficient');
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
'allow_ticket_partial_refund' => true,
'ticket_partial_refund_percentage' => 50.00,
@@ -299,7 +321,10 @@ class AdminAppTicketControllerTest extends TestCase
public function test_it_fails_calculating_refund_if_ticket_is_not_active(): void
{
$tenant = $this->createTenant('ticket-calc-inactive');
$tenant->update(['allow_ticket_total_refund' => true]);
$tenant->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
]);
$admin = $this->createAdminAppUser($tenant);
$this->grantTicketsMenu($tenant);
Sanctum::actingAs($admin);
@@ -316,8 +341,14 @@ class AdminAppTicketControllerTest extends TestCase
{
$tenantA = $this->createTenant('ticket-calc-a');
$tenantB = $this->createTenant('ticket-calc-b');
$tenantA->update(['allow_ticket_total_refund' => true]);
$tenantB->update(['allow_ticket_total_refund' => true]);
$tenantA->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
]);
$tenantB->update([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
]);
$adminA = $this->createAdminAppUser($tenantA);
$adminB = $this->createAdminAppUser($tenantB);

View File

@@ -67,6 +67,7 @@ class TicketTest extends TestCase
public function test_it_exposes_admin_action_capabilities(): void
{
$tenant = new Tenant([
'allow_ticket_refund' => true,
'allow_ticket_total_refund' => true,
]);
$active = (new Ticket)->setRelation('tenant', $tenant);