test pdf use case

This commit is contained in:
Yisroel Baum 2026-06-26 08:13:46 +03:00
parent 208c683dac
commit b1bee8a16e
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 165 additions and 0 deletions

View file

@ -8,6 +8,7 @@ use App\Element\Element;
use App\Element\UseCases\CreateChildElement\CreateChildElement;
use App\Element\UseCases\DeleteChildElement\DeleteChildElement;
use App\Element\UseCases\GetElement\GetElement;
use App\Element\UseCases\GetElementPdf\GetElementPdf;
use App\Element\UseCases\ReorderChildElements\ReorderChildElements;
use App\Element\UseCases\UpdateElement\UpdateDescription;
use App\Element\UseCases\UpdateElement\UpdateElement;
@ -25,6 +26,7 @@ use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Tests\Fakes\FakeElementRepository;
use Tests\Fakes\FakeFileUploader;
use Tests\Fakes\FakeStoredFileReader;
use Tests\TestCase;
class ElementControllerTest extends TestCase
@ -35,10 +37,13 @@ class ElementControllerTest extends TestCase
private FakeFileUploader $fileUploader;
private FakeStoredFileReader $storedFileReader;
protected function setUp(): void
{
$this->elementRepo = new FakeElementRepository();
$this->fileUploader = new FakeFileUploader();
$this->storedFileReader = new FakeStoredFileReader();
$getElement = new GetElement($this->elementRepo);
$updateElement = new UpdateElement(
new UpdateTitle($this->elementRepo),
@ -68,6 +73,7 @@ class ElementControllerTest extends TestCase
new DeleteChildElement($this->elementRepo, $this->fileUploader),
new ReorderChildElements($this->elementRepo),
$updateElement,
new GetElementPdf($this->storedFileReader),
$this->fileUploader,
);
}
@ -244,6 +250,38 @@ class ElementControllerTest extends TestCase
);
}
public function testShowPdfReturnsPdfResponse(): void
{
$this->storedFileReader->put(
'element-pdfs/short/baderech.pdf',
'pdf-bytes',
);
$response = $this->controller->showPdf('short', 'baderech.pdf');
$this->assertEquals(200, $response->getStatusCode());
$this->assertSame('pdf-bytes', $response->getContent());
$this->assertSame(
'application/pdf',
$response->headers->get('Content-Type'),
);
$this->assertSame(
'inline; filename="baderech.pdf"',
$response->headers->get('Content-Disposition'),
);
}
public function testShowPdfReturns404WhenPdfDoesNotExist(): void
{
$response = $this->controller->showPdf('short', 'missing.pdf');
$this->assertEquals(404, $response->getStatusCode());
$this->assertSame(
['error' => 'PDF not found'],
json_decode($response->getContent(), true),
);
}
public function testUpdateWithIconImageReturnsElementPayload(): void
{
$set = $this->createSet(1, 'Baderech');