test element file routing
This commit is contained in:
parent
14d2ce2284
commit
0d5783ba9c
14 changed files with 951 additions and 388 deletions
|
|
@ -43,7 +43,8 @@ class DemoSeedDataTest extends TestCase
|
|||
Storage::disk('public')->assertExists(
|
||||
'element-icons/baderech-haavodah-icon.png',
|
||||
);
|
||||
$this->assertNull($rootElement->getPdfPath());
|
||||
$this->assertNull($rootElement->getShortPdfPath());
|
||||
$this->assertNull($rootElement->getLongPdfPath());
|
||||
$this->assertNull($rootElement->getYoutubeUrl());
|
||||
$this->assertCount(6, $childElements);
|
||||
$this->assertSame(
|
||||
|
|
@ -96,10 +97,13 @@ class DemoSeedDataTest extends TestCase
|
|||
$childElements[0]->getRichText(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/baderech.pdf',
|
||||
$childElements[0]->getPdfPath(),
|
||||
'element-pdfs/short/baderech.pdf',
|
||||
$childElements[0]->getShortPdfPath(),
|
||||
);
|
||||
$this->assertNull($childElements[0]->getLongPdfPath());
|
||||
Storage::disk('public')->assertExists(
|
||||
'element-pdfs/short/baderech.pdf',
|
||||
);
|
||||
Storage::disk('public')->assertExists('element-pdfs/baderech.pdf');
|
||||
|
||||
$introductionChildElements = $elementRepository->findByParentElement(
|
||||
$childElements[0],
|
||||
|
|
@ -114,7 +118,8 @@ class DemoSeedDataTest extends TestCase
|
|||
$this->assertSame('', $introductionAudioElement->getDescription());
|
||||
$this->assertNull($introductionAudioElement->getIconImageUrl());
|
||||
$this->assertSame('', $introductionAudioElement->getRichText());
|
||||
$this->assertNull($introductionAudioElement->getPdfPath());
|
||||
$this->assertNull($introductionAudioElement->getShortPdfPath());
|
||||
$this->assertNull($introductionAudioElement->getLongPdfPath());
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
$introductionAudioElement->getYoutubeUrl(),
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ namespace Tests\Feature;
|
|||
use App\Auth\CreateSessionDto;
|
||||
use App\Auth\SessionRepository;
|
||||
use App\Element\CreateElementDto;
|
||||
use App\Element\Element;
|
||||
use App\Element\ElementRepository;
|
||||
use App\Set\CreateSetDto;
|
||||
use App\Set\Set;
|
||||
use App\Set\SetRepository;
|
||||
use App\Shared\ValueObject\EmailAddress;
|
||||
use App\User\CreateUserDto;
|
||||
|
|
@ -28,41 +30,43 @@ class ElementsEndpointTest extends TestCase
|
|||
. 'yHx-r4p6hHU&t=1s';
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: '/assets/pdfs/baderech.pdf',
|
||||
youtubeUrl: $sampleYoutubeUrl,
|
||||
parentElement: null,
|
||||
));
|
||||
$firstChildElement = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Avodah Foundations',
|
||||
description: 'Foundations for steady avodah',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Foundations rich text</p>',
|
||||
pdfPath: '/assets/pdfs/foundations.pdf',
|
||||
youtubeUrl: null,
|
||||
parentElement: $element,
|
||||
));
|
||||
$secondChildElement = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Daily Practice',
|
||||
description: 'Daily practices for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Daily practice rich text</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: $element,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
'/assets/baderech-haavodah-icon.png',
|
||||
'<p>A structured path for growth</p>',
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
'/assets/pdfs/baderech-long.pdf',
|
||||
$sampleYoutubeUrl,
|
||||
null,
|
||||
);
|
||||
$firstChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Avodah Foundations',
|
||||
'Foundations for steady avodah',
|
||||
null,
|
||||
'<p>Foundations rich text</p>',
|
||||
'/assets/pdfs/foundations.pdf',
|
||||
null,
|
||||
null,
|
||||
$element,
|
||||
);
|
||||
$secondChildElement = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Daily Practice',
|
||||
'Daily practices for growth',
|
||||
null,
|
||||
'<p>Daily practice rich text</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$element,
|
||||
);
|
||||
|
||||
$response = $this->getJson("/api/elements/{$element->getId()}");
|
||||
|
||||
|
|
@ -86,6 +90,8 @@ class ElementsEndpointTest extends TestCase
|
|||
'description' => 'A structured path for growth',
|
||||
'iconImageUrl' => '/assets/baderech-haavodah-icon.png',
|
||||
'richText' => '<p>A structured path for growth</p>',
|
||||
'shortPdfPath' => '/assets/pdfs/baderech.pdf',
|
||||
'longPdfPath' => '/assets/pdfs/baderech-long.pdf',
|
||||
'pdfPath' => '/assets/pdfs/baderech.pdf',
|
||||
'youtubeUrl' => $sampleYoutubeUrl,
|
||||
],
|
||||
|
|
@ -106,21 +112,19 @@ class ElementsEndpointTest extends TestCase
|
|||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: '/assets/pdfs/baderech.pdf',
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
'/assets/baderech-haavodah-icon.png',
|
||||
'<p>A structured path for growth</p>',
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$response = $this->postJson('/api/element/update', [
|
||||
'elementId' => $element->getId(),
|
||||
|
|
@ -128,7 +132,8 @@ class ElementsEndpointTest extends TestCase
|
|||
'description' => 'Updated description',
|
||||
'iconImageUrl' => '/assets/updated-icon.png',
|
||||
'richText' => '<p>Updated rich text</p>',
|
||||
'pdfPath' => '/assets/pdfs/updated.pdf',
|
||||
'shortPdfPath' => '/assets/pdfs/updated.pdf',
|
||||
'longPdfPath' => '/assets/pdfs/updated-long.pdf',
|
||||
'youtubeUrl' => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
]);
|
||||
|
||||
|
|
@ -144,21 +149,19 @@ class ElementsEndpointTest extends TestCase
|
|||
. 'dQw4w9WgXcQ';
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: '/assets/pdfs/baderech.pdf',
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
'/assets/baderech-haavodah-icon.png',
|
||||
'<p>A structured path for growth</p>',
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
|
|
@ -169,7 +172,8 @@ class ElementsEndpointTest extends TestCase
|
|||
'description' => 'Updated description',
|
||||
'iconImageUrl' => '/assets/updated-icon.png',
|
||||
'richText' => '<p>Updated rich text</p>',
|
||||
'pdfPath' => '/assets/pdfs/updated.pdf',
|
||||
'shortPdfPath' => '/assets/pdfs/updated.pdf',
|
||||
'longPdfPath' => '/assets/pdfs/updated-long.pdf',
|
||||
'youtubeUrl' => $sampleYoutubeUrl,
|
||||
]);
|
||||
|
||||
|
|
@ -181,6 +185,8 @@ class ElementsEndpointTest extends TestCase
|
|||
'description' => 'Updated description',
|
||||
'iconImageUrl' => '/assets/updated-icon.png',
|
||||
'richText' => '<p>Updated rich text</p>',
|
||||
'shortPdfPath' => '/assets/pdfs/updated.pdf',
|
||||
'longPdfPath' => '/assets/pdfs/updated-long.pdf',
|
||||
'pdfPath' => '/assets/pdfs/updated.pdf',
|
||||
'youtubeUrl' => $sampleYoutubeUrl,
|
||||
],
|
||||
|
|
@ -191,6 +197,52 @@ class ElementsEndpointTest extends TestCase
|
|||
'<p>Updated rich text</p>',
|
||||
$updatedElement->getRichText(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/updated-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthenticatedUpdateAcceptsLegacyPdfPath(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
'/assets/pdfs/baderech-long.pdf',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->postJson('/api/element/update', [
|
||||
'elementId' => $element->getId(),
|
||||
'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'],
|
||||
);
|
||||
}
|
||||
|
||||
public function testAuthenticatedUpdateClearsUploadedMedia(): void
|
||||
|
|
@ -201,26 +253,28 @@ class ElementsEndpointTest extends TestCase
|
|||
'icon bytes',
|
||||
);
|
||||
Storage::disk('public')->put(
|
||||
'element-pdfs/original.pdf',
|
||||
'pdf bytes',
|
||||
'element-pdfs/short/original.pdf',
|
||||
'short pdf bytes',
|
||||
);
|
||||
Storage::disk('public')->put(
|
||||
'element-pdfs/long/original-long.pdf',
|
||||
'long pdf bytes',
|
||||
);
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: 'element-icons/original-icon.png',
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: 'element-pdfs/original.pdf',
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
'element-icons/original-icon.png',
|
||||
'<p>A structured path for growth</p>',
|
||||
'element-pdfs/short/original.pdf',
|
||||
'element-pdfs/long/original-long.pdf',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
|
|
@ -229,21 +283,28 @@ class ElementsEndpointTest extends TestCase
|
|||
'elementId' => $element->getId(),
|
||||
'iconImageUrl' => '',
|
||||
'pdfPath' => '',
|
||||
'longPdfPath' => '',
|
||||
]);
|
||||
|
||||
$response->assertOk();
|
||||
$body = $response->json();
|
||||
$this->assertNull($body['element']['iconImageUrl']);
|
||||
$this->assertNull($body['element']['shortPdfPath']);
|
||||
$this->assertNull($body['element']['longPdfPath']);
|
||||
$this->assertNull($body['element']['pdfPath']);
|
||||
$updatedElement = $elementRepository->find($element->getId());
|
||||
$this->assertNotNull($updatedElement);
|
||||
$this->assertNull($updatedElement->getIconImageUrl());
|
||||
$this->assertNull($updatedElement->getPdfPath());
|
||||
$this->assertNull($updatedElement->getShortPdfPath());
|
||||
$this->assertNull($updatedElement->getLongPdfPath());
|
||||
Storage::disk('public')->assertMissing(
|
||||
'element-icons/original-icon.png',
|
||||
);
|
||||
Storage::disk('public')->assertMissing(
|
||||
'element-pdfs/original.pdf',
|
||||
'element-pdfs/short/original.pdf',
|
||||
);
|
||||
Storage::disk('public')->assertMissing(
|
||||
'element-pdfs/long/original-long.pdf',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -251,27 +312,26 @@ class ElementsEndpointTest extends TestCase
|
|||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$response = $this->post(
|
||||
'/api/element/update',
|
||||
[
|
||||
'elementId' => (string) $element->getId(),
|
||||
'iconImage' => $this->iconImageUpload(),
|
||||
'fileType' => 'iconImage',
|
||||
'file' => $this->iconImageUpload(),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
@ -286,21 +346,19 @@ class ElementsEndpointTest extends TestCase
|
|||
Storage::fake('public');
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
|
|
@ -309,7 +367,8 @@ class ElementsEndpointTest extends TestCase
|
|||
'/api/element/update',
|
||||
[
|
||||
'elementId' => (string) $element->getId(),
|
||||
'iconImage' => $this->iconImageUpload(),
|
||||
'fileType' => 'iconImage',
|
||||
'file' => $this->iconImageUpload(),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
@ -331,31 +390,30 @@ class ElementsEndpointTest extends TestCase
|
|||
Storage::disk('public')->assertExists($updatedIconImageUrl);
|
||||
}
|
||||
|
||||
public function testPdfUploadRequiresAuthentication(): void
|
||||
public function testShortPdfUploadRequiresAuthentication(): void
|
||||
{
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$response = $this->post(
|
||||
'/api/element/update',
|
||||
[
|
||||
'elementId' => (string) $element->getId(),
|
||||
'pdf' => $this->pdfUpload(),
|
||||
'fileType' => 'shortPdf',
|
||||
'file' => $this->pdfUpload(),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
@ -365,26 +423,24 @@ class ElementsEndpointTest extends TestCase
|
|||
]);
|
||||
}
|
||||
|
||||
public function testAuthenticatedPdfUploadReturnsElementPayload(): void
|
||||
public function testAuthenticatedShortPdfUploadReturnsElementPayload(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
$element = $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>A structured path for growth</p>',
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
|
|
@ -393,7 +449,8 @@ class ElementsEndpointTest extends TestCase
|
|||
'/api/element/update',
|
||||
[
|
||||
'elementId' => (string) $element->getId(),
|
||||
'pdf' => $this->pdfUpload(),
|
||||
'fileType' => 'shortPdf',
|
||||
'file' => $this->pdfUpload(),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
@ -401,17 +458,107 @@ class ElementsEndpointTest extends TestCase
|
|||
$body = $response->json();
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertStringContainsString(
|
||||
'/storage/element-pdfs/',
|
||||
'/storage/element-pdfs/short/',
|
||||
$body['element']['shortPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
$body['element']['shortPdfPath'],
|
||||
$body['element']['pdfPath'],
|
||||
);
|
||||
$updatedElement = $elementRepository->find($element->getId());
|
||||
$this->assertNotNull($updatedElement);
|
||||
$updatedPdfPath = $updatedElement->getPdfPath();
|
||||
$updatedPdfPath = $updatedElement->getShortPdfPath();
|
||||
$this->assertIsString($updatedPdfPath);
|
||||
$this->assertStringStartsWith('element-pdfs/', $updatedPdfPath);
|
||||
$this->assertStringStartsWith(
|
||||
'element-pdfs/short/',
|
||||
$updatedPdfPath,
|
||||
);
|
||||
Storage::disk('public')->assertExists($updatedPdfPath);
|
||||
}
|
||||
|
||||
public function testAuthenticatedLongPdfUploadReturnsElementPayload(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
$setRepository = app(SetRepository::class);
|
||||
$elementRepository = app(ElementRepository::class);
|
||||
$set = $this->createSet($setRepository);
|
||||
$element = $this->createElement(
|
||||
$elementRepository,
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$this->createSession('valid-token');
|
||||
|
||||
$response = $this->withCredentials()
|
||||
->withUnencryptedCookie('auth_token', 'valid-token')
|
||||
->post(
|
||||
'/api/element/update',
|
||||
[
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'longPdf',
|
||||
'file' => $this->pdfUpload(),
|
||||
],
|
||||
);
|
||||
|
||||
$response->assertOk();
|
||||
$body = $response->json();
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertStringContainsString(
|
||||
'/storage/element-pdfs/long/',
|
||||
$body['element']['longPdfPath'],
|
||||
);
|
||||
$updatedElement = $elementRepository->find($element->getId());
|
||||
$this->assertNotNull($updatedElement);
|
||||
$updatedPdfPath = $updatedElement->getLongPdfPath();
|
||||
$this->assertIsString($updatedPdfPath);
|
||||
$this->assertStringStartsWith(
|
||||
'element-pdfs/long/',
|
||||
$updatedPdfPath,
|
||||
);
|
||||
Storage::disk('public')->assertExists($updatedPdfPath);
|
||||
}
|
||||
|
||||
private function createSet(SetRepository $setRepository): Set
|
||||
{
|
||||
return $setRepository->create(new CreateSetDto(
|
||||
name: 'Baderech HaAvodah',
|
||||
description: 'A structured path for growth',
|
||||
iconImageUrl: '/assets/baderech-haavodah-icon.png',
|
||||
));
|
||||
}
|
||||
|
||||
private function createElement(
|
||||
ElementRepository $elementRepository,
|
||||
Set $set,
|
||||
string $title,
|
||||
string $description,
|
||||
?string $iconImageUrl,
|
||||
string $richText,
|
||||
?string $shortPdfPath,
|
||||
?string $longPdfPath,
|
||||
?string $youtubeUrl,
|
||||
?Element $parentElement,
|
||||
): Element {
|
||||
return $elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: $title,
|
||||
description: $description,
|
||||
iconImageUrl: $iconImageUrl,
|
||||
richText: $richText,
|
||||
shortPdfPath: $shortPdfPath,
|
||||
longPdfPath: $longPdfPath,
|
||||
youtubeUrl: $youtubeUrl,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
}
|
||||
|
||||
private function createSession(string $token): void
|
||||
{
|
||||
$userRepository = app(UserRepository::class);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,8 @@ class SetsEndpointTest extends TestCase
|
|||
description: $baderechSet->getDescription(),
|
||||
iconImageUrl: null,
|
||||
richText: '',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ use App\Element\UseCases\UpdateElement\UpdateDescription;
|
|||
use App\Element\UseCases\UpdateElement\UpdateElement;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
||||
use App\Set\Set as DomainSet;
|
||||
|
|
@ -40,13 +42,18 @@ class ElementControllerTest extends TestCase
|
|||
new UpdateDescription($this->elementRepo),
|
||||
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
||||
new UpdateRichText($this->elementRepo),
|
||||
new UpdatePdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateShortPdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateLongPdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateYoutubeUrl($this->elementRepo),
|
||||
new UpdateIconImage(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
new UpdatePdf(
|
||||
new UpdateShortPdf(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
new UpdateLongPdf(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
|
|
@ -69,6 +76,7 @@ class ElementControllerTest extends TestCase
|
|||
'/assets/baderech-icon.png',
|
||||
'<p>A structured path for growth</p>',
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
'/assets/pdfs/baderech-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -80,6 +88,7 @@ class ElementControllerTest extends TestCase
|
|||
'<p>Foundations rich text</p>',
|
||||
'/assets/pdfs/foundations.pdf',
|
||||
null,
|
||||
null,
|
||||
$element,
|
||||
);
|
||||
$secondChildElement = $this->createElement(
|
||||
|
|
@ -90,6 +99,7 @@ class ElementControllerTest extends TestCase
|
|||
'<p>Daily practice rich text</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$element,
|
||||
);
|
||||
|
||||
|
|
@ -111,6 +121,14 @@ class ElementControllerTest extends TestCase
|
|||
'/assets/baderech-icon.png',
|
||||
$body['element']['iconImageUrl'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
$body['element']['shortPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech-long.pdf',
|
||||
$body['element']['longPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
$body['element']['pdfPath'],
|
||||
|
|
@ -158,21 +176,13 @@ class ElementControllerTest extends TestCase
|
|||
public function testUpdateWithIconImageReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$element = $this->createEmptyElement($set);
|
||||
$fixturePath = __DIR__ . '/../../fixtures/icon.png';
|
||||
$request = new Request([], [
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'iconImage',
|
||||
], [], [], [
|
||||
'iconImage' => new UploadedFile(
|
||||
'file' => new UploadedFile(
|
||||
$fixturePath,
|
||||
'icon.png',
|
||||
'image/png',
|
||||
|
|
@ -196,24 +206,16 @@ class ElementControllerTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdateWithPdfReturnsElementPayload(): void
|
||||
public function testUpdateWithShortPdfReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$element = $this->createEmptyElement($set);
|
||||
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
||||
$request = new Request([], [
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'shortPdf',
|
||||
], [], [], [
|
||||
'pdf' => new UploadedFile(
|
||||
'file' => new UploadedFile(
|
||||
$fixturePath,
|
||||
'baderech.pdf',
|
||||
'application/pdf',
|
||||
|
|
@ -228,11 +230,48 @@ class ElementControllerTest extends TestCase
|
|||
$body = json_decode($response->getContent(), true);
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertSame(
|
||||
'https://test.local/storage/element-pdfs/fake-baderech.pdf',
|
||||
'https://test.local/storage/element-pdfs/short/fake-baderech.pdf',
|
||||
$body['element']['shortPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
$body['element']['shortPdfPath'],
|
||||
$body['element']['pdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs',
|
||||
'element-pdfs/short',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateWithLongPdfReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createEmptyElement($set);
|
||||
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
||||
$request = new Request([], [
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'longPdf',
|
||||
], [], [], [
|
||||
'file' => new UploadedFile(
|
||||
$fixturePath,
|
||||
'baderech.pdf',
|
||||
'application/pdf',
|
||||
null,
|
||||
true,
|
||||
),
|
||||
], ['REQUEST_METHOD' => 'POST']);
|
||||
|
||||
$response = $this->controller->update($request);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertSame(
|
||||
'https://test.local/storage/element-pdfs/long/fake-baderech.pdf',
|
||||
$body['element']['longPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
}
|
||||
|
|
@ -247,13 +286,29 @@ class ElementControllerTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
private function createEmptyElement(DomainSet $set): Element
|
||||
{
|
||||
return $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
private function createElement(
|
||||
DomainSet $set,
|
||||
string $title,
|
||||
string $description,
|
||||
?string $iconImageUrl,
|
||||
string $richText,
|
||||
?string $pdfPath,
|
||||
?string $shortPdfPath,
|
||||
?string $longPdfPath,
|
||||
?string $youtubeUrl,
|
||||
?Element $parentElement,
|
||||
): Element {
|
||||
|
|
@ -263,7 +318,8 @@ class ElementControllerTest extends TestCase
|
|||
description: $description,
|
||||
iconImageUrl: $iconImageUrl,
|
||||
richText: $richText,
|
||||
pdfPath: $pdfPath,
|
||||
shortPdfPath: $shortPdfPath,
|
||||
longPdfPath: $longPdfPath,
|
||||
youtubeUrl: $youtubeUrl,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ class ElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
set: $set,
|
||||
parentElement: null,
|
||||
|
|
@ -33,7 +34,8 @@ class ElementTest extends TestCase
|
|||
description: 'Child description',
|
||||
iconImageUrl: '/assets/child-icon.svg',
|
||||
richText: '<p>Child rich text</p>',
|
||||
pdfPath: '/assets/pdfs/child.pdf',
|
||||
shortPdfPath: '/assets/pdfs/child.pdf',
|
||||
longPdfPath: '/assets/pdfs/child-long.pdf',
|
||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
set: $set,
|
||||
parentElement: $rootElement,
|
||||
|
|
@ -55,7 +57,11 @@ class ElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/child.pdf',
|
||||
$childElement->getPdfPath(),
|
||||
$childElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/child-long.pdf',
|
||||
$childElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
|
|
@ -64,7 +70,8 @@ class ElementTest extends TestCase
|
|||
$this->assertSame($set, $childElement->getSet());
|
||||
$this->assertSame($rootElement, $childElement->getParentElement());
|
||||
$this->assertNull($rootElement->getIconImageUrl());
|
||||
$this->assertNull($rootElement->getPdfPath());
|
||||
$this->assertNull($rootElement->getShortPdfPath());
|
||||
$this->assertNull($rootElement->getLongPdfPath());
|
||||
$this->assertNull($rootElement->getYoutubeUrl());
|
||||
$this->assertNull($rootElement->getParentElement());
|
||||
}
|
||||
|
|
@ -83,7 +90,8 @@ class ElementTest extends TestCase
|
|||
description: 'Original description',
|
||||
iconImageUrl: '/assets/original.svg',
|
||||
richText: '<p>Original</p>',
|
||||
pdfPath: '/assets/pdfs/original.pdf',
|
||||
shortPdfPath: '/assets/pdfs/original.pdf',
|
||||
longPdfPath: '/assets/pdfs/original-long.pdf',
|
||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
|
||||
set: $set,
|
||||
parentElement: null,
|
||||
|
|
@ -93,14 +101,16 @@ class ElementTest extends TestCase
|
|||
$element->setDescription('Updated description');
|
||||
$element->setIconImageUrl(null);
|
||||
$element->setRichText('<p>Updated</p>');
|
||||
$element->setPdfPath(null);
|
||||
$element->setShortPdfPath(null);
|
||||
$element->setLongPdfPath(null);
|
||||
$element->setYoutubeUrl(null);
|
||||
|
||||
$this->assertSame('Updated', $element->getTitle());
|
||||
$this->assertSame('Updated description', $element->getDescription());
|
||||
$this->assertNull($element->getIconImageUrl());
|
||||
$this->assertSame('<p>Updated</p>', $element->getRichText());
|
||||
$this->assertNull($element->getPdfPath());
|
||||
$this->assertNull($element->getShortPdfPath());
|
||||
$this->assertNull($element->getLongPdfPath());
|
||||
$this->assertNull($element->getYoutubeUrl());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: '/assets/root-icon.svg',
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: '/assets/pdfs/root.pdf',
|
||||
shortPdfPath: '/assets/pdfs/root.pdf',
|
||||
longPdfPath: '/assets/pdfs/root-long.pdf',
|
||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -63,7 +64,14 @@ class CreateElementTest extends TestCase
|
|||
$element->getIconImageUrl(),
|
||||
);
|
||||
$this->assertSame('<p>Root rich text</p>', $element->getRichText());
|
||||
$this->assertSame('/assets/pdfs/root.pdf', $element->getPdfPath());
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/root.pdf',
|
||||
$element->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/root-long.pdf',
|
||||
$element->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
$element->getYoutubeUrl(),
|
||||
|
|
@ -82,7 +90,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
)
|
||||
|
|
@ -95,7 +104,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Child description',
|
||||
iconImageUrl: '/assets/child-icon.svg',
|
||||
richText: '<p>Child rich text</p>',
|
||||
pdfPath: '/assets/pdfs/child.pdf',
|
||||
shortPdfPath: '/assets/pdfs/child.pdf',
|
||||
longPdfPath: '/assets/pdfs/child-long.pdf',
|
||||
youtubeUrl: 'https://youtu.be/yHx-r4p6hHU',
|
||||
parentElementId: $rootElement->getId(),
|
||||
)
|
||||
|
|
@ -116,7 +126,11 @@ class CreateElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/child.pdf',
|
||||
$childElement->getPdfPath(),
|
||||
$childElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/child-long.pdf',
|
||||
$childElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://youtu.be/yHx-r4p6hHU',
|
||||
|
|
@ -138,7 +152,8 @@ class CreateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -146,7 +161,8 @@ class CreateElementTest extends TestCase
|
|||
$this->assertSame('', $element->getDescription());
|
||||
$this->assertNull($element->getIconImageUrl());
|
||||
$this->assertSame('', $element->getRichText());
|
||||
$this->assertNull($element->getPdfPath());
|
||||
$this->assertNull($element->getShortPdfPath());
|
||||
$this->assertNull($element->getLongPdfPath());
|
||||
$this->assertNull($element->getYoutubeUrl());
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +176,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: '',
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -168,7 +185,7 @@ class CreateElementTest extends TestCase
|
|||
$this->assertNull($element->getIconImageUrl());
|
||||
}
|
||||
|
||||
public function testCreatesElementWithNullPdfPathWhenBlank(): void
|
||||
public function testCreatesElementWithNullPdfPathsWhenBlank(): void
|
||||
{
|
||||
$set = $this->createSet('Daily learning');
|
||||
|
||||
|
|
@ -178,12 +195,14 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: '',
|
||||
shortPdfPath: '',
|
||||
longPdfPath: '',
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
||||
$this->assertNull($element->getPdfPath());
|
||||
$this->assertNull($element->getShortPdfPath());
|
||||
$this->assertNull($element->getLongPdfPath());
|
||||
}
|
||||
|
||||
public function testCreatesElementWithNullYoutubeUrlWhenBlank(): void
|
||||
|
|
@ -196,7 +215,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: '',
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -215,7 +235,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -232,7 +253,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -249,7 +271,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -270,7 +293,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Child description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Child rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: 99,
|
||||
));
|
||||
|
|
@ -285,7 +309,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -301,7 +326,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Another root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Another root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
));
|
||||
|
|
@ -318,7 +344,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Parent root description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Parent root rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: null,
|
||||
)
|
||||
|
|
@ -335,7 +362,8 @@ class CreateElementTest extends TestCase
|
|||
description: 'Invalid child description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Invalid child rich text</p>',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElementId: $parentElement->getId(),
|
||||
));
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class GetElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
$foundElement->getPdfPath(),
|
||||
$foundElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
|
|
@ -201,7 +201,8 @@ class GetElementTest extends TestCase
|
|||
description: $description,
|
||||
iconImageUrl: $iconImageUrl,
|
||||
richText: $richText,
|
||||
pdfPath: $pdfPath,
|
||||
shortPdfPath: $pdfPath,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: $youtubeUrl,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -8,8 +8,10 @@ use App\Element\UseCases\UpdateElement\UpdateDescription;
|
|||
use App\Element\UseCases\UpdateElement\UpdateDescriptionRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrlRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfPathRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPathRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPathRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||
use App\Element\UseCases\UpdateElement\UpdateRichTextRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||
|
|
@ -134,19 +136,26 @@ class UpdateElementFieldsTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdatePdfPathClearsEmptyString(): void
|
||||
public function testUpdateShortPdfPathClearsEmptyString(): void
|
||||
{
|
||||
$element = $this->createFilledElement();
|
||||
$updatePdfPath = new UpdatePdfPath(
|
||||
$updateShortPdfPath = new UpdateShortPdfPath(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
);
|
||||
|
||||
$updatedElement = $updatePdfPath->execute(
|
||||
new UpdatePdfPathRequest(id: $element->getId(), pdfPath: '')
|
||||
$updatedElement = $updateShortPdfPath->execute(
|
||||
new UpdateShortPdfPathRequest(
|
||||
id: $element->getId(),
|
||||
shortPdfPath: '',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNull($updatedElement->getPdfPath());
|
||||
$this->assertNull($updatedElement->getShortPdfPath());
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
|
||||
$this->assertSame(
|
||||
['/assets/pdfs/original.pdf'],
|
||||
|
|
@ -154,6 +163,33 @@ class UpdateElementFieldsTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdateLongPdfPathClearsEmptyString(): void
|
||||
{
|
||||
$element = $this->createFilledElement();
|
||||
$updateLongPdfPath = new UpdateLongPdfPath(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
);
|
||||
|
||||
$updatedElement = $updateLongPdfPath->execute(
|
||||
new UpdateLongPdfPathRequest(
|
||||
id: $element->getId(),
|
||||
longPdfPath: '',
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original.pdf',
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertNull($updatedElement->getLongPdfPath());
|
||||
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
|
||||
$this->assertSame(
|
||||
['/assets/pdfs/original-long.pdf'],
|
||||
$this->fileUploader->deletedPaths,
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateYoutubeUrlClearsEmptyString(): void
|
||||
{
|
||||
$element = $this->createFilledElement();
|
||||
|
|
@ -175,12 +211,14 @@ class UpdateElementFieldsTest extends TestCase
|
|||
return $this->createElementWithMedia(
|
||||
'/assets/original-icon.png',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
);
|
||||
}
|
||||
|
||||
private function createElementWithMedia(
|
||||
?string $iconImageUrl,
|
||||
?string $pdfPath,
|
||||
?string $shortPdfPath,
|
||||
?string $longPdfPath,
|
||||
): Element {
|
||||
$set = new DomainSet(
|
||||
id: 1,
|
||||
|
|
@ -195,7 +233,8 @@ class UpdateElementFieldsTest extends TestCase
|
|||
description: 'Original description',
|
||||
iconImageUrl: $iconImageUrl,
|
||||
richText: '<p>Original rich text</p>',
|
||||
pdfPath: $pdfPath,
|
||||
shortPdfPath: $shortPdfPath,
|
||||
longPdfPath: $longPdfPath,
|
||||
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
|
||||
parentElement: null,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -9,9 +9,11 @@ use App\Element\UseCases\UpdateElement\UpdateElement;
|
|||
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
||||
use App\Exceptions\BadRequestException;
|
||||
|
|
@ -38,13 +40,18 @@ class UpdateElementTest extends TestCase
|
|||
new UpdateDescription($this->elementRepo),
|
||||
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
||||
new UpdateRichText($this->elementRepo),
|
||||
new UpdatePdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateShortPdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateLongPdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateYoutubeUrl($this->elementRepo),
|
||||
new UpdateIconImage(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
new UpdatePdf(
|
||||
new UpdateShortPdf(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
new UpdateLongPdf(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
|
|
@ -62,6 +69,7 @@ class UpdateElementTest extends TestCase
|
|||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -73,16 +81,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: '/assets/updated-icon.png',
|
||||
richText: '<p>Updated rich text</p>',
|
||||
pdfPath: '/assets/pdfs/updated.pdf',
|
||||
shortPdfPath: '/assets/pdfs/updated.pdf',
|
||||
longPdfPath: '/assets/pdfs/updated-long.pdf',
|
||||
pdfPath: null,
|
||||
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -102,7 +109,11 @@ class UpdateElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/updated.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/updated-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
|
|
@ -114,6 +125,50 @@ class UpdateElementTest extends TestCase
|
|||
$this->assertSame('Updated title', $persistedElement->getTitle());
|
||||
}
|
||||
|
||||
public function testLegacyPdfPathUpdatesShortPdfPath(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Original title',
|
||||
'Original description',
|
||||
null,
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
null,
|
||||
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->assertSame(
|
||||
'/assets/pdfs/legacy-updated.pdf',
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testConvertsEmptyNullableFieldsToNull(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
|
|
@ -124,6 +179,7 @@ class UpdateElementTest extends TestCase
|
|||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -135,21 +191,21 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: '',
|
||||
richText: '<p>Updated rich text</p>',
|
||||
pdfPath: '',
|
||||
shortPdfPath: '',
|
||||
longPdfPath: '',
|
||||
pdfPath: null,
|
||||
youtubeUrl: '',
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNull($updatedElement->getIconImageUrl());
|
||||
$this->assertNull($updatedElement->getPdfPath());
|
||||
$this->assertNull($updatedElement->getShortPdfPath());
|
||||
$this->assertNull($updatedElement->getLongPdfPath());
|
||||
$this->assertNull($updatedElement->getYoutubeUrl());
|
||||
}
|
||||
|
||||
|
|
@ -163,6 +219,7 @@ class UpdateElementTest extends TestCase
|
|||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -174,16 +231,15 @@ class UpdateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -202,7 +258,11 @@ class UpdateElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
|
|
@ -210,7 +270,7 @@ class UpdateElementTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdatesUploadedFiles(): void
|
||||
public function testRoutesUploadedFilesByFileType(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
|
|
@ -222,8 +282,41 @@ class UpdateElementTest extends TestCase
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: 'iconImage',
|
||||
fileContents: 'binary-image-bytes',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: 'shortPdf',
|
||||
fileContents: 'binary-short-pdf-bytes',
|
||||
fileOriginalName: 'baderech.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
$updatedElement = $this->updateElement->execute(
|
||||
new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
|
|
@ -231,16 +324,15 @@ class UpdateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: 'binary-image-bytes',
|
||||
iconImageOriginalName: 'icon.png',
|
||||
iconImageMimeType: 'image/png',
|
||||
iconImageSizeBytes: 1024,
|
||||
pdfContents: 'binary-pdf-bytes',
|
||||
pdfOriginalName: 'baderech.pdf',
|
||||
pdfMimeType: 'application/pdf',
|
||||
pdfSizeBytes: 1024,
|
||||
fileType: 'longPdf',
|
||||
fileContents: 'binary-long-pdf-bytes',
|
||||
fileOriginalName: 'baderech-long.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 1024,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -249,17 +341,71 @@ class UpdateElementTest extends TestCase
|
|||
$updatedElement->getIconImageUrl(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/fake-baderech.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
'element-pdfs/short/fake-baderech.pdf',
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long/fake-baderech-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-icons',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs',
|
||||
'element-pdfs/short',
|
||||
$this->fileUploader->uploads[1]['folder'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long',
|
||||
$this->fileUploader->uploads[2]['folder'],
|
||||
);
|
||||
}
|
||||
|
||||
public function testThrowsWhenFileTypeMissingForUpload(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('fileType is required');
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: 1,
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: null,
|
||||
fileContents: 'binary-image-bytes',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
}
|
||||
|
||||
public function testThrowsWhenFileTypeInvalid(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('fileType is invalid');
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: 1,
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: 'audio',
|
||||
fileContents: 'binary-audio-bytes',
|
||||
fileOriginalName: 'shiur.mp3',
|
||||
fileMimeType: 'audio/mpeg',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
}
|
||||
|
||||
public function testThrowsWhenIdMissing(): void
|
||||
|
|
@ -273,16 +419,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Updated rich text</p>',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -297,16 +442,15 @@ class UpdateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -321,16 +465,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Updated rich text</p>',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -345,16 +488,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Updated rich text</p>',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +516,8 @@ class UpdateElementTest extends TestCase
|
|||
string $description,
|
||||
?string $iconImageUrl,
|
||||
string $richText,
|
||||
?string $pdfPath,
|
||||
?string $shortPdfPath,
|
||||
?string $longPdfPath,
|
||||
?string $youtubeUrl,
|
||||
?Element $parentElement,
|
||||
): Element {
|
||||
|
|
@ -384,7 +527,8 @@ class UpdateElementTest extends TestCase
|
|||
description: $description,
|
||||
iconImageUrl: $iconImageUrl,
|
||||
richText: $richText,
|
||||
pdfPath: $pdfPath,
|
||||
shortPdfPath: $shortPdfPath,
|
||||
longPdfPath: $longPdfPath,
|
||||
youtubeUrl: $youtubeUrl,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
|
|
|
|||
|
|
@ -33,19 +33,19 @@ class UpdateIconImageTest extends TestCase
|
|||
|
||||
/**
|
||||
* @return array{
|
||||
* iconImageContents: string,
|
||||
* iconImageOriginalName: string,
|
||||
* iconImageMimeType: string,
|
||||
* iconImageSizeBytes: int
|
||||
* fileContents: string,
|
||||
* fileOriginalName: string,
|
||||
* fileMimeType: string,
|
||||
* fileSizeBytes: int
|
||||
* }
|
||||
*/
|
||||
private function imageArgs(): array
|
||||
{
|
||||
return [
|
||||
'iconImageContents' => 'binary-image-bytes',
|
||||
'iconImageOriginalName' => 'icon.png',
|
||||
'iconImageMimeType' => 'image/png',
|
||||
'iconImageSizeBytes' => 1024,
|
||||
'fileContents' => 'binary-image-bytes',
|
||||
'fileOriginalName' => 'icon.png',
|
||||
'fileMimeType' => 'image/png',
|
||||
'fileSizeBytes' => 1024,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -97,10 +97,10 @@ class UpdateIconImageTest extends TestCase
|
|||
$this->useCase->execute(
|
||||
new UpdateIconImageRequest(
|
||||
id: 1,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -115,10 +115,10 @@ class UpdateIconImageTest extends TestCase
|
|||
$this->useCase->execute(
|
||||
new UpdateIconImageRequest(
|
||||
id: 1,
|
||||
iconImageContents: 'not-an-image',
|
||||
iconImageOriginalName: 'icon.pdf',
|
||||
iconImageMimeType: 'application/pdf',
|
||||
iconImageSizeBytes: 1024,
|
||||
fileContents: 'not-an-image',
|
||||
fileOriginalName: 'icon.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 1024,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -131,10 +131,10 @@ class UpdateIconImageTest extends TestCase
|
|||
$this->useCase->execute(
|
||||
new UpdateIconImageRequest(
|
||||
id: 1,
|
||||
iconImageContents: 'big',
|
||||
iconImageOriginalName: 'icon.png',
|
||||
iconImageMimeType: 'image/png',
|
||||
iconImageSizeBytes: 6 * 1024 * 1024,
|
||||
fileContents: 'big',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 6 * 1024 * 1024,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -167,7 +167,8 @@ class UpdateIconImageTest extends TestCase
|
|||
description: 'Original description',
|
||||
iconImageUrl: null,
|
||||
richText: '',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
|
|
|
|||
95
backend/tests/Unit/Element/UseCases/UpdateLongPdfTest.php
Normal file
95
backend/tests/Unit/Element/UseCases/UpdateLongPdfTest.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Element\UseCases;
|
||||
|
||||
use App\Element\CreateElementDto;
|
||||
use App\Element\Element;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfRequest;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Set\Set as DomainSet;
|
||||
use Tests\Fakes\FakeElementRepository;
|
||||
use Tests\Fakes\FakeFileUploader;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdateLongPdfTest extends TestCase
|
||||
{
|
||||
private FakeElementRepository $elementRepository;
|
||||
|
||||
private FakeFileUploader $fileUploader;
|
||||
|
||||
private UpdateLongPdf $useCase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->elementRepository = new FakeElementRepository();
|
||||
$this->fileUploader = new FakeFileUploader();
|
||||
$this->useCase = new UpdateLongPdf(
|
||||
$this->elementRepository,
|
||||
$this->fileUploader,
|
||||
);
|
||||
}
|
||||
|
||||
public function testUploadsLongPdfAndStoresPath(): void
|
||||
{
|
||||
$element = $this->createElement();
|
||||
|
||||
$updatedElement = $this->useCase->execute(
|
||||
new UpdateLongPdfRequest(
|
||||
id: $element->getId(),
|
||||
fileContents: 'binary-pdf-bytes',
|
||||
fileOriginalName: 'baderech-long.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 1024,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNull($updatedElement->getShortPdfPath());
|
||||
$this->assertSame(
|
||||
'element-pdfs/long/fake-baderech-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
}
|
||||
|
||||
public function testDisallowedMimeThrowsBadRequest(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('pdf must be a pdf file');
|
||||
|
||||
$this->useCase->execute(
|
||||
new UpdateLongPdfRequest(
|
||||
id: 1,
|
||||
fileContents: 'not-a-pdf',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 1024,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private function createElement(): Element
|
||||
{
|
||||
$set = new DomainSet(
|
||||
id: 1,
|
||||
name: 'Baderech',
|
||||
description: 'Baderech description',
|
||||
iconImageUrl: '/assets/baderech-icon.png',
|
||||
);
|
||||
|
||||
return $this->elementRepository->create(new CreateElementDto(
|
||||
set: $set,
|
||||
title: 'Original title',
|
||||
description: 'Original description',
|
||||
iconImageUrl: null,
|
||||
richText: '',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,8 +4,8 @@ namespace Tests\Unit\Element\UseCases;
|
|||
|
||||
use App\Element\CreateElementDto;
|
||||
use App\Element\Element;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfRequest;
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Exceptions\NotFoundException;
|
||||
use App\Set\Set as DomainSet;
|
||||
|
|
@ -13,19 +13,19 @@ use Tests\Fakes\FakeElementRepository;
|
|||
use Tests\Fakes\FakeFileUploader;
|
||||
use Tests\TestCase;
|
||||
|
||||
class UpdatePdfTest extends TestCase
|
||||
class UpdateShortPdfTest extends TestCase
|
||||
{
|
||||
private FakeElementRepository $elementRepository;
|
||||
|
||||
private FakeFileUploader $fileUploader;
|
||||
|
||||
private UpdatePdf $useCase;
|
||||
private UpdateShortPdf $useCase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->elementRepository = new FakeElementRepository();
|
||||
$this->fileUploader = new FakeFileUploader();
|
||||
$this->useCase = new UpdatePdf(
|
||||
$this->useCase = new UpdateShortPdf(
|
||||
$this->elementRepository,
|
||||
$this->fileUploader,
|
||||
);
|
||||
|
|
@ -33,45 +33,46 @@ class UpdatePdfTest extends TestCase
|
|||
|
||||
/**
|
||||
* @return array{
|
||||
* pdfContents: string,
|
||||
* pdfOriginalName: string,
|
||||
* pdfMimeType: string,
|
||||
* pdfSizeBytes: int
|
||||
* fileContents: string,
|
||||
* fileOriginalName: string,
|
||||
* fileMimeType: string,
|
||||
* fileSizeBytes: int
|
||||
* }
|
||||
*/
|
||||
private function pdfArgs(): array
|
||||
{
|
||||
return [
|
||||
'pdfContents' => 'binary-pdf-bytes',
|
||||
'pdfOriginalName' => 'baderech.pdf',
|
||||
'pdfMimeType' => 'application/pdf',
|
||||
'pdfSizeBytes' => 1024,
|
||||
'fileContents' => 'binary-pdf-bytes',
|
||||
'fileOriginalName' => 'baderech.pdf',
|
||||
'fileMimeType' => 'application/pdf',
|
||||
'fileSizeBytes' => 1024,
|
||||
];
|
||||
}
|
||||
|
||||
public function testUploadsPdfAndStoresPath(): void
|
||||
public function testUploadsShortPdfAndStoresPath(): void
|
||||
{
|
||||
$element = $this->createElement();
|
||||
|
||||
$updatedElement = $this->useCase->execute(
|
||||
new UpdatePdfRequest(
|
||||
new UpdateShortPdfRequest(
|
||||
...$this->pdfArgs(),
|
||||
id: $element->getId(),
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'element-pdfs/fake-baderech.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
'element-pdfs/short/fake-baderech.pdf',
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertNull($updatedElement->getLongPdfPath());
|
||||
$storedElement = $this->elementRepository->find($element->getId());
|
||||
$this->assertNotNull($storedElement);
|
||||
$this->assertSame(
|
||||
'element-pdfs/fake-baderech.pdf',
|
||||
$storedElement->getPdfPath(),
|
||||
'element-pdfs/short/fake-baderech.pdf',
|
||||
$storedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs',
|
||||
'element-pdfs/short',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
}
|
||||
|
|
@ -82,7 +83,7 @@ class UpdatePdfTest extends TestCase
|
|||
$this->expectExceptionMessage('id is required');
|
||||
|
||||
$this->useCase->execute(
|
||||
new UpdatePdfRequest(
|
||||
new UpdateShortPdfRequest(
|
||||
...$this->pdfArgs(),
|
||||
id: null,
|
||||
)
|
||||
|
|
@ -95,12 +96,12 @@ class UpdatePdfTest extends TestCase
|
|||
$this->expectExceptionMessage('pdf is required');
|
||||
|
||||
$this->useCase->execute(
|
||||
new UpdatePdfRequest(
|
||||
new UpdateShortPdfRequest(
|
||||
id: 1,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -111,12 +112,12 @@ class UpdatePdfTest extends TestCase
|
|||
$this->expectExceptionMessage('pdf must be a pdf file');
|
||||
|
||||
$this->useCase->execute(
|
||||
new UpdatePdfRequest(
|
||||
new UpdateShortPdfRequest(
|
||||
id: 1,
|
||||
pdfContents: 'not-a-pdf',
|
||||
pdfOriginalName: 'icon.png',
|
||||
pdfMimeType: 'image/png',
|
||||
pdfSizeBytes: 1024,
|
||||
fileContents: 'not-a-pdf',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 1024,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -127,12 +128,12 @@ class UpdatePdfTest extends TestCase
|
|||
$this->expectExceptionMessage('pdf must be 10MB or smaller');
|
||||
|
||||
$this->useCase->execute(
|
||||
new UpdatePdfRequest(
|
||||
new UpdateShortPdfRequest(
|
||||
id: 1,
|
||||
pdfContents: 'big',
|
||||
pdfOriginalName: 'baderech.pdf',
|
||||
pdfMimeType: 'application/pdf',
|
||||
pdfSizeBytes: 11 * 1024 * 1024,
|
||||
fileContents: 'big',
|
||||
fileOriginalName: 'baderech.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 11 * 1024 * 1024,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -143,7 +144,7 @@ class UpdatePdfTest extends TestCase
|
|||
$this->expectExceptionMessage('Element not found');
|
||||
|
||||
$this->useCase->execute(
|
||||
new UpdatePdfRequest(
|
||||
new UpdateShortPdfRequest(
|
||||
...$this->pdfArgs(),
|
||||
id: 999,
|
||||
)
|
||||
|
|
@ -165,7 +166,8 @@ class UpdatePdfTest extends TestCase
|
|||
description: 'Original description',
|
||||
iconImageUrl: null,
|
||||
richText: '',
|
||||
pdfPath: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
youtubeUrl: null,
|
||||
parentElement: null,
|
||||
));
|
||||
Loading…
Add table
Add a link
Reference in a new issue