test pdf path removal

This commit is contained in:
Yisroel Baum 2026-06-20 22:46:11 +03:00
parent 9bbabc7fa6
commit 28f4114def
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 29 additions and 58 deletions

View file

@ -92,7 +92,6 @@ class ElementsEndpointTest extends TestCase
'richText' => '<p>A structured path for growth</p>', 'richText' => '<p>A structured path for growth</p>',
'shortPdfPath' => '/assets/pdfs/baderech.pdf', 'shortPdfPath' => '/assets/pdfs/baderech.pdf',
'longPdfPath' => '/assets/pdfs/baderech-long.pdf', 'longPdfPath' => '/assets/pdfs/baderech-long.pdf',
'pdfPath' => '/assets/pdfs/baderech.pdf',
'youtubeUrl' => $sampleYoutubeUrl, 'youtubeUrl' => $sampleYoutubeUrl,
], ],
]); ]);
@ -187,7 +186,6 @@ class ElementsEndpointTest extends TestCase
'richText' => '<p>Updated rich text</p>', 'richText' => '<p>Updated rich text</p>',
'shortPdfPath' => '/assets/pdfs/updated.pdf', 'shortPdfPath' => '/assets/pdfs/updated.pdf',
'longPdfPath' => '/assets/pdfs/updated-long.pdf', 'longPdfPath' => '/assets/pdfs/updated-long.pdf',
'pdfPath' => '/assets/pdfs/updated.pdf',
'youtubeUrl' => $sampleYoutubeUrl, 'youtubeUrl' => $sampleYoutubeUrl,
], ],
]); ]);
@ -203,7 +201,7 @@ class ElementsEndpointTest extends TestCase
); );
} }
public function testAuthenticatedUpdateAcceptsLegacyPdfPath(): void public function testAuthenticatedUpdateRejectsLegacyPdfPath(): void
{ {
$setRepository = app(SetRepository::class); $setRepository = app(SetRepository::class);
$elementRepository = app(ElementRepository::class); $elementRepository = app(ElementRepository::class);
@ -229,20 +227,10 @@ class ElementsEndpointTest extends TestCase
'pdfPath' => '/assets/pdfs/legacy-updated.pdf', 'pdfPath' => '/assets/pdfs/legacy-updated.pdf',
]); ]);
$response->assertOk(); $response->assertBadRequest();
$body = $response->json(); $response->assertExactJson([
$this->assertSame( 'error' => 'nothing to update',
'/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'],
);
} }
public function testAuthenticatedUpdateClearsUploadedMedia(): void public function testAuthenticatedUpdateClearsUploadedMedia(): void
@ -282,7 +270,7 @@ class ElementsEndpointTest extends TestCase
->postJson('/api/element/update', [ ->postJson('/api/element/update', [
'elementId' => $element->getId(), 'elementId' => $element->getId(),
'iconImageUrl' => '', 'iconImageUrl' => '',
'pdfPath' => '', 'shortPdfPath' => '',
'longPdfPath' => '', 'longPdfPath' => '',
]); ]);
@ -291,7 +279,7 @@ class ElementsEndpointTest extends TestCase
$this->assertNull($body['element']['iconImageUrl']); $this->assertNull($body['element']['iconImageUrl']);
$this->assertNull($body['element']['shortPdfPath']); $this->assertNull($body['element']['shortPdfPath']);
$this->assertNull($body['element']['longPdfPath']); $this->assertNull($body['element']['longPdfPath']);
$this->assertNull($body['element']['pdfPath']); $this->assertArrayNotHasKey('pdfPath', $body['element']);
$updatedElement = $elementRepository->find($element->getId()); $updatedElement = $elementRepository->find($element->getId());
$this->assertNotNull($updatedElement); $this->assertNotNull($updatedElement);
$this->assertNull($updatedElement->getIconImageUrl()); $this->assertNull($updatedElement->getIconImageUrl());
@ -461,10 +449,7 @@ class ElementsEndpointTest extends TestCase
'/storage/element-pdfs/short/', '/storage/element-pdfs/short/',
$body['element']['shortPdfPath'], $body['element']['shortPdfPath'],
); );
$this->assertSame( $this->assertArrayNotHasKey('pdfPath', $body['element']);
$body['element']['shortPdfPath'],
$body['element']['pdfPath'],
);
$updatedElement = $elementRepository->find($element->getId()); $updatedElement = $elementRepository->find($element->getId());
$this->assertNotNull($updatedElement); $this->assertNotNull($updatedElement);
$updatedPdfPath = $updatedElement->getShortPdfPath(); $updatedPdfPath = $updatedElement->getShortPdfPath();

View file

@ -129,10 +129,7 @@ class ElementControllerTest extends TestCase
'/assets/pdfs/baderech-long.pdf', '/assets/pdfs/baderech-long.pdf',
$body['element']['longPdfPath'], $body['element']['longPdfPath'],
); );
$this->assertSame( $this->assertArrayNotHasKey('pdfPath', $body['element']);
'/assets/pdfs/baderech.pdf',
$body['element']['pdfPath'],
);
$this->assertSame( $this->assertSame(
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s', 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
$body['element']['youtubeUrl'], $body['element']['youtubeUrl'],
@ -233,10 +230,7 @@ class ElementControllerTest extends TestCase
'https://test.local/storage/element-pdfs/short/fake-baderech.pdf', 'https://test.local/storage/element-pdfs/short/fake-baderech.pdf',
$body['element']['shortPdfPath'], $body['element']['shortPdfPath'],
); );
$this->assertSame( $this->assertArrayNotHasKey('pdfPath', $body['element']);
$body['element']['shortPdfPath'],
$body['element']['pdfPath'],
);
$this->assertSame( $this->assertSame(
'element-pdfs/short', 'element-pdfs/short',
$this->fileUploader->uploads[0]['folder'], $this->fileUploader->uploads[0]['folder'],

View file

@ -125,7 +125,7 @@ class UpdateElementTest extends TestCase
$this->assertSame('Updated title', $persistedElement->getTitle()); $this->assertSame('Updated title', $persistedElement->getTitle());
} }
public function testLegacyPdfPathUpdatesShortPdfPath(): void public function testLegacyPdfPathIsNotAnUpdateField(): void
{ {
$set = $this->createSet(1, 'Baderech'); $set = $this->createSet(1, 'Baderech');
$element = $this->createElement( $element = $this->createElement(
@ -140,33 +140,25 @@ class UpdateElementTest extends TestCase
null, null,
); );
$updatedElement = $this->updateElement->execute( $this->expectException(BadRequestException::class);
new UpdateElementRequest( $this->expectExceptionMessage('nothing to update');
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->assertSame( $this->updateElement->execute(new UpdateElementRequest(
'/assets/pdfs/legacy-updated.pdf', id: $element->getId(),
$updatedElement->getShortPdfPath(), title: null,
); description: null,
$this->assertSame( iconImageUrl: null,
'/assets/pdfs/original-long.pdf', richText: null,
$updatedElement->getLongPdfPath(), 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 public function testConvertsEmptyNullableFieldsToNull(): void