app->register(ServiceProvider::class); Carbon::setTestNow(Carbon::parse('2026-08-24 17:53:00', 'UTC')); } protected function tearDown(): void { Carbon::setTestNow(); parent::tearDown(); } public function test_it_downloads_the_ticket_report_as_an_excel_file(): void { $response = (new AdminAppTicketExcelService($this->reportService(), $this->columnService())) ->download($this->tenant(), collect(), 'America/La_Paz'); $this->assertSame( 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('content-type'), ); $this->assertStringContainsString( 'attachment; filename=tickets_fiesta_futbol_infantil_20260824_135300.xlsx', (string) $response->headers->get('content-disposition'), ); $path = $this->spreadsheetPath($response); try { $sheet = IOFactory::load($path)->getActiveSheet(); $this->assertSame('Tickets', $sheet->getTitle()); $this->assertSame('N° de orden', $sheet->getCell('A1')->getValue()); $this->assertSame('#15', $sheet->getCell('A2')->getValue()); $this->assertSame('Cena', $sheet->getCell('D2')->getValue()); $this->assertSame(8000.0, $sheet->getCell('E2')->getValue()); $this->assertSame('25', $sheet->getCell('G2')->getValue()); $this->assertSame('Usado', $sheet->getCell('H2')->getValue()); } finally { @unlink($path); } } public function test_it_downloads_the_ticket_report_as_a_pdf(): void { $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_fiesta_futbol_infantil_20260824_135300.pdf', (string) $response->headers->get('content-disposition'), ); $this->assertStringStartsWith('%PDF', $response->getContent()); } 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(), 'columns' => $columns, 'tickets' => (new AdminAppTicketRowService)->displayRows( collect([$this->row()]), $columns, 'America/La_Paz', ), 'generatedAt' => now(), 'timeZone' => 'America/La_Paz', ])->render(); $this->assertStringContainsString('Generado el 24/08/2026 13:53', $html); $this->assertStringContainsString('25', $html); $this->assertStringNotContainsString('00000000-0000-0000-0000-000000000001', $html); $this->assertStringContainsString('Cena', $html); } private function reportService(): AdminAppTicketReportService { $rowService = Mockery::mock(AdminAppTicketRowService::class)->makePartial(); $rowService->shouldReceive('rows')->once()->andReturn(collect([$this->row()])); return new AdminAppTicketReportService($rowService); } /** @return array */ private function row(): array { return [ 'order_number' => 15, 'category' => 'Comida', 'product' => '12/10', 'type' => 'Cena', 'amount' => 8000.0, 'client' => 'Cliente Test', 'id' => 25, 'status' => 'used', 'scanned_by' => 'Admin Test', ]; } private function tenant(): Tenant { return (new Tenant)->forceFill([ '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(); ($response->getCallback())(); $contents = ob_get_clean(); $this->assertIsString($contents); $this->assertStringStartsWith('PK', $contents); $path = tempnam(sys_get_temp_dir(), 'shopit_ticket_excel_'); $this->assertNotFalse($path); file_put_contents($path, $contents); return $path; } }