test element update dispatcher
This commit is contained in:
parent
240ab4e771
commit
581852ecbc
4 changed files with 314 additions and 1 deletions
|
|
@ -4,8 +4,14 @@ namespace Tests\Unit\Element\UseCases;
|
|||
|
||||
use App\Element\CreateElementDto;
|
||||
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\UpdateElementRequest;
|
||||
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\Exceptions\BadRequestException;
|
||||
use App\Exceptions\NotFoundException;
|
||||
use App\Set\Set as DomainSet;
|
||||
|
|
@ -21,7 +27,15 @@ class UpdateElementTest extends TestCase
|
|||
protected function setUp(): void
|
||||
{
|
||||
$this->elementRepo = new FakeElementRepository();
|
||||
$this->updateElement = new UpdateElement($this->elementRepo);
|
||||
$this->updateElement = new UpdateElement(
|
||||
new UpdateTitle($this->elementRepo),
|
||||
new UpdateDescription($this->elementRepo),
|
||||
new UpdateIconImageUrl($this->elementRepo),
|
||||
new UpdateRichText($this->elementRepo),
|
||||
new UpdatePdfPath($this->elementRepo),
|
||||
new UpdateYoutubeUrl($this->elementRepo),
|
||||
$this->elementRepo,
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdatesContentFields(): void
|
||||
|
|
@ -109,6 +123,55 @@ class UpdateElementTest extends TestCase
|
|||
$this->assertNull($updatedElement->getYoutubeUrl());
|
||||
}
|
||||
|
||||
public function testUpdatesOnlySuppliedFields(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Original title',
|
||||
'Original description',
|
||||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
||||
$updatedElement = $this->updateElement->execute(
|
||||
new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
title: 'Updated title',
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame('Updated title', $updatedElement->getTitle());
|
||||
$this->assertSame(
|
||||
'Original description',
|
||||
$updatedElement->getDescription(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/original-icon.png',
|
||||
$updatedElement->getIconImageUrl(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'<p>Original rich text</p>',
|
||||
$updatedElement->getRichText(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
$updatedElement->getYoutubeUrl(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testThrowsWhenIdMissing(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
|
|
@ -125,6 +188,22 @@ class UpdateElementTest extends TestCase
|
|||
));
|
||||
}
|
||||
|
||||
public function testThrowsWhenNothingProvided(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('nothing to update');
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: 1,
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
));
|
||||
}
|
||||
|
||||
public function testThrowsWhenTitleIsBlank(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue