add element updates

This commit is contained in:
Yisroel Baum 2026-05-28 20:08:36 +03:00
parent 6d0acaae56
commit 73b0befc97
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
10 changed files with 223 additions and 13 deletions

View file

@ -5,6 +5,7 @@ namespace Tests\Fakes;
use App\Element\CreateElementDto;
use App\Element\Element;
use App\Element\ElementRepository;
use App\Element\UpdateElementDto;
use App\Set\Set as DomainSet;
class FakeElementRepository implements ElementRepository
@ -33,6 +34,24 @@ class FakeElementRepository implements ElementRepository
return $element;
}
public function update(Element $element, UpdateElementDto $dto): Element
{
$updatedElement = new Element(
id: $element->getId(),
title: $dto->title,
description: $dto->description,
iconImageUrl: $dto->iconImageUrl,
richText: $dto->richText,
pdfPath: $dto->pdfPath,
youtubeUrl: $dto->youtubeUrl,
set: $element->getSet(),
parentElement: $element->getParentElement(),
);
$this->elementsById[$element->getId()] = $updatedElement;
return $this->cloneElement($updatedElement);
}
public function find(int $id): ?Element
{
if (! isset($this->elementsById[$id])) {

View file

@ -158,7 +158,8 @@ class ElementsEndpointTest extends TestCase
));
$this->createSession('valid-token');
$response = $this->withCookie('auth_token', 'valid-token')
$response = $this->withCredentials()
->withUnencryptedCookie('auth_token', 'valid-token')
->patchJson("/api/elements/{$element->getId()}", [
'title' => 'Updated title',
'description' => 'Updated description',

View file

@ -6,6 +6,7 @@ use App\Controllers\ElementController;
use App\Element\CreateElementDto;
use App\Element\Element;
use App\Element\UseCases\GetElement\GetElement;
use App\Element\UseCases\UpdateElement\UpdateElement;
use App\Set\Set as DomainSet;
use Tests\Fakes\FakeElementRepository;
use Tests\TestCase;
@ -20,7 +21,8 @@ class ElementControllerTest extends TestCase
{
$this->elementRepo = new FakeElementRepository();
$getElement = new GetElement($this->elementRepo);
$this->controller = new ElementController($getElement);
$updateElement = new UpdateElement($this->elementRepo);
$this->controller = new ElementController($getElement, $updateElement);
}
public function testShowReturnsElementPayload(): void