From 28f4114def1ccb469052f5618fd8bc454b264e01 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Sat, 20 Jun 2026 22:46:11 +0300 Subject: [PATCH] test pdf path removal --- .../tests/Feature/ElementsEndpointTest.php | 31 ++++--------- .../Controllers/ElementControllerTest.php | 10 +--- .../Element/UseCases/UpdateElementTest.php | 46 ++++++++----------- 3 files changed, 29 insertions(+), 58 deletions(-) diff --git a/backend/tests/Feature/ElementsEndpointTest.php b/backend/tests/Feature/ElementsEndpointTest.php index 345396c..cd17cd2 100644 --- a/backend/tests/Feature/ElementsEndpointTest.php +++ b/backend/tests/Feature/ElementsEndpointTest.php @@ -92,7 +92,6 @@ class ElementsEndpointTest extends TestCase 'richText' => '

A structured path for growth

', 'shortPdfPath' => '/assets/pdfs/baderech.pdf', 'longPdfPath' => '/assets/pdfs/baderech-long.pdf', - 'pdfPath' => '/assets/pdfs/baderech.pdf', 'youtubeUrl' => $sampleYoutubeUrl, ], ]); @@ -187,7 +186,6 @@ class ElementsEndpointTest extends TestCase 'richText' => '

Updated rich text

', 'shortPdfPath' => '/assets/pdfs/updated.pdf', 'longPdfPath' => '/assets/pdfs/updated-long.pdf', - 'pdfPath' => '/assets/pdfs/updated.pdf', 'youtubeUrl' => $sampleYoutubeUrl, ], ]); @@ -203,7 +201,7 @@ class ElementsEndpointTest extends TestCase ); } - public function testAuthenticatedUpdateAcceptsLegacyPdfPath(): void + public function testAuthenticatedUpdateRejectsLegacyPdfPath(): void { $setRepository = app(SetRepository::class); $elementRepository = app(ElementRepository::class); @@ -229,20 +227,10 @@ class ElementsEndpointTest extends TestCase 'pdfPath' => '/assets/pdfs/legacy-updated.pdf', ]); - $response->assertOk(); - $body = $response->json(); - $this->assertSame( - '/assets/pdfs/legacy-updated.pdf', - $body['element']['shortPdfPath'], - ); - $this->assertSame( - '/assets/pdfs/legacy-updated.pdf', - $body['element']['pdfPath'], - ); - $this->assertSame( - '/assets/pdfs/baderech-long.pdf', - $body['element']['longPdfPath'], - ); + $response->assertBadRequest(); + $response->assertExactJson([ + 'error' => 'nothing to update', + ]); } public function testAuthenticatedUpdateClearsUploadedMedia(): void @@ -282,7 +270,7 @@ class ElementsEndpointTest extends TestCase ->postJson('/api/element/update', [ 'elementId' => $element->getId(), 'iconImageUrl' => '', - 'pdfPath' => '', + 'shortPdfPath' => '', 'longPdfPath' => '', ]); @@ -291,7 +279,7 @@ class ElementsEndpointTest extends TestCase $this->assertNull($body['element']['iconImageUrl']); $this->assertNull($body['element']['shortPdfPath']); $this->assertNull($body['element']['longPdfPath']); - $this->assertNull($body['element']['pdfPath']); + $this->assertArrayNotHasKey('pdfPath', $body['element']); $updatedElement = $elementRepository->find($element->getId()); $this->assertNotNull($updatedElement); $this->assertNull($updatedElement->getIconImageUrl()); @@ -461,10 +449,7 @@ class ElementsEndpointTest extends TestCase '/storage/element-pdfs/short/', $body['element']['shortPdfPath'], ); - $this->assertSame( - $body['element']['shortPdfPath'], - $body['element']['pdfPath'], - ); + $this->assertArrayNotHasKey('pdfPath', $body['element']); $updatedElement = $elementRepository->find($element->getId()); $this->assertNotNull($updatedElement); $updatedPdfPath = $updatedElement->getShortPdfPath(); diff --git a/backend/tests/Unit/Controllers/ElementControllerTest.php b/backend/tests/Unit/Controllers/ElementControllerTest.php index 69ec667..7d97527 100644 --- a/backend/tests/Unit/Controllers/ElementControllerTest.php +++ b/backend/tests/Unit/Controllers/ElementControllerTest.php @@ -129,10 +129,7 @@ class ElementControllerTest extends TestCase '/assets/pdfs/baderech-long.pdf', $body['element']['longPdfPath'], ); - $this->assertSame( - '/assets/pdfs/baderech.pdf', - $body['element']['pdfPath'], - ); + $this->assertArrayNotHasKey('pdfPath', $body['element']); $this->assertSame( 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s', $body['element']['youtubeUrl'], @@ -233,10 +230,7 @@ class ElementControllerTest extends TestCase 'https://test.local/storage/element-pdfs/short/fake-baderech.pdf', $body['element']['shortPdfPath'], ); - $this->assertSame( - $body['element']['shortPdfPath'], - $body['element']['pdfPath'], - ); + $this->assertArrayNotHasKey('pdfPath', $body['element']); $this->assertSame( 'element-pdfs/short', $this->fileUploader->uploads[0]['folder'], diff --git a/backend/tests/Unit/Element/UseCases/UpdateElementTest.php b/backend/tests/Unit/Element/UseCases/UpdateElementTest.php index cea63d1..1002906 100644 --- a/backend/tests/Unit/Element/UseCases/UpdateElementTest.php +++ b/backend/tests/Unit/Element/UseCases/UpdateElementTest.php @@ -125,7 +125,7 @@ class UpdateElementTest extends TestCase $this->assertSame('Updated title', $persistedElement->getTitle()); } - public function testLegacyPdfPathUpdatesShortPdfPath(): void + public function testLegacyPdfPathIsNotAnUpdateField(): void { $set = $this->createSet(1, 'Baderech'); $element = $this->createElement( @@ -140,33 +140,25 @@ class UpdateElementTest extends TestCase null, ); - $updatedElement = $this->updateElement->execute( - new UpdateElementRequest( - id: $element->getId(), - title: null, - description: null, - iconImageUrl: null, - richText: null, - shortPdfPath: null, - longPdfPath: null, - pdfPath: '/assets/pdfs/legacy-updated.pdf', - youtubeUrl: null, - fileType: null, - fileContents: null, - fileOriginalName: null, - fileMimeType: null, - fileSizeBytes: null, - ) - ); + $this->expectException(BadRequestException::class); + $this->expectExceptionMessage('nothing to update'); - $this->assertSame( - '/assets/pdfs/legacy-updated.pdf', - $updatedElement->getShortPdfPath(), - ); - $this->assertSame( - '/assets/pdfs/original-long.pdf', - $updatedElement->getLongPdfPath(), - ); + $this->updateElement->execute(new UpdateElementRequest( + id: $element->getId(), + title: null, + description: null, + iconImageUrl: null, + richText: null, + shortPdfPath: null, + longPdfPath: null, + pdfPath: '/assets/pdfs/legacy-updated.pdf', + youtubeUrl: null, + fileType: null, + fileContents: null, + fileOriginalName: null, + fileMimeType: null, + fileSizeBytes: null, + )); } public function testConvertsEmptyNullableFieldsToNull(): void