split set update tests
This commit is contained in:
parent
7428612316
commit
0bb17d1420
3 changed files with 136 additions and 80 deletions
108
backend/tests/Unit/Set/UseCases/UpdateIconImageTest.php
Normal file
108
backend/tests/Unit/Set/UseCases/UpdateIconImageTest.php
Normal 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',
|
||||
));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue