test icon uploads

This commit is contained in:
Yisroel Baum 2026-06-02 10:17:21 +03:00
parent 77dc4173b6
commit 0f3bb6de6b
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
4 changed files with 356 additions and 1 deletions

View file

@ -8,13 +8,17 @@ use App\Element\Element;
use App\Element\UseCases\GetElement\GetElement;
use App\Element\UseCases\UpdateElement\UpdateDescription;
use App\Element\UseCases\UpdateElement\UpdateElement;
use App\Element\UseCases\UpdateElement\UpdateElementIconImage;
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
use App\Element\UseCases\UpdateElement\UpdateRichText;
use App\Element\UseCases\UpdateElement\UpdateTitle;
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
use App\Set\Set as DomainSet;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Tests\Fakes\FakeElementRepository;
use Tests\Fakes\FakeFileUploader;
use Tests\TestCase;
class ElementControllerTest extends TestCase
@ -23,9 +27,12 @@ class ElementControllerTest extends TestCase
private FakeElementRepository $elementRepo;
private FakeFileUploader $fileUploader;
protected function setUp(): void
{
$this->elementRepo = new FakeElementRepository();
$this->fileUploader = new FakeFileUploader();
$getElement = new GetElement($this->elementRepo);
$updateElement = new UpdateElement(
new UpdateTitle($this->elementRepo),
@ -36,7 +43,15 @@ class ElementControllerTest extends TestCase
new UpdateYoutubeUrl($this->elementRepo),
$this->elementRepo,
);
$this->controller = new ElementController($getElement, $updateElement);
$this->controller = new ElementController(
$getElement,
$updateElement,
new UpdateElementIconImage(
$this->elementRepo,
$this->fileUploader,
),
$this->fileUploader,
);
}
public function testShowReturnsElementPayload(): void
@ -135,6 +150,50 @@ class ElementControllerTest extends TestCase
);
}
public function testUploadIconImageReturnsElementPayload(): 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,
);
$fixturePath = __DIR__
. '/../../../../frontend/rabbi_gerzi/public/assets/'
. 'baderech-haavodah-icon.png';
$request = new Request([], [], [], [], [
'iconImage' => new UploadedFile(
$fixturePath,
'icon.png',
'image/png',
null,
true,
),
]);
$response = $this->controller->uploadIconImage(
$element->getId(),
$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-icons/fake-icon.png',
$body['element']['iconImageUrl'],
);
$this->assertSame(
'element-icons',
$this->fileUploader->uploads[0]['folder'],
);
}
private function createSet(int $id, string $name): DomainSet
{
return new DomainSet(