test set update routing

This commit is contained in:
Yisroel Baum 2026-07-03 13:59:17 +03:00
parent f8666454c3
commit b2e39a98e4
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
2 changed files with 242 additions and 3 deletions

View file

@ -7,6 +7,9 @@ use App\Exceptions\BadRequestException;
use App\Exceptions\NotFoundException;
use App\Set\CreateSetDto;
use App\Set\Set as DomainSet;
use App\Set\UseCases\UpdateSet\UpdateDescription;
use App\Set\UseCases\UpdateSet\UpdateIconImage;
use App\Set\UseCases\UpdateSet\UpdateName;
use App\Set\UseCases\UpdateSet\UpdateSet;
use App\Set\UseCases\UpdateSet\UpdateSetRequest;
use Tests\Fakes\FakeElementRepository;
@ -30,8 +33,13 @@ class UpdateSetTest extends TestCase
$this->elementRepository = new FakeElementRepository();
$this->filesystem = new FakeFilesystem();
$this->updateSet = new UpdateSet(
new UpdateName($this->setRepository),
new UpdateDescription($this->setRepository),
new UpdateIconImage(
$this->setRepository,
$this->filesystem,
),
$this->setRepository,
$this->filesystem,
);
}
@ -89,6 +97,35 @@ class UpdateSetTest extends TestCase
);
}
public function testUpdatesOnlySuppliedFields(): void
{
$set = $this->setRepository->create(new CreateSetDto(
name: 'Original Set',
description: 'Original set description',
iconImageUrl: 'set-icons/original.png',
));
$updatedSet = $this->updateSet->execute(new UpdateSetRequest(
id: $set->getId(),
name: 'Updated Set',
description: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
));
$this->assertSame('Updated Set', $updatedSet->getName());
$this->assertSame(
'Original set description',
$updatedSet->getDescription(),
);
$this->assertSame(
'set-icons/original.png',
$updatedSet->getIconImageUrl(),
);
}
public function testReplacesSetIconAndDeletesOldManagedIcon(): void
{
$set = $this->setRepository->create(new CreateSetDto(
@ -118,6 +155,24 @@ class UpdateSetTest extends TestCase
], $this->filesystem->deletedPaths);
}
public function testRejectsNothingToUpdate(): void
{
$set = $this->createSet();
$this->expectException(BadRequestException::class);
$this->expectExceptionMessage('nothing to update');
$this->updateSet->execute(new UpdateSetRequest(
id: $set->getId(),
name: null,
description: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
iconImageSizeBytes: null,
));
}
public function testRequiresName(): void
{
$set = $this->createSet();
@ -128,7 +183,7 @@ class UpdateSetTest extends TestCase
$this->updateSet->execute(new UpdateSetRequest(
id: $set->getId(),
name: '',
description: 'Updated set description',
description: null,
iconImageContents: null,
iconImageOriginalName: null,
iconImageMimeType: null,
@ -145,7 +200,7 @@ class UpdateSetTest extends TestCase
$this->updateSet->execute(new UpdateSetRequest(
id: $set->getId(),
name: 'Updated Set',
name: null,
description: '',
iconImageContents: null,
iconImageOriginalName: null,