Squashed commit of the following:
commit c993da3397b65488d919d1b929cbd4638754601b Author: ncoronel <ncoronel@quo.ar> Date: Tue Jul 28 09:54:10 2026 -0300 feat(tickets): update ticket metadata layout for improved readability and clarity commit 140fa4676d84bed788894e1d7994b26dccac7a34 Author: ncoronel <ncoronel@quo.ar> Date: Tue Jul 28 09:43:21 2026 -0300 feat(tickets): enhance PDF ticket download with dynamic filename and improved styling commit 8875c047b198776e61e8353c99cf4c7b00bc8fc9 Author: ncoronel <ncoronel@quo.ar> Date: Tue Jul 28 09:03:17 2026 -0300 feat(tickets): add PDF download functionality for tickets - Implemented a new endpoint to download tickets as a PDF. - Created DownloadTicketsPdfRequest for validating ticket IDs. - Added TicketPdfService to handle PDF generation and QR code embedding. - Developed a Blade view for rendering ticket details in PDF format. - Updated API routes to include the new PDF download route. - Added tests to ensure authenticated users can download their tickets and that users cannot download tickets belonging to others. - Updated composer.json and composer.lock to include necessary dependencies for PDF generation and QR code creation.
This commit is contained in:
@@ -61,6 +61,43 @@ class TicketControllerTest extends TestCase
|
||||
->assertUnauthorized();
|
||||
}
|
||||
|
||||
public function test_an_authenticated_user_can_download_a_pdf_for_their_tickets(): void
|
||||
{
|
||||
$tenant = $this->createTenant('current');
|
||||
$user = User::factory()->create();
|
||||
$firstTicket = $this->createTicket($tenant, $user, 'First ticket');
|
||||
$secondTicket = $this->createTicket($tenant, $user, 'Second ticket');
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')
|
||||
->post("/api/tenants/{$tenant->codigo}/tickets/pdf", [
|
||||
'ticket_ids' => [$firstTicket->id, $secondTicket->id],
|
||||
]);
|
||||
|
||||
$response
|
||||
->assertOk()
|
||||
->assertHeader('content-type', 'application/pdf')
|
||||
->assertHeader(
|
||||
'content-disposition',
|
||||
"attachment; filename=tickets_{$secondTicket->id}_{$firstTicket->id}.pdf"
|
||||
);
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_a_user_cannot_download_someone_elses_ticket(): void
|
||||
{
|
||||
$tenant = $this->createTenant('current');
|
||||
$user = User::factory()->create();
|
||||
$otherUser = User::factory()->create();
|
||||
$ownTicket = $this->createTicket($tenant, $user, 'Own ticket');
|
||||
$otherTicket = $this->createTicket($tenant, $otherUser, 'Other ticket');
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->postJson("/api/tenants/{$tenant->codigo}/tickets/pdf", [
|
||||
'ticket_ids' => [$ownTicket->id, $otherTicket->id],
|
||||
])
|
||||
->assertNotFound();
|
||||
}
|
||||
|
||||
private function createTicket(Tenant $tenant, User $user, string $name): Ticket
|
||||
{
|
||||
return Ticket::query()->create([
|
||||
|
||||
Reference in New Issue
Block a user