split set update tests
This commit is contained in:
parent
7428612316
commit
0bb17d1420
3 changed files with 136 additions and 80 deletions
67
backend/tests/Unit/Set/UseCases/UpdateDescriptionTest.php
Normal file
67
backend/tests/Unit/Set/UseCases/UpdateDescriptionTest.php
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
<?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\UpdateDescription;
|
||||||
|
use App\Set\UseCases\UpdateSet\UpdateDescriptionRequest;
|
||||||
|
use Tests\Fakes\FakeSetRepository;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateDescriptionTest extends TestCase
|
||||||
|
{
|
||||||
|
private FakeSetRepository $setRepository;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->setRepository = new FakeSetRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdatesOnlyDescription(): void
|
||||||
|
{
|
||||||
|
$set = $this->createSet();
|
||||||
|
$updateDescription = new UpdateDescription($this->setRepository);
|
||||||
|
|
||||||
|
$updatedSet = $updateDescription->execute(
|
||||||
|
new UpdateDescriptionRequest(
|
||||||
|
id: $set->getId(),
|
||||||
|
description: 'Updated set description',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'Updated set description',
|
||||||
|
$updatedSet->getDescription(),
|
||||||
|
);
|
||||||
|
$this->assertSame($set->getName(), $updatedSet->getName());
|
||||||
|
$this->assertSame(
|
||||||
|
$set->getIconImageUrl(),
|
||||||
|
$updatedSet->getIconImageUrl(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRejectsBlankDescription(): void
|
||||||
|
{
|
||||||
|
$set = $this->createSet();
|
||||||
|
$updateDescription = new UpdateDescription($this->setRepository);
|
||||||
|
|
||||||
|
$this->expectException(BadRequestException::class);
|
||||||
|
$this->expectExceptionMessage('description is required');
|
||||||
|
|
||||||
|
$updateDescription->execute(new UpdateDescriptionRequest(
|
||||||
|
id: $set->getId(),
|
||||||
|
description: '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createSet(): DomainSet
|
||||||
|
{
|
||||||
|
return $this->setRepository->create(new CreateSetDto(
|
||||||
|
name: 'Original Set',
|
||||||
|
description: 'Original set description',
|
||||||
|
iconImageUrl: 'set-icons/original.png',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,17 +5,13 @@ namespace Tests\Unit\Set\UseCases;
|
||||||
use App\Exceptions\BadRequestException;
|
use App\Exceptions\BadRequestException;
|
||||||
use App\Set\CreateSetDto;
|
use App\Set\CreateSetDto;
|
||||||
use App\Set\Set as DomainSet;
|
use App\Set\Set as DomainSet;
|
||||||
use App\Set\UseCases\UpdateSet\UpdateDescription;
|
|
||||||
use App\Set\UseCases\UpdateSet\UpdateDescriptionRequest;
|
|
||||||
use App\Set\UseCases\UpdateSet\UpdateIconImage;
|
use App\Set\UseCases\UpdateSet\UpdateIconImage;
|
||||||
use App\Set\UseCases\UpdateSet\UpdateIconImageRequest;
|
use App\Set\UseCases\UpdateSet\UpdateIconImageRequest;
|
||||||
use App\Set\UseCases\UpdateSet\UpdateName;
|
|
||||||
use App\Set\UseCases\UpdateSet\UpdateNameRequest;
|
|
||||||
use Tests\Fakes\FakeFilesystem;
|
use Tests\Fakes\FakeFilesystem;
|
||||||
use Tests\Fakes\FakeSetRepository;
|
use Tests\Fakes\FakeSetRepository;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UpdateSetFieldsTest extends TestCase
|
class UpdateIconImageTest extends TestCase
|
||||||
{
|
{
|
||||||
private FakeSetRepository $setRepository;
|
private FakeSetRepository $setRepository;
|
||||||
|
|
||||||
|
|
@ -27,79 +23,7 @@ class UpdateSetFieldsTest extends TestCase
|
||||||
$this->filesystem = new FakeFilesystem();
|
$this->filesystem = new FakeFilesystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateNameUpdatesOnlyName(): void
|
public function testUpdatesOnlyIconAndDeletesOldIcon(): void
|
||||||
{
|
|
||||||
$set = $this->createSet();
|
|
||||||
$updateName = new UpdateName($this->setRepository);
|
|
||||||
|
|
||||||
$updatedSet = $updateName->execute(new UpdateNameRequest(
|
|
||||||
id: $set->getId(),
|
|
||||||
name: 'Updated Set',
|
|
||||||
));
|
|
||||||
|
|
||||||
$this->assertSame('Updated Set', $updatedSet->getName());
|
|
||||||
$this->assertSame(
|
|
||||||
$set->getDescription(),
|
|
||||||
$updatedSet->getDescription(),
|
|
||||||
);
|
|
||||||
$this->assertSame(
|
|
||||||
$set->getIconImageUrl(),
|
|
||||||
$updatedSet->getIconImageUrl(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateNameRejectsBlankName(): void
|
|
||||||
{
|
|
||||||
$set = $this->createSet();
|
|
||||||
$updateName = new UpdateName($this->setRepository);
|
|
||||||
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('name is required');
|
|
||||||
|
|
||||||
$updateName->execute(new UpdateNameRequest(
|
|
||||||
id: $set->getId(),
|
|
||||||
name: '',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateDescriptionUpdatesOnlyDescription(): void
|
|
||||||
{
|
|
||||||
$set = $this->createSet();
|
|
||||||
$updateDescription = new UpdateDescription($this->setRepository);
|
|
||||||
|
|
||||||
$updatedSet = $updateDescription->execute(
|
|
||||||
new UpdateDescriptionRequest(
|
|
||||||
id: $set->getId(),
|
|
||||||
description: 'Updated set description',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->assertSame(
|
|
||||||
'Updated set description',
|
|
||||||
$updatedSet->getDescription(),
|
|
||||||
);
|
|
||||||
$this->assertSame($set->getName(), $updatedSet->getName());
|
|
||||||
$this->assertSame(
|
|
||||||
$set->getIconImageUrl(),
|
|
||||||
$updatedSet->getIconImageUrl(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateDescriptionRejectsBlankDescription(): void
|
|
||||||
{
|
|
||||||
$set = $this->createSet();
|
|
||||||
$updateDescription = new UpdateDescription($this->setRepository);
|
|
||||||
|
|
||||||
$this->expectException(BadRequestException::class);
|
|
||||||
$this->expectExceptionMessage('description is required');
|
|
||||||
|
|
||||||
$updateDescription->execute(new UpdateDescriptionRequest(
|
|
||||||
id: $set->getId(),
|
|
||||||
description: '',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testUpdateIconImageUpdatesOnlyIconAndDeletesOldIcon(): void
|
|
||||||
{
|
{
|
||||||
$set = $this->createSet();
|
$set = $this->createSet();
|
||||||
$updateIconImage = new UpdateIconImage(
|
$updateIconImage = new UpdateIconImage(
|
||||||
|
|
@ -131,7 +55,7 @@ class UpdateSetFieldsTest extends TestCase
|
||||||
], $this->filesystem->deletedPaths);
|
], $this->filesystem->deletedPaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateIconImageRejectsMissingFile(): void
|
public function testRejectsMissingFile(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet();
|
$set = $this->createSet();
|
||||||
$updateIconImage = new UpdateIconImage(
|
$updateIconImage = new UpdateIconImage(
|
||||||
|
|
@ -151,7 +75,7 @@ class UpdateSetFieldsTest extends TestCase
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateIconImageRejectsInvalidMimeType(): void
|
public function testRejectsInvalidMimeType(): void
|
||||||
{
|
{
|
||||||
$set = $this->createSet();
|
$set = $this->createSet();
|
||||||
$updateIconImage = new UpdateIconImage(
|
$updateIconImage = new UpdateIconImage(
|
||||||
65
backend/tests/Unit/Set/UseCases/UpdateNameTest.php
Normal file
65
backend/tests/Unit/Set/UseCases/UpdateNameTest.php
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?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\UpdateName;
|
||||||
|
use App\Set\UseCases\UpdateSet\UpdateNameRequest;
|
||||||
|
use Tests\Fakes\FakeSetRepository;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class UpdateNameTest extends TestCase
|
||||||
|
{
|
||||||
|
private FakeSetRepository $setRepository;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->setRepository = new FakeSetRepository();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdatesOnlyName(): void
|
||||||
|
{
|
||||||
|
$set = $this->createSet();
|
||||||
|
$updateName = new UpdateName($this->setRepository);
|
||||||
|
|
||||||
|
$updatedSet = $updateName->execute(new UpdateNameRequest(
|
||||||
|
id: $set->getId(),
|
||||||
|
name: 'Updated Set',
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertSame('Updated Set', $updatedSet->getName());
|
||||||
|
$this->assertSame(
|
||||||
|
$set->getDescription(),
|
||||||
|
$updatedSet->getDescription(),
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
$set->getIconImageUrl(),
|
||||||
|
$updatedSet->getIconImageUrl(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRejectsBlankName(): void
|
||||||
|
{
|
||||||
|
$set = $this->createSet();
|
||||||
|
$updateName = new UpdateName($this->setRepository);
|
||||||
|
|
||||||
|
$this->expectException(BadRequestException::class);
|
||||||
|
$this->expectExceptionMessage('name is required');
|
||||||
|
|
||||||
|
$updateName->execute(new UpdateNameRequest(
|
||||||
|
id: $set->getId(),
|
||||||
|
name: '',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
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