feat(ticket): add entry reservation handling to ticket refund logic and tests
This commit is contained in:
@@ -13,6 +13,8 @@ use App\Domains\Core\Authorization\Enums\RoleCode;
|
||||
use App\Domains\Core\Menu\Models\Menu;
|
||||
use App\Domains\Core\Tenant\Models\AdminWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Desfile\Enums\EntryReservationPaymentType;
|
||||
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
||||
use App\Domains\Ticketing\Ticket\Models\Ticket;
|
||||
use App\Domains\Ticketing\Ticket\Models\TicketRefund;
|
||||
use App\Shared\Attachable\Enums\AttachmentType;
|
||||
@@ -222,6 +224,54 @@ class AdminAppTicketControllerTest extends TestCase
|
||||
$this->assertSame(1, $purchaseItem->ticketRefunds()->count());
|
||||
}
|
||||
|
||||
public function test_it_does_not_refund_a_reserved_desfile_entry(): void
|
||||
{
|
||||
$tenant = $this->createTenant('desfile_pura_tendencia');
|
||||
$tenant->update([
|
||||
'allow_ticket_refund' => true,
|
||||
'allow_ticket_total_refund' => true,
|
||||
]);
|
||||
$admin = $this->createAdminAppUser($tenant);
|
||||
$this->grantTicketsMenu($tenant);
|
||||
Sanctum::actingAs($admin);
|
||||
[$ticket, $purchaseItem] = $this->createRefundableTicket($tenant, $admin, '100.00');
|
||||
$inventory = $ticket->sourceCatalogItem->inventory;
|
||||
$variant = Variant::query()->create([
|
||||
'catalog_item_id' => $ticket->source_catalog_item_id,
|
||||
'inventory_id' => $inventory->id,
|
||||
'precio' => '100.00',
|
||||
]);
|
||||
$ticket->update(['source_variant_id' => $variant->id]);
|
||||
EntryReservation::query()->create([
|
||||
'variant_id' => $variant->id,
|
||||
'ticket_id' => $ticket->id,
|
||||
'inventory_id' => $inventory->id,
|
||||
'fecha_reserva' => now(),
|
||||
'importe' => '100.00',
|
||||
'tipo_pago' => EntryReservationPaymentType::Other,
|
||||
]);
|
||||
|
||||
$this->getJson('/api/v1/adminapp/tenant/tickets')
|
||||
->assertOk()
|
||||
->assertJsonPath('data.0.id', $ticket->id)
|
||||
->assertJsonPath('data.0.allow_refund', true)
|
||||
->assertJsonPath('data.0.can_refund', false);
|
||||
|
||||
$this->getJson("/api/v1/adminapp/tenant/tickets/{$ticket->id}/refund")
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('refund');
|
||||
|
||||
$this->postJson("/api/v1/adminapp/tenant/tickets/{$ticket->id}/refund", [
|
||||
'refund_type' => TicketRefund::TYPE_TOTAL,
|
||||
])
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors('refund');
|
||||
|
||||
$this->assertNull($ticket->fresh()->refunded_at);
|
||||
$this->assertSame(0, $purchaseItem->ticketRefunds()->count());
|
||||
$this->assertSame(0, $inventory->fresh()->refunded_units);
|
||||
}
|
||||
|
||||
public function test_it_partially_refunds_a_ticket_using_the_tenant_percentage(): void
|
||||
{
|
||||
$tenant = $this->createTenant('ticket-partial-refund');
|
||||
|
||||
Reference in New Issue
Block a user