split set update tests

This commit is contained in:
Yisroel Baum 2026-07-03 14:17:52 +03:00
parent 7428612316
commit 0bb17d1420
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
3 changed files with 136 additions and 80 deletions

View file

@ -0,0 +1,108 @@
<?php
namespace Tests\Unit\Set\UseCases;
use App\Exceptions\BadRequestException;
use App\Set\CreateSetDto;
use App\Set\Set as DomainSet;
use App\Set\UseCases\UpdateSet\UpdateIconImage;
use App\Set\UseCases\UpdateSet\UpdateIconImageRequest;
use Tests\Fakes\FakeFilesystem;
use Tests\Fakes\FakeSetRepository;
use Tests\TestCase;
class UpdateIconImageTest extends TestCase
{
private FakeSetRepository $setRepository;
private FakeFilesystem $filesystem;
protected function setUp(): void
{
$this->setRepository = new FakeSetRepository();
$this->filesystem = new FakeFilesystem();
}
public function testUpdatesOnlyIconAndDeletesOldIcon(): void
{
$set = $this->createSet();
$updateIconImage = new UpdateIconImage(
$this->setRepository,
$this->filesystem,
);
$updatedSet = $updateIconImage->execute(new UpdateIconImageRequest(
id: $set->getId(),
fileContents: 'image contents',
fileOriginalName: 'updated.png',
fileMimeType: 'image/png',
fileSizeBytes: 13,
));
$this->assertSame($set->getName(), $updatedSet->getName());
$this->assertSame(
$set->getDescription(),
$updatedSet->getDescription(),
);
$this->assertSame(
'set-icons/fake-updated.png',
$updatedSet->getIconImageUrl(),
);
$this->assertCount(1, $this->filesystem->uploads);
$this->assertSame('set-icons', $this->filesystem->uploads[0]['folder']);
$this->assertSame([
'set-icons/original.png',
], $this->filesystem->deletedPaths);
}
public function testRejectsMissingFile(): void
{
$set = $this->createSet();
$updateIconImage = new UpdateIconImage(
$this->setRepository,
$this->filesystem,
);
$this->expectException(BadRequestException::class);
$this->expectExceptionMessage('icon image is required');
$updateIconImage->execute(new UpdateIconImageRequest(
id: $set->getId(),
fileContents: null,
fileOriginalName: null,
fileMimeType: null,
fileSizeBytes: null,
));
}
public function testRejectsInvalidMimeType(): void
{
$set = $this->createSet();
$updateIconImage = new UpdateIconImage(
$this->setRepository,
$this->filesystem,
);
$this->expectException(BadRequestException::class);
$this->expectExceptionMessage(
'icon image must be a jpeg, png or webp image',
);
$updateIconImage->execute(new UpdateIconImageRequest(
id: $set->getId(),
fileContents: 'image contents',
fileOriginalName: 'updated.gif',
fileMimeType: 'image/gif',
fileSizeBytes: 13,
));
}
private function createSet(): DomainSet
{
return $this->setRepository->create(new CreateSetDto(
name: 'Original Set',
description: 'Original set description',
iconImageUrl: 'set-icons/original.png',
));
}
}