fix: ♻️ Remove generic failed output for US2.1

This commit is contained in:
Noah Lancien 2026-10-26 17:02:07 +01:00
parent a0160bfa8f
commit cca776dbeb
5 changed files with 16 additions and 34 deletions

View file

@ -5,8 +5,7 @@ declare(strict_types=1);
namespace Application\UseCases\Campaign\Create;
use Application\UseCases\Campaign\Create\Outputs\CampaignCreated;
use Application\UseCases\Campaign\Create\Outputs\CampaignCreationFailed;
use Application\UseCases\Campaign\Create\Outputs\CreateCampaignError;
use Application\UseCases\Campaign\Create\Outputs\CampaignNameAlreadyExists;
use Domain\Models\Entities\Campaign;
use Domain\Ports\Repositories\CampaignRepository;
use Shared\DDD\UseCases\Input as BaseInput;
@ -29,7 +28,7 @@ final readonly class CreateCampaign implements UseCase, Transactional
Assert::isInstanceOf($input, Input::class);
if ($this->repository->existsByName($input->name)) {
return new CampaignCreationFailed(CreateCampaignError::CampaignNameAlreadyExists);
return new CampaignNameAlreadyExists();
}
$campaign = Campaign::create(

View file

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Application\UseCases\Campaign\Create\Outputs;
use Shared\DDD\UseCases\Output as UseCaseOutput;
final readonly class CampaignCreationFailed implements UseCaseOutput
{
public function __construct(
public CreateCampaignError $error,
) {
}
}

View file

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Application\UseCases\Campaign\Create\Outputs;
use Shared\DDD\UseCases\Output as UseCaseOutput;
final readonly class CampaignNameAlreadyExists implements UseCaseOutput
{
}

View file

@ -1,11 +0,0 @@
<?php
declare(strict_types=1);
namespace Application\UseCases\Campaign\Create\Outputs;
enum CreateCampaignError: string
{
case CampaignNameAlreadyExists = 'campaign_name_already_exists';
case NotEnoughCoupons = 'not_enough_coupons_provided';
}

View file

@ -5,10 +5,9 @@ declare(strict_types=1);
namespace Tests\Unit\Application\UseCases\Campaign\Create;
use Application\UseCases\Campaign\Create\Outputs\CampaignCreated;
use Application\UseCases\Campaign\Create\Outputs\CampaignCreationFailed;
use Application\UseCases\Campaign\Create\CreateCampaign;
use Application\UseCases\Campaign\Create\Input;
use Application\UseCases\Campaign\Create\Outputs\CreateCampaignError;
use Application\UseCases\Campaign\Create\Outputs\CampaignNameAlreadyExists;
use Domain\Models\Entities\Campaign;
use Domain\Models\ValueObjects\Actor\ActorId;
use Domain\Models\ValueObjects\Brand\BrandCode;
@ -20,7 +19,7 @@ use Domain\Models\ValueObjects\Coupon\CouponCode;
use Domain\Ports\Repositories\CampaignRepository;
use Domain\Models\ValueObjects\PrintRules;
covers(CreateCampaign::class, Input::class, CampaignCreated::class, CampaignCreationFailed::class);
covers(CreateCampaign::class, Input::class, CampaignCreated::class, CampaignNameAlreadyExists::class);
describe('create campaign use case', function (): void {
$makeInput = fn (array $overrides = []): Input => new Input(...array_merge([
@ -72,7 +71,6 @@ describe('create campaign use case', function (): void {
$result = $useCase->execute($input);
// THEN
expect($result)->toBeInstanceOf(CampaignCreationFailed::class)
->and($result->error)->toBe(CreateCampaignError::CampaignNameAlreadyExists);
expect($result)->toBeInstanceOf(CampaignNameAlreadyExists::class);
});
});