refactor(tickets): reuse dynamic columns in exports
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
namespace Tests\Unit\Ticket;
|
||||
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Services\AdminAppTicketColumnService;
|
||||
use App\Domains\Ticket\Services\AdminAppTicketExcelService;
|
||||
use App\Domains\Ticket\Services\AdminAppTicketPdfService;
|
||||
use App\Domains\Ticket\Services\AdminAppTicketReportService;
|
||||
use App\Domains\Ticket\Services\AdminAppTicketRowService;
|
||||
use Barryvdh\DomPDF\ServiceProvider;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Mockery;
|
||||
@@ -32,7 +34,7 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
|
||||
public function test_it_downloads_the_ticket_report_as_an_excel_file(): void
|
||||
{
|
||||
$response = (new AdminAppTicketExcelService($this->reportService()))
|
||||
$response = (new AdminAppTicketExcelService($this->reportService(), $this->columnService()))
|
||||
->download($this->tenant(), collect(), 'America/La_Paz');
|
||||
|
||||
$this->assertSame(
|
||||
@@ -40,7 +42,7 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
$response->headers->get('content-type'),
|
||||
);
|
||||
$this->assertStringContainsString(
|
||||
'attachment; filename=tickets_acme_20260824_135300.xlsx',
|
||||
'attachment; filename=tickets_fiesta_futbol_infantil_20260824_135300.xlsx',
|
||||
(string) $response->headers->get('content-disposition'),
|
||||
);
|
||||
|
||||
@@ -62,12 +64,12 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
|
||||
public function test_it_downloads_the_ticket_report_as_a_pdf(): void
|
||||
{
|
||||
$response = (new AdminAppTicketPdfService($this->reportService()))
|
||||
$response = (new AdminAppTicketPdfService($this->reportService(), $this->columnService()))
|
||||
->download($this->tenant(), collect(), 'America/La_Paz');
|
||||
|
||||
$this->assertSame('application/pdf', $response->headers->get('content-type'));
|
||||
$this->assertStringContainsString(
|
||||
'attachment; filename=tickets_acme_20260824_135300.pdf',
|
||||
'attachment; filename=tickets_fiesta_futbol_infantil_20260824_135300.pdf',
|
||||
(string) $response->headers->get('content-disposition'),
|
||||
);
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
@@ -75,9 +77,15 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
|
||||
public function test_the_pdf_view_contains_the_report_data_and_requested_timezone(): void
|
||||
{
|
||||
$columns = $this->columnService()->columns($this->tenant());
|
||||
$html = view('pdf.adminapp.tickets', [
|
||||
'tenant' => $this->tenant(),
|
||||
'tickets' => collect([$this->row()]),
|
||||
'columns' => $columns,
|
||||
'tickets' => (new AdminAppTicketRowService)->displayRows(
|
||||
collect([$this->row()]),
|
||||
$columns,
|
||||
'America/La_Paz',
|
||||
),
|
||||
'generatedAt' => now(),
|
||||
'timeZone' => 'America/La_Paz',
|
||||
])->render();
|
||||
@@ -90,10 +98,10 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
|
||||
private function reportService(): AdminAppTicketReportService
|
||||
{
|
||||
$service = Mockery::mock(AdminAppTicketReportService::class);
|
||||
$service->shouldReceive('rows')->once()->andReturn(collect([$this->row()]));
|
||||
$rowService = Mockery::mock(AdminAppTicketRowService::class)->makePartial();
|
||||
$rowService->shouldReceive('rows')->once()->andReturn(collect([$this->row()]));
|
||||
|
||||
return $service;
|
||||
return new AdminAppTicketReportService($rowService);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
@@ -108,7 +116,7 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
'client' => 'Cliente Test',
|
||||
'ticket' => '00000000-0000-0000-0000-000000000001',
|
||||
'date' => now(),
|
||||
'status' => 'Usado',
|
||||
'status' => 'used',
|
||||
'scanned_by' => 'Admin Test',
|
||||
];
|
||||
}
|
||||
@@ -116,11 +124,16 @@ class AdminAppTicketExportServiceTest extends TestCase
|
||||
private function tenant(): Tenant
|
||||
{
|
||||
return (new Tenant)->forceFill([
|
||||
'codigo' => 'acme',
|
||||
'nombre' => 'Acme Eventos',
|
||||
'codigo' => 'fiesta_futbol_infantil',
|
||||
'nombre' => 'Fiesta del Fútbol Infantil',
|
||||
]);
|
||||
}
|
||||
|
||||
private function columnService(): AdminAppTicketColumnService
|
||||
{
|
||||
return new AdminAppTicketColumnService;
|
||||
}
|
||||
|
||||
private function spreadsheetPath(StreamedResponse $response): string
|
||||
{
|
||||
ob_start();
|
||||
|
||||
Reference in New Issue
Block a user