test unified uploads

This commit is contained in:
Yisroel Baum 2026-06-02 16:06:59 +03:00
parent a2c3ffad8b
commit b6da71ecd2
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
6 changed files with 144 additions and 27 deletions

View file

@ -7,6 +7,8 @@ use App\Element\Element;
use App\Element\UseCases\UpdateElement\UpdateDescription;
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
use App\Element\UseCases\UpdateElement\UpdateElement;
use App\Element\UseCases\UpdateElement\UpdateElementIconImage;
use App\Element\UseCases\UpdateElement\UpdateElementPdf;
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
use App\Element\UseCases\UpdateElement\UpdateRichText;
@ -16,17 +18,21 @@ use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
use App\Set\Set as DomainSet;
use Tests\Fakes\FakeElementRepository;
use Tests\Fakes\FakeFileUploader;
use Tests\TestCase;
class UpdateElementTest extends TestCase
{
private FakeElementRepository $elementRepo;
private FakeFileUploader $fileUploader;
private UpdateElement $updateElement;
protected function setUp(): void
{
$this->elementRepo = new FakeElementRepository();
$this->fileUploader = new FakeFileUploader();
$this->updateElement = new UpdateElement(
new UpdateTitle($this->elementRepo),
new UpdateDescription($this->elementRepo),
@ -34,6 +40,14 @@ class UpdateElementTest extends TestCase
new UpdateRichText($this->elementRepo),
new UpdatePdfPath($this->elementRepo),
new UpdateYoutubeUrl($this->elementRepo),
new UpdateElementIconImage(
$this->elementRepo,
$this->fileUploader,
),
new UpdateElementPdf(
$this->elementRepo,
$this->fileUploader,
),
$this->elementRepo,
);
}
@ -61,6 +75,14 @@ class UpdateElementTest extends TestCase
richText: '<p>Updated rich text</p>',
pdfPath: '/assets/pdfs/updated.pdf',
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
)
);
@ -115,6 +137,14 @@ class UpdateElementTest extends TestCase
richText: '<p>Updated rich text</p>',
pdfPath: '',
youtubeUrl: '',
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
)
);
@ -146,6 +176,14 @@ class UpdateElementTest extends TestCase
richText: null,
pdfPath: null,
youtubeUrl: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
)
);
@ -172,6 +210,58 @@ class UpdateElementTest extends TestCase
);
}
public function testUpdatesUploadedFiles(): void
{
$set = $this->createSet(1, 'Baderech');
$element = $this->createElement(
$set,
'Original title',
'Original description',
null,
'<p>Original rich text</p>',
null,
null,
null,
);
$updatedElement = $this->updateElement->execute(
new UpdateElementRequest(
id: $element->getId(),
title: null,
description: null,
iconImageUrl: null,
richText: 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,
)
);
$this->assertSame(
'element-icons/fake-icon.png',
$updatedElement->getIconImageUrl(),
);
$this->assertSame(
'element-pdfs/fake-baderech.pdf',
$updatedElement->getPdfPath(),
);
$this->assertSame(
'element-icons',
$this->fileUploader->uploads[0]['folder'],
);
$this->assertSame(
'element-pdfs',
$this->fileUploader->uploads[1]['folder'],
);
}
public function testThrowsWhenIdMissing(): void
{
$this->expectException(BadRequestException::class);
@ -185,6 +275,14 @@ class UpdateElementTest extends TestCase
richText: '<p>Updated rich text</p>',
pdfPath: null,
youtubeUrl: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
));
}
@ -201,6 +299,14 @@ class UpdateElementTest extends TestCase
richText: null,
pdfPath: null,
youtubeUrl: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
));
}
@ -217,6 +323,14 @@ class UpdateElementTest extends TestCase
richText: '<p>Updated rich text</p>',
pdfPath: null,
youtubeUrl: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
));
}
@ -233,6 +347,14 @@ class UpdateElementTest extends TestCase
richText: '<p>Updated rich text</p>',
pdfPath: null,
youtubeUrl: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
pdfContents: null,
pdfOriginalName: null,
pdfMimeType: null,
pdfSizeBytes: null,
));
}