From 9126b0e968af6d7d5ad2161ca4e4ca8ea2e0d178 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 26 Jun 2026 10:08:30 +0300 Subject: [PATCH] test nullable pdf params --- .../Controllers/ElementControllerTest.php | 22 ++++++++++++++++++ .../Element/UseCases/GetElementPdfTest.php | 23 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/backend/tests/Unit/Controllers/ElementControllerTest.php b/backend/tests/Unit/Controllers/ElementControllerTest.php index ca25498..67023d0 100644 --- a/backend/tests/Unit/Controllers/ElementControllerTest.php +++ b/backend/tests/Unit/Controllers/ElementControllerTest.php @@ -278,6 +278,28 @@ class ElementControllerTest extends TestCase ); } + public function testShowPdfReturns400WhenFolderIsMissing(): void + { + $response = $this->controller->showPdf(null, 'baderech.pdf'); + + $this->assertEquals(400, $response->getStatusCode()); + $this->assertSame( + ['error' => 'folder is required'], + json_decode($response->getContent(), true), + ); + } + + public function testShowPdfReturns400WhenFileNameIsMissing(): void + { + $response = $this->controller->showPdf('short', null); + + $this->assertEquals(400, $response->getStatusCode()); + $this->assertSame( + ['error' => 'fileName is required'], + json_decode($response->getContent(), true), + ); + } + public function testUpdateWithIconImageReturnsElementPayload(): void { $set = $this->createSet(1, 'Baderech'); diff --git a/backend/tests/Unit/Element/UseCases/GetElementPdfTest.php b/backend/tests/Unit/Element/UseCases/GetElementPdfTest.php index a8abd59..3a88163 100644 --- a/backend/tests/Unit/Element/UseCases/GetElementPdfTest.php +++ b/backend/tests/Unit/Element/UseCases/GetElementPdfTest.php @@ -4,6 +4,7 @@ namespace Tests\Unit\Element\UseCases; use App\Element\UseCases\GetElementPdf\GetElementPdf; use App\Element\UseCases\GetElementPdf\GetElementPdfRequest; +use App\Exceptions\BadRequestException; use App\Exceptions\NotFoundException; use Tests\Fakes\FakeFilesystem; use Tests\TestCase; @@ -73,6 +74,28 @@ class GetElementPdfTest extends TestCase )); } + public function testMissingFolderThrowsBadRequest(): void + { + $this->expectException(BadRequestException::class); + $this->expectExceptionMessage('folder is required'); + + $this->useCase->execute(new GetElementPdfRequest( + folder: null, + fileName: 'baderech.pdf', + )); + } + + public function testMissingFileNameThrowsBadRequest(): void + { + $this->expectException(BadRequestException::class); + $this->expectExceptionMessage('fileName is required'); + + $this->useCase->execute(new GetElementPdfRequest( + folder: 'short', + fileName: null, + )); + } + public function testInvalidFileNameThrowsNotFound(): void { $this->expectException(NotFoundException::class);