add element updates
This commit is contained in:
parent
6d0acaae56
commit
73b0befc97
10 changed files with 223 additions and 13 deletions
|
|
@ -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])) {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue