91 lines
2.8 KiB
PHP
91 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Sale;
|
|
|
|
use App\Domains\Auth\Models\User;
|
|
use App\Domains\Logging\Models\ValueChange;
|
|
use App\Domains\Purchase\Models\Purchase;
|
|
use App\Domains\Sale\Services\AdminAppSalePdfService;
|
|
use App\Domains\Tenant\Models\Tenant;
|
|
use Barryvdh\DomPDF\ServiceProvider;
|
|
use Tests\TestCase;
|
|
|
|
class AdminAppSalePdfServiceTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->app->register(ServiceProvider::class);
|
|
}
|
|
|
|
public function test_it_downloads_the_sales_report_as_a_pdf(): void
|
|
{
|
|
$response = app(AdminAppSalePdfService::class)->downloadSales(
|
|
$this->tenant(),
|
|
collect([$this->sale()]),
|
|
);
|
|
|
|
$this->assertSame('application/pdf', $response->headers->get('content-type'));
|
|
$this->assertStringContainsString(
|
|
'attachment; filename=ventas_acme_',
|
|
(string) $response->headers->get('content-disposition'),
|
|
);
|
|
$this->assertStringStartsWith('%PDF', $response->getContent());
|
|
}
|
|
|
|
public function test_it_downloads_the_modification_history_as_a_pdf(): void
|
|
{
|
|
$sale = $this->sale();
|
|
$admin = (new User)->forceFill([
|
|
'id' => 10,
|
|
'nombre_apellido' => 'Admin Test',
|
|
'email' => 'admin@example.test',
|
|
]);
|
|
$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' => 'user',
|
|
]);
|
|
$modification->setRelation('trackable', $sale);
|
|
$modification->setRelation('user', $admin);
|
|
|
|
$response = app(AdminAppSalePdfService::class)->downloadModifications(
|
|
$this->tenant(),
|
|
collect([$modification]),
|
|
);
|
|
|
|
$this->assertSame('application/pdf', $response->headers->get('content-type'));
|
|
$this->assertStringContainsString(
|
|
'attachment; filename=historial_modificaciones_acme_',
|
|
(string) $response->headers->get('content-disposition'),
|
|
);
|
|
$this->assertStringStartsWith('%PDF', $response->getContent());
|
|
}
|
|
|
|
private function tenant(): Tenant
|
|
{
|
|
return (new Tenant)->forceFill([
|
|
'codigo' => 'acme',
|
|
'nombre' => 'Acme Eventos',
|
|
]);
|
|
}
|
|
|
|
private function sale(): Purchase
|
|
{
|
|
return (new Purchase)->forceFill([
|
|
'id' => 15,
|
|
'created_at' => now(),
|
|
'nombre_apellido' => 'Cliente Test',
|
|
'quantity' => 2,
|
|
'status' => Purchase::STATUS_PAID,
|
|
'total' => '25000.00',
|
|
'tickets_count' => 2,
|
|
]);
|
|
}
|
|
}
|