fix(sales): render PDFs in client timezone
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Domains\Purchase\Models\Purchase;
|
||||
use App\Domains\Sale\Services\AdminAppSalePdfService;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use Barryvdh\DomPDF\ServiceProvider;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminAppSalePdfServiceTest extends TestCase
|
||||
@@ -17,6 +18,14 @@ class AdminAppSalePdfServiceTest extends TestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->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_sales_report_as_a_pdf(): void
|
||||
@@ -24,11 +33,12 @@ class AdminAppSalePdfServiceTest extends TestCase
|
||||
$response = app(AdminAppSalePdfService::class)->downloadSales(
|
||||
$this->tenant(),
|
||||
collect([$this->sale()]),
|
||||
'America/La_Paz',
|
||||
);
|
||||
|
||||
$this->assertSame('application/pdf', $response->headers->get('content-type'));
|
||||
$this->assertStringContainsString(
|
||||
'attachment; filename=ventas_acme_',
|
||||
'attachment; filename=ventas_acme_20260824_135300.pdf',
|
||||
(string) $response->headers->get('content-disposition'),
|
||||
);
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
@@ -57,16 +67,52 @@ class AdminAppSalePdfServiceTest extends TestCase
|
||||
$response = app(AdminAppSalePdfService::class)->downloadModifications(
|
||||
$this->tenant(),
|
||||
collect([$modification]),
|
||||
'America/La_Paz',
|
||||
);
|
||||
|
||||
$this->assertSame('application/pdf', $response->headers->get('content-type'));
|
||||
$this->assertStringContainsString(
|
||||
'attachment; filename=historial_modificaciones_acme_',
|
||||
'attachment; filename=historial_modificaciones_acme_20260824_135300.pdf',
|
||||
(string) $response->headers->get('content-disposition'),
|
||||
);
|
||||
$this->assertStringStartsWith('%PDF', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_it_renders_pdf_dates_in_the_requested_timezone(): void
|
||||
{
|
||||
$sale = $this->sale();
|
||||
$modification = (new ValueChange)->forceFill([
|
||||
'id' => 1,
|
||||
'trackable_id' => $sale->id,
|
||||
'attribute' => 'status',
|
||||
'old_value' => Purchase::STATUS_PENDING_PAYMENT,
|
||||
'new_value' => Purchase::STATUS_PAID,
|
||||
'changed_at' => now(),
|
||||
'actor_type' => 'system',
|
||||
]);
|
||||
$modification->setRelation('trackable', $sale);
|
||||
$modification->setRelation('user', null);
|
||||
|
||||
$salesHtml = view('pdf.adminapp.sales', [
|
||||
'tenant' => $this->tenant(),
|
||||
'sales' => collect([$sale]),
|
||||
'generatedAt' => now(),
|
||||
'timeZone' => 'America/La_Paz',
|
||||
'confirmedSalesTotal' => '25000.00',
|
||||
])->render();
|
||||
$modificationsHtml = view('pdf.adminapp.sale-modifications', [
|
||||
'tenant' => $this->tenant(),
|
||||
'modifications' => collect([$modification]),
|
||||
'generatedAt' => now(),
|
||||
'timeZone' => 'America/La_Paz',
|
||||
])->render();
|
||||
|
||||
$this->assertStringContainsString('Generado el 24/08/2026 13:53', $salesHtml);
|
||||
$this->assertStringContainsString('24/08/2026 13:53', $salesHtml);
|
||||
$this->assertStringContainsString('Generado el 24/08/2026 13:53', $modificationsHtml);
|
||||
$this->assertStringContainsString('13:53:00', $modificationsHtml);
|
||||
}
|
||||
|
||||
private function tenant(): Tenant
|
||||
{
|
||||
return (new Tenant)->forceFill([
|
||||
|
||||
Reference in New Issue
Block a user