diff --git a/app/Http/Controllers/V1/User/ChangeUserRoleController.php b/app/Http/Controllers/V1/User/ChangeUserRoleController.php index bb136a2..c4f1d6c 100644 --- a/app/Http/Controllers/V1/User/ChangeUserRoleController.php +++ b/app/Http/Controllers/V1/User/ChangeUserRoleController.php @@ -4,13 +4,13 @@ use App\Http\Controllers\Controller; use App\Http\Requests\V1\User\ChangeUserRoleRequest; -use Core\Application\User\ChangeRole\Inputs\ChangeRoleInput; +use Core\Application\User\ChangeRole\Inputs\ChangeUserRoleInput; use Core\Application\User\Commons\Gateways\UserCommandInterface; use Core\Application\User\Commons\Gateways\UserRepositoryInterface; use Core\Presentation\Http\Errors\ErrorPresenter; use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\OutputErrorException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Infra\Handlers\UseCases\User\ChangeRole\ChangeRoleUserHandler; class ChangeUserRoleController extends Controller @@ -25,7 +25,7 @@ public function __construct( public function __invoke(ChangeUserRoleRequest $request, string $userUuid) { $userAutenticated = $this->frameworkService->auth()->user(); - $changeRoleInput = new ChangeRoleInput( + $changeRoleInput = new ChangeUserRoleInput( authenticatedUser: $userAutenticated, userUuid: $userUuid, role: $request->role @@ -52,7 +52,7 @@ public function __invoke(ChangeUserRoleRequest $request, string $userUuid) } return response()->json( - status: ResponseStatusCodeEnum::NO_CONTENT->value + status: ResponseStatus::NO_CONTENT->value ); } } diff --git a/app/Http/Controllers/V1/User/CreateUserController.php b/app/Http/Controllers/V1/User/CreateUserController.php index 061118d..45d6b45 100644 --- a/app/Http/Controllers/V1/User/CreateUserController.php +++ b/app/Http/Controllers/V1/User/CreateUserController.php @@ -15,7 +15,7 @@ use Core\Presentation\Http\User\UserPresenter; use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\OutputErrorException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Infra\Handlers\UseCases\User\Create\CreateUserHandler; class CreateUserController extends Controller @@ -70,7 +70,7 @@ public function __invoke(CreateUserRequest $request) return response()->json( data: (new UserPresenter($output->userEntity))->withDataAttribute()->toArray(), - status: ResponseStatusCodeEnum::CREATED->value + status: ResponseStatus::CREATED->value ); } } diff --git a/app/Http/Controllers/V1/User/ShowUserController.php b/app/Http/Controllers/V1/User/ShowUserController.php index 6db78b9..9c74278 100644 --- a/app/Http/Controllers/V1/User/ShowUserController.php +++ b/app/Http/Controllers/V1/User/ShowUserController.php @@ -9,7 +9,7 @@ use Core\Presentation\Http\User\UserDetaisPresenter; use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\OutputErrorException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Infra\Database\User\Repository\UserRepository; use Ramsey\Uuid\Uuid; @@ -45,7 +45,7 @@ public function __invoke(string $uuid) return response()->json( data: (new UserDetaisPresenter($userEntity))->withDataAttribute()->toArray(), - status: ResponseStatusCodeEnum::OK->value + status: ResponseStatus::OK->value ); } } diff --git a/app/Http/Controllers/V1/User/UpdateUserController.php b/app/Http/Controllers/V1/User/UpdateUserController.php index ab36dd9..6d9ae08 100644 --- a/app/Http/Controllers/V1/User/UpdateUserController.php +++ b/app/Http/Controllers/V1/User/UpdateUserController.php @@ -14,7 +14,7 @@ use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\InvalidEmailException; use Core\Support\Exceptions\OutputErrorException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Infra\Handlers\UseCases\User\Update\UpdateUserHandler; use Ramsey\Uuid\Uuid; @@ -35,9 +35,10 @@ public function __invoke(UpdateUserRequest $request, string $uuid) $input = new UpdateUserInput( uuid: Uuid::fromString($uuid), name: $request->name, - email: new EmailValueObject($request->email, false), + email: new EmailValueObject($request->email), password: $request->password, - birthday: Carbon::createFromFormat('Y-m-d', $request->birthday) + birthday: Carbon::createFromFormat('Y-m-d', $request->birthday), + authenticableUser: $this->frameworkService->auth()->user() ); try { @@ -69,7 +70,7 @@ public function __invoke(UpdateUserRequest $request, string $uuid) return response()->json( data: (new UserPresenter($output->userEntity))->withDataAttribute()->toArray(), - status: ResponseStatusCodeEnum::OK->value + status: ResponseStatus::OK->value ); } } diff --git a/core/Application/Account/Create/CreateAccountUseCase.php b/core/Application/Account/Create/CreateAccountUseCase.php index f9bb40d..91758f4 100644 --- a/core/Application/Account/Create/CreateAccountUseCase.php +++ b/core/Application/Account/Create/CreateAccountUseCase.php @@ -10,7 +10,7 @@ use Core\Domain\Entities\Account\AccountEntity; use Core\Domain\Entities\User\UserEntity; use Core\Services\Framework\FrameworkContract; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Validations\HasErrorBagTrait; class CreateAccountUseCase @@ -77,7 +77,7 @@ private function findAnAccountByAccessCode(AccountInput $accountInput): AccountE if (is_null($accountEntity)) { throw new AccountNotFoundException( message: 'Account join code not found', - code: ResponseStatusCodeEnum::NOT_FOUND->value + code: ResponseStatus::NOT_FOUND->value ); } diff --git a/core/Application/User/ChangeRole/ChangeRoleUseCase.php b/core/Application/User/ChangeRole/ChangeUserRoleUseCase.php similarity index 75% rename from core/Application/User/ChangeRole/ChangeRoleUseCase.php rename to core/Application/User/ChangeRole/ChangeUserRoleUseCase.php index 7ffbe86..62efc54 100644 --- a/core/Application/User/ChangeRole/ChangeRoleUseCase.php +++ b/core/Application/User/ChangeRole/ChangeUserRoleUseCase.php @@ -2,16 +2,16 @@ namespace Core\Application\User\ChangeRole; -use Core\Application\User\ChangeRole\Inputs\ChangeRoleInput; +use Core\Application\User\ChangeRole\Inputs\ChangeUserRoleInput; use Core\Application\User\Commons\Exceptions\UserNotFountException; use Core\Application\User\Commons\Gateways\UserCommandInterface; use Core\Application\User\Commons\Gateways\UserRepositoryInterface; use Core\Support\Exceptions\ForbidenException; use Core\Support\Exceptions\InvalidRoleException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; -readonly class ChangeRoleUseCase +readonly class ChangeUserRoleUseCase { public function __construct( private UserCommandInterface $userCommand, @@ -24,19 +24,14 @@ public function __construct( * @throws InvalidRoleException * @throws ForbidenException */ - public function execute(ChangeRoleInput $input): void + public function execute(ChangeUserRoleInput $input): void { - if ($input->authenticatedUser->hasNotPermission(UserRoles::ADMIN)) { - throw new ForbidenException( - message: 'You do not have permission to change the role', - code: ResponseStatusCodeEnum::FORBIDDEN->value - ); - } + $this->validateAccessPolicies($input); if (UserRoles::isValidRole($input->role)) { throw new InvalidRoleException( message: 'Invalid role', - code: ResponseStatusCodeEnum::BAD_REQUEST->value + code: ResponseStatus::BAD_REQUEST->value ); } @@ -44,7 +39,7 @@ public function execute(ChangeRoleInput $input): void if (!$userForChange) { throw new UserNotFountException( message: 'User not found', - code: ResponseStatusCodeEnum::NOT_FOUND->value + code: ResponseStatus::NOT_FOUND->value ); } $userForChange->checkUsersAreFromSameAccount($input->authenticatedUser); @@ -56,4 +51,16 @@ public function execute(ChangeRoleInput $input): void $userForChange->setPermissions($input->role); $this->userCommand->changeRole($userForChange); } + + /** + * @throws ForbidenException + */ + private function validateAccessPolicies(ChangeUserRoleInput $input): void + { + if ($input->authenticatedUser->hasNotPermission(UserRoles::ADMIN)) { + throw new ForbidenException( + message: 'You do not have permission to change the role' + ); + } + } } diff --git a/core/Application/User/ChangeRole/Inputs/ChangeRoleInput.php b/core/Application/User/ChangeRole/Inputs/ChangeUserRoleInput.php similarity index 88% rename from core/Application/User/ChangeRole/Inputs/ChangeRoleInput.php rename to core/Application/User/ChangeRole/Inputs/ChangeUserRoleInput.php index 346f3bc..40fffbf 100644 --- a/core/Application/User/ChangeRole/Inputs/ChangeRoleInput.php +++ b/core/Application/User/ChangeRole/Inputs/ChangeUserRoleInput.php @@ -4,7 +4,7 @@ use Core\Domain\Entities\User\UserEntity; -readonly class ChangeRoleInput +readonly class ChangeUserRoleInput { public function __construct( public UserEntity $authenticatedUser, diff --git a/core/Application/User/Create/CreateUserUseCase.php b/core/Application/User/Create/CreateUserUseCase.php index 6698f93..12b1414 100644 --- a/core/Application/User/Create/CreateUserUseCase.php +++ b/core/Application/User/Create/CreateUserUseCase.php @@ -26,7 +26,10 @@ public function __construct( */ public function execute(CreateUserInput $createUserInput): UserEntity { - $this->processEmail($createUserInput); + $emailAlreadyExists = $this->userRepository->existsEmail($createUserInput->email); + if ($emailAlreadyExists) { + $this->addError('email', 'Email já utilizado por outro usuário'); + } $userEntity = UserEntity::forCreate( name: $this->framework->Str()->title($createUserInput->name), @@ -36,7 +39,18 @@ public function execute(CreateUserInput $createUserInput): UserEntity uuid: $this->framework->uuid()->uuid7Generate(), birthday: $createUserInput->birthday ); + $this->processValidations($userEntity); + $this->checkValidationErrors(); + return $this->createUserInterface->create($userEntity); + } + + /** + * @param UserEntity $userEntity + * @return void + */ + private function processValidations(UserEntity $userEntity): void + { if ($userEntity->getEmail()->isInvalid()) { $this->addError('email', 'Invalid email'); } @@ -44,18 +58,6 @@ public function execute(CreateUserInput $createUserInput): UserEntity if ($isUnderAge) { $this->addError('birthday', 'Idade inválida'); } - - $this->checkValidationErrors(); - - return $this->createUserInterface->create($userEntity); - } - - private function processEmail(CreateUserInput $createUserInput): void - { - $emailAlreadyExists = $this->userRepository->existsEmail($createUserInput->email); - if ($emailAlreadyExists) { - $this->addError('email', 'Email já utilizado por outro usuário'); - } } } diff --git a/core/Application/User/Show/ShowUserUseCase.php b/core/Application/User/Show/ShowUserUseCase.php index 95e3aa0..25718f3 100644 --- a/core/Application/User/Show/ShowUserUseCase.php +++ b/core/Application/User/Show/ShowUserUseCase.php @@ -6,7 +6,7 @@ use Core\Application\User\Commons\Exceptions\UserNotFountException; use Core\Application\User\Commons\Gateways\UserRepositoryInterface; use Core\Domain\Entities\User\UserEntity; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; use Ramsey\Uuid\UuidInterface; @@ -23,20 +23,12 @@ public function __construct( */ public function execute(UuidInterface $uuid, UserEntity $userAuthenticaded): UserEntity { - if ( - !$userAuthenticaded->getUuid()->equals($uuid) && - $userAuthenticaded->hasNotPermission(UserRoles::ADMIN) - ) { - throw new UserNotFountException( - message: 'Forbidden access', - code: ResponseStatusCodeEnum::FORBIDDEN->value, - ); - } + $this->validateAccessPolicies($userAuthenticaded, $uuid); $userEntity = $this->userRepository->findByUuid($uuid); if (!$userEntity) { throw new UserNotFountException( message: 'User not found', - code: ResponseStatusCodeEnum::NOT_FOUND->value, + code: ResponseStatus::NOT_FOUND->value, ); } @@ -45,4 +37,20 @@ public function execute(UuidInterface $uuid, UserEntity $userAuthenticaded): Use return $userEntity; } + + /** + * @throws UserNotFountException + */ + private function validateAccessPolicies(UserEntity $userAuthenticaded, UuidInterface $uuid): void + { + if ( + !$userAuthenticaded->getUuid()->equals($uuid) && + $userAuthenticaded->hasNotPermission(UserRoles::ADMIN) + ) { + throw new UserNotFountException( + message: 'Forbidden access', + code: ResponseStatus::FORBIDDEN->value, + ); + } + } } diff --git a/core/Application/User/Update/Inputs/UpdateUserInput.php b/core/Application/User/Update/Inputs/UpdateUserInput.php index 23fd3ad..42a6a5f 100644 --- a/core/Application/User/Update/Inputs/UpdateUserInput.php +++ b/core/Application/User/Update/Inputs/UpdateUserInput.php @@ -2,6 +2,7 @@ namespace Core\Application\User\Update\Inputs; +use Core\Domain\Entities\User\UserEntity; use Core\Domain\ValueObjects\EmailValueObject; use DateTimeInterface; use Ramsey\Uuid\UuidInterface; @@ -15,7 +16,8 @@ public function __construct( public EmailValueObject $email, #[SensitiveParameter] public string $password, - public DateTimeInterface $birthday + public DateTimeInterface $birthday, + public UserEntity $authenticableUser ) { } } diff --git a/core/Application/User/Update/UpdateUserUseCase.php b/core/Application/User/Update/UpdateUserUseCase.php index 59e2e42..bc2ff5a 100644 --- a/core/Application/User/Update/UpdateUserUseCase.php +++ b/core/Application/User/Update/UpdateUserUseCase.php @@ -10,7 +10,7 @@ use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\ForbidenException; use Core\Support\Exceptions\OutputErrorException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; use Core\Support\Validations\HasErrorBagTrait; @@ -31,23 +31,13 @@ public function __construct( */ public function execute(UpdateUserInput $input): UserEntity { - if (!filter_var($input->email, FILTER_VALIDATE_EMAIL)) { - $this->addError('email', 'Invalid email.'); - } + $this->validateAccessPolicies($input); + $recordedUser = $this->userRepository->findByUuid(uuid: $input->uuid); if (!$recordedUser) { throw new UserNotFountException( message: 'Contém erros de validação', - code: ResponseStatusCodeEnum::NOT_FOUND->value - ); - } - if ( - !$this->framework->auth()->user()->getUuid()->equals($input->uuid) && - !$this->framework->auth()->user()->hasNotPermission(UserRoles::ADMIN) - ) { - throw new ForbidenException( - message: 'Você não tem permissão para alterar este usuário', - code: ResponseStatusCodeEnum::FORBIDDEN->value + code: ResponseStatus::NOT_FOUND->value ); } @@ -76,4 +66,16 @@ public function execute(UpdateUserInput $input): UserEntity $userEntity->setUuid($recordedUser->getUuid()); return $this->userCommand->update($userEntity); } + + private function validateAccessPolicies(UpdateUserInput $input): void + { + if ( + !$input->authenticableUser->getUuid()->equals($input->uuid) && + !$input->authenticableUser->hasNotPermission(UserRoles::ADMIN) + ) { + throw new ForbidenException( + message: 'Você não tem permissão para alterar este usuário' + ); + } + } } diff --git a/core/Domain/Entities/Account/AccountEntity.php b/core/Domain/Entities/Account/AccountEntity.php index ecddc9f..7729446 100644 --- a/core/Domain/Entities/Account/AccountEntity.php +++ b/core/Domain/Entities/Account/AccountEntity.php @@ -6,7 +6,7 @@ use Core\Domain\Entities\Account\Traits\Account\AccountEntityAcessors; use Core\Domain\Entities\Account\Traits\Account\AccountEntityBuilder; use Core\Domain\Entities\User\UserEntity; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; class AccountEntity { @@ -32,7 +32,7 @@ public function validateAccountName(): void if (is_null($this->name) || strlen($this->name) <= 0) { throw new AccountNameInvalidException( 'Account name is required', - ResponseStatusCodeEnum::BAD_REQUEST->value + ResponseStatus::BAD_REQUEST->value ); } } diff --git a/core/Domain/Entities/Account/AccountJoinCodeEntity.php b/core/Domain/Entities/Account/AccountJoinCodeEntity.php index a83064f..f983bf8 100644 --- a/core/Domain/Entities/Account/AccountJoinCodeEntity.php +++ b/core/Domain/Entities/Account/AccountJoinCodeEntity.php @@ -5,7 +5,7 @@ use Core\Application\Account\Commons\Exceptions\AccountJoinCodeInvalidException; use Core\Domain\Entities\Account\Traits\JoinCode\AccountJoinCodeAccessors; use Core\Domain\Entities\Account\Traits\JoinCode\AccountJoinCodeBuilder; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use DateTime; use DateTimeInterface; @@ -28,14 +28,14 @@ public function validateJoinCode(): void if ($this->expiresAt && $this->expiresAt < new DateTime()) { throw new AccountJoinCodeInvalidException( 'Join code has expired', - ResponseStatusCodeEnum::BAD_REQUEST->value + ResponseStatus::BAD_REQUEST->value ); } if (strlen($this->code) !== 6) { throw new AccountJoinCodeInvalidException( 'Join code must be 6 characters long', - ResponseStatusCodeEnum::BAD_REQUEST->value + ResponseStatus::BAD_REQUEST->value ); } } diff --git a/core/Domain/Entities/User/Traits/HasUserAccountValidator.php b/core/Domain/Entities/User/Traits/HasUserAccountValidator.php deleted file mode 100644 index 005a2ac..0000000 --- a/core/Domain/Entities/User/Traits/HasUserAccountValidator.php +++ /dev/null @@ -1,23 +0,0 @@ -getAccount()->getId() !== $userToCompare->getAccount()->getId()) { - throw new ForbidenException( - message: 'You do not have permission to change the role', - code: ResponseStatusCodeEnum::FORBIDDEN->value - ); - } - } -} diff --git a/core/Domain/Entities/User/Traits/HasUserRoleTrait.php b/core/Domain/Entities/User/Traits/HasUserRoleTrait.php index 38dd471..0b80bdd 100644 --- a/core/Domain/Entities/User/Traits/HasUserRoleTrait.php +++ b/core/Domain/Entities/User/Traits/HasUserRoleTrait.php @@ -3,7 +3,7 @@ namespace Core\Domain\Entities\User\Traits; use Core\Support\Exceptions\InvalidRoleException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; trait HasUserRoleTrait @@ -41,7 +41,7 @@ public function getRoleName(): string UserRoles::VIEWER => 'VIEWER', default => throw new InvalidRoleException( "Invalid role", - ResponseStatusCodeEnum::INTERNAL_SERVER_ERROR->value + ResponseStatus::INTERNAL_SERVER_ERROR->value ), }; } diff --git a/core/Domain/Entities/User/UserEntity.php b/core/Domain/Entities/User/UserEntity.php index c422242..6f713a4 100644 --- a/core/Domain/Entities/User/UserEntity.php +++ b/core/Domain/Entities/User/UserEntity.php @@ -3,11 +3,13 @@ namespace Core\Domain\Entities\User; use Core\Domain\Entities\Account\AccountEntity; -use Core\Domain\Entities\User\Traits\HasUserAccountValidator; use Core\Domain\Entities\User\Traits\HasUserEntityBuilder; use Core\Domain\Entities\User\Traits\HasUserRoleTrait; use Core\Domain\Entities\User\Traits\UserEntityAcessors; use Core\Domain\ValueObjects\EmailValueObject; +use Core\Support\Exceptions\ForbidenException; +use Core\Support\Exceptions\InvalidComparationException; +use Core\Support\Http\ResponseStatus; use DateTime; use DateTimeInterface; use Ramsey\Uuid\UuidInterface; @@ -17,7 +19,6 @@ class UserEntity use HasUserEntityBuilder; use UserEntityAcessors; use HasUserRoleTrait; - use HasUserAccountValidator; private ?int $id = null; private string $name; @@ -35,4 +36,24 @@ public function underAge(): bool { return $this->birthday->diff(new DateTime())->y < 18; } + + /** + * @throws ForbidenException + * @throws InvalidComparationException + */ + public function checkUsersAreFromSameAccount(UserEntity $userToCompare): void + { + if ($this->getAccount()->getId() !== $userToCompare->getAccount()->getId()) { + throw new ForbidenException( + message: 'You do not have permission to change the role' + ); + } + + if ($this->getId() === $userToCompare->getId()) { + throw new InvalidComparationException( + message: 'You can not compare the same user', + code: ResponseStatus::INTERNAL_SERVER_ERROR->value + ); + } + } } diff --git a/core/Domain/ValueObjects/EmailValueObject.php b/core/Domain/ValueObjects/EmailValueObject.php index 0a17145..e3a9fe2 100644 --- a/core/Domain/ValueObjects/EmailValueObject.php +++ b/core/Domain/ValueObjects/EmailValueObject.php @@ -3,7 +3,7 @@ namespace Core\Domain\ValueObjects; use Core\Support\Exceptions\InvalidEmailException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; class EmailValueObject { @@ -19,7 +19,7 @@ public function __construct(string $email, bool $autoValidete = true) if ($autoValidete && $this->isInvalid()) { throw new InvalidEmailException( 'Invalid email format', - ResponseStatusCodeEnum::BAD_REQUEST->value + ResponseStatus::BAD_REQUEST->value ); } } diff --git a/core/Support/Exceptions/ForbidenException.php b/core/Support/Exceptions/ForbidenException.php index aa32a57..b3ef719 100644 --- a/core/Support/Exceptions/ForbidenException.php +++ b/core/Support/Exceptions/ForbidenException.php @@ -2,7 +2,17 @@ namespace Core\Support\Exceptions; +use Core\Support\Http\ResponseStatus; +use Exception; + class ForbidenException extends OutputErrorException { - + public function __construct( + string $message, + int $code = ResponseStatus::FORBIDDEN->value, + Exception $previous = null, + ?array $errors = [] + ) { + parent::__construct($message, $code, $previous, $errors); + } } diff --git a/core/Support/Exceptions/InvalidComparationException.php b/core/Support/Exceptions/InvalidComparationException.php new file mode 100644 index 0000000..801b959 --- /dev/null +++ b/core/Support/Exceptions/InvalidComparationException.php @@ -0,0 +1,8 @@ + 1 + public const int WRITE = 1 << 1; // 0010 -> 2 + public const int DELETE = 1 << 2; // 0100 -> 4 + public const int EXECUTE = 1 << 3; // 1000 -> 8 } diff --git a/core/Support/Validations/HasErrorBagTrait.php b/core/Support/Validations/HasErrorBagTrait.php index 6d3fc76..023c655 100644 --- a/core/Support/Validations/HasErrorBagTrait.php +++ b/core/Support/Validations/HasErrorBagTrait.php @@ -3,7 +3,7 @@ namespace Core\Support\Validations; use Core\Support\Exceptions\HasErrorsInBagException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; trait HasErrorBagTrait { @@ -19,7 +19,7 @@ protected function addError(string $key, string $message): void */ protected function checkValidationErrors( string $message = 'Validation error', - ResponseStatusCodeEnum $errorCodeEnum = ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY + ResponseStatus $errorCodeEnum = ResponseStatus::UNPROCESSABLE_ENTITY ): void { if (!empty($this->errorBag)) { throw new HasErrorsInBagException( diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 6835f7d..2070fa4 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -39,6 +39,9 @@ RUN mkdir -p /home/$user/.composer && \ USER $user +RUN echo "alias pest='./vendor/bin/pest'" >> ~/.bashrc +RUN echo "alias test='php artisan test'" >> ~/.bashrc + CMD [ "php-fpm" ] # # Set the working directory # WORKDIR /var/www/html diff --git a/infra/Handlers/UseCases/User/ChangeRole/ChangeRoleUserHandler.php b/infra/Handlers/UseCases/User/ChangeRole/ChangeRoleUserHandler.php index 20196fa..d921bc8 100644 --- a/infra/Handlers/UseCases/User/ChangeRole/ChangeRoleUserHandler.php +++ b/infra/Handlers/UseCases/User/ChangeRole/ChangeRoleUserHandler.php @@ -2,12 +2,12 @@ namespace Infra\Handlers\UseCases\User\ChangeRole; -use Core\Application\User\ChangeRole\ChangeRoleUseCase; -use Core\Application\User\ChangeRole\Inputs\ChangeRoleInput; +use Core\Application\User\ChangeRole\ChangeUserRoleUseCase; +use Core\Application\User\ChangeRole\Inputs\ChangeUserRoleInput; use Core\Application\User\Commons\Gateways\UserCommandInterface; use Core\Application\User\Commons\Gateways\UserRepositoryInterface; -class ChangeRoleUserHandler +readonly class ChangeRoleUserHandler { public function __construct( private UserCommandInterface $userCommand, @@ -15,9 +15,9 @@ public function __construct( ) { } - public function handle(ChangeRoleInput $input): void + public function handle(ChangeUserRoleInput $input): void { - $changeRoleUseCase = new ChangeRoleUseCase( + $changeRoleUseCase = new ChangeUserRoleUseCase( userCommand: $this->userCommand, userRepository: $this->userRepository ); diff --git a/tests/Integration/UseCases/Account/CreateAccountUseCaseTest.php b/tests/Integration/UseCases/Account/CreateAccountUseCaseTest.php index 67f648d..3434946 100644 --- a/tests/Integration/UseCases/Account/CreateAccountUseCaseTest.php +++ b/tests/Integration/UseCases/Account/CreateAccountUseCaseTest.php @@ -12,7 +12,7 @@ use Core\Application\Account\Create\CreateAccountUseCase; use Core\Application\Account\Create\Inputs\AccountInput; use Core\Services\Framework\FrameworkContract; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\TestCase; @@ -88,7 +88,7 @@ public function test_must_create_associate_an_user_to_an_account_with_code_acces public function test_must_create_associate_an_user_to_an_account_with_code_access_not_existing() { $this->expectException(AccountNotFoundException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::NOT_FOUND->value); + $this->expectExceptionCode(ResponseStatus::NOT_FOUND->value); $userFactory = User::factory()->create(); // Arrange $input = new AccountInput( @@ -103,7 +103,7 @@ public function test_must_create_associate_an_user_to_an_account_with_code_acces public function test_must_create_associate_an_user_to_an_account_with_code_access_expired() { $this->expectException(AccountJoinCodeInvalidException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); $userFactory = User::factory()->create(); $accountFactory = Account::factory()->create(); $accountJoinCode = AccountJoinCode::factory()->create([ diff --git a/tests/Integration/UseCases/User/ChangeUserRoleUseCaseTest.php b/tests/Integration/UseCases/User/ChangeUserRoleUseCaseTest.php index 19af274..231aeda 100644 --- a/tests/Integration/UseCases/User/ChangeUserRoleUseCaseTest.php +++ b/tests/Integration/UseCases/User/ChangeUserRoleUseCaseTest.php @@ -3,8 +3,8 @@ namespace Tests\Integration\UseCases\User; use App\Models\User; -use Core\Application\User\ChangeRole\ChangeRoleUseCase; -use Core\Application\User\ChangeRole\Inputs\ChangeRoleInput; +use Core\Application\User\ChangeRole\ChangeUserRoleUseCase; +use Core\Application\User\ChangeRole\Inputs\ChangeUserRoleInput; use Core\Application\User\Commons\Exceptions\UserNotFountException; use Core\Application\User\Commons\Gateways\UserCommandInterface; use Core\Application\User\Commons\Gateways\UserRepositoryInterface; @@ -25,7 +25,7 @@ class ChangeUserRoleUseCaseTest extends TestCase use DatabaseMigrations; use WithFaker; - private ChangeRoleUseCase $useCase; + private ChangeUserRoleUseCase $useCase; public function test_success_case_for_change_role_from_any_user_when_authenticated_user_is_admin(): void { @@ -43,7 +43,7 @@ public function test_success_case_for_change_role_from_any_user_when_authenticat 'account_id' => $userAuth->account_id ] ); - $input = new ChangeRoleInput( + $input = new ChangeUserRoleInput( authenticatedUser: UserEntity::forIdentify( id: $userAuth->id, uuid: Uuid::fromString($userAuth->uuid), @@ -77,7 +77,7 @@ public function test_success_case_for_change_role_when_is_the_same_already_defin 'account_id' => $userAuth->account_id ] ); - $input = new ChangeRoleInput( + $input = new ChangeUserRoleInput( authenticatedUser: UserEntity::forIdentify( id: $userAuth->id, uuid: Uuid::fromString($userAuth->uuid), @@ -113,7 +113,7 @@ public function test_fail_case_for_change_role_from_any_user_when_authenticated_ 'account_id' => $userAuth->account_id ] ); - $input = new ChangeRoleInput( + $input = new ChangeUserRoleInput( authenticatedUser: UserEntity::forIdentify( id: $userAuth->id, uuid: Uuid::fromString($userAuth->uuid), @@ -144,7 +144,7 @@ public function test_fail_case_for_change_role_from_any_user_when_authenticated_ 'account_id' => $userAuth->account_id ] ); - $input = new ChangeRoleInput( + $input = new ChangeUserRoleInput( authenticatedUser: UserEntity::forIdentify( id: $userAuth->id, uuid: Uuid::fromString($userAuth->uuid), @@ -169,7 +169,7 @@ public function test_fail_when_user_not_found(): void ['*'] ); - $input = new ChangeRoleInput( + $input = new ChangeUserRoleInput( authenticatedUser: UserEntity::forIdentify( id: $userAuth->id, uuid: Uuid::fromString($userAuth->uuid), @@ -199,7 +199,7 @@ public function test_tail_if_users_arent_from_same_account(): void 'role' => UserRoles::VIEWER ] ); - $input = new ChangeRoleInput( + $input = new ChangeUserRoleInput( authenticatedUser: UserEntity::forIdentify( id: $userAuth->id, uuid: Uuid::fromString($userAuth->uuid), @@ -215,7 +215,7 @@ public function test_tail_if_users_arent_from_same_account(): void protected function setUp(): void { parent::setUp(); - $this->useCase = new ChangeRoleUseCase( + $this->useCase = new ChangeUserRoleUseCase( $this->app->make(UserCommandInterface::class), $this->app->make(UserRepositoryInterface::class) ); diff --git a/tests/Integration/UseCases/User/CreateUserUseCaseTest.php b/tests/Integration/UseCases/User/CreateUserUseCaseTest.php index 060a1ec..f3cfdb9 100644 --- a/tests/Integration/UseCases/User/CreateUserUseCaseTest.php +++ b/tests/Integration/UseCases/User/CreateUserUseCaseTest.php @@ -8,7 +8,7 @@ use Core\Application\User\Create\Inputs\CreateUserInput; use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\HasErrorsInBagException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\TestCase; @@ -48,7 +48,7 @@ public function test_must_create_a_user(): void public function test_must_not_create_a_user_with_invalid_email_and_birthday(): void { $this->expectException(HasErrorsInBagException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); + $this->expectExceptionCode(ResponseStatus::UNPROCESSABLE_ENTITY->value); // Arrange $input = new CreateUserInput( @@ -65,7 +65,7 @@ public function test_must_not_create_a_user_with_invalid_email_and_birthday(): v public function test_must_not_create_a_user_with_invalid_email(): void { $this->expectException(HasErrorsInBagException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); + $this->expectExceptionCode(ResponseStatus::UNPROCESSABLE_ENTITY->value); // Arrange $input = new CreateUserInput( @@ -82,7 +82,7 @@ public function test_must_not_create_a_user_with_invalid_email(): void public function test_must_not_create_a_user_with_invalid_age(): void { $this->expectException(HasErrorsInBagException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); + $this->expectExceptionCode(ResponseStatus::UNPROCESSABLE_ENTITY->value); // Arrange $input = new CreateUserInput( diff --git a/tests/Integration/UseCases/User/UpdateUserUseCaseTest.php b/tests/Integration/UseCases/User/UpdateUserUseCaseTest.php index 780a559..a51e45b 100644 --- a/tests/Integration/UseCases/User/UpdateUserUseCaseTest.php +++ b/tests/Integration/UseCases/User/UpdateUserUseCaseTest.php @@ -8,10 +8,11 @@ use Core\Application\User\Commons\Gateways\UserRepositoryInterface; use Core\Application\User\Update\Inputs\UpdateUserInput; use Core\Application\User\Update\UpdateUserUseCase; +use Core\Domain\Entities\User\UserEntity; use Core\Domain\ValueObjects\EmailValueObject; use Core\Services\Framework\FrameworkContract; use Core\Support\Exceptions\OutputErrorException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Illuminate\Foundation\Testing\DatabaseMigrations; use Laravel\Sanctum\Sanctum; use Ramsey\Uuid\Uuid; @@ -38,9 +39,13 @@ public function test_must_update_a_user(): void $input = new UpdateUserInput( uuid: Uuid::fromString($this->user->uuid), name: 'name 2', - email: new EmailValueObject('email3@email.com', false), + email: new EmailValueObject('email3@email.com'), password: 'password', - birthday: now()->subYears(18) + birthday: now()->subYears(18), + authenticableUser: UserEntity::forIdentify( + id: $this->user->id, + uuid: Uuid::fromString($this->user->uuid) + ) ); // Act @@ -60,7 +65,7 @@ public function test_must_update_a_user(): void public function test_must_not_update_a_user_with_invalid_email_and_birthday(): void { $this->expectException(OutputErrorException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); // Arrange $userFactory = User::factory()->create([ @@ -70,48 +75,34 @@ public function test_must_not_update_a_user_with_invalid_email_and_birthday(): v $input = new UpdateUserInput( uuid: Uuid::fromString($userFactory->uuid), name: 'name 2', - email: new EmailValueObject('email3', false), + email: new EmailValueObject('email3'), password: 'password', - birthday: now()->subYears(17) + birthday: now()->subYears(17), + authenticableUser: UserEntity::forIdentify( + id: $this->user->id, + uuid: Uuid::fromString($this->user->uuid) + ) ); $this->useCase->execute($input); } - public function test_must_not_update_a_user_with_invalid_email(): void - { - $this->expectException(OutputErrorException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); - - // Arrange - $userFactory = User::factory()->create([ - 'birthday' => now()->subYears(19) - ]); - - $input = new UpdateUserInput( - uuid: Uuid::fromString($userFactory->uuid), - name: 'name 2', - email: new EmailValueObject('email3', false), - password: 'password', - birthday: now()->subYears(18) - ); - - $this->useCase->execute($input); - } - - public function test_user_not_found_must_throw_an_exception(): void { $this->expectException(UserNotFountException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::NOT_FOUND->value); + $this->expectExceptionCode(ResponseStatus::NOT_FOUND->value); // Arrange $input = new UpdateUserInput( uuid: Uuid::uuid7(), name: 'name 2', - email: new EmailValueObject('email3@gmail.com', false), + email: new EmailValueObject('email3@gmail.com'), password: 'password', - birthday: now()->subYears(18) + birthday: now()->subYears(18), + authenticableUser: UserEntity::forIdentify( + id: $this->user->id, + uuid: Uuid::fromString($this->user->uuid) + ) ); $this->useCase->execute($input); @@ -120,7 +111,7 @@ public function test_user_not_found_must_throw_an_exception(): void public function test_must_not_update_a_user_with_invalid_birthday(): void { $this->expectException(OutputErrorException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); + $this->expectExceptionCode(ResponseStatus::UNPROCESSABLE_ENTITY->value); // Arrange $userFactory = User::factory()->create([ @@ -130,9 +121,13 @@ public function test_must_not_update_a_user_with_invalid_birthday(): void $input = new UpdateUserInput( uuid: Uuid::fromString($userFactory->uuid), name: 'name 2', - email: new EmailValueObject('email3@gmail.com', false), + email: new EmailValueObject('email3@gmail.com'), password: 'password', - birthday: now()->subYears(17) + birthday: now()->subYears(17), + authenticableUser: UserEntity::forIdentify( + id: $this->user->id, + uuid: Uuid::fromString($this->user->uuid) + ) ); $useCase = new UpdateUserUseCase( diff --git a/tests/Integration/e2e/User/ChangeUserRoleE2eTest.php b/tests/Integration/e2e/User/ChangeUserRoleE2eTest.php index f926ce4..bec91a4 100644 --- a/tests/Integration/e2e/User/ChangeUserRoleE2eTest.php +++ b/tests/Integration/e2e/User/ChangeUserRoleE2eTest.php @@ -4,7 +4,7 @@ use App\Models\User; use Core\Support\Http\HttpApiHeaders; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\WithFaker; @@ -42,7 +42,7 @@ public function test_success_case_for_change_role_from_any_user_when_authenticat ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::NO_CONTENT->value); + $response->assertStatus(ResponseStatus::NO_CONTENT->value); } public function test_success_case_for_change_role_when_is_the_same_already_defined(): void @@ -68,7 +68,7 @@ public function test_success_case_for_change_role_when_is_the_same_already_defin ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::NO_CONTENT->value); + $response->assertStatus(ResponseStatus::NO_CONTENT->value); } public function test_fail_case_for_change_role_from_any_user_when_authenticated_user_as_viewer_admin(): void @@ -93,7 +93,7 @@ public function test_fail_case_for_change_role_from_any_user_when_authenticated_ ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::FORBIDDEN->value); + $response->assertStatus(ResponseStatus::FORBIDDEN->value); } public function test_fail_case_for_change_role_from_any_user_when_authenticated_user_as_editor_admin(): void @@ -118,7 +118,7 @@ public function test_fail_case_for_change_role_from_any_user_when_authenticated_ ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::FORBIDDEN->value); + $response->assertStatus(ResponseStatus::FORBIDDEN->value); } public function test_fail_role_field_is_required(): void @@ -141,7 +141,7 @@ public function test_fail_role_field_is_required(): void [], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::UNPROCESSABLE_ENTITY->value); + $response->assertStatus(ResponseStatus::UNPROCESSABLE_ENTITY->value); $response->assertJsonStructure([ 'message', 'errors' => [ @@ -167,7 +167,7 @@ public function test_fail_when_user_not_found(): void ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::NOT_FOUND->value); + $response->assertStatus(ResponseStatus::NOT_FOUND->value); } public function test_tail_if_users_arent_from_same_account(): void @@ -192,6 +192,6 @@ public function test_tail_if_users_arent_from_same_account(): void ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::FORBIDDEN->value); + $response->assertStatus(ResponseStatus::FORBIDDEN->value); } } diff --git a/tests/Integration/e2e/User/CreateUserE2eTest.php b/tests/Integration/e2e/User/CreateUserE2eTest.php index 8957957..2d55d0f 100644 --- a/tests/Integration/e2e/User/CreateUserE2eTest.php +++ b/tests/Integration/e2e/User/CreateUserE2eTest.php @@ -5,7 +5,7 @@ use App\Models\AccountJoinCode; use App\Models\User; use Core\Support\Http\HttpApiHeaders; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\WithFaker; use Tests\TestCase; @@ -31,7 +31,7 @@ public function test_create_user_success_case() ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::CREATED->value); + $response->assertStatus(ResponseStatus::CREATED->value); $response->assertJsonStructure([ 'data' => [ 'uuid' @@ -59,7 +59,7 @@ public function test_create_user_join_into_an_account_success_case() HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::CREATED->value); + $response->assertStatus(ResponseStatus::CREATED->value); $response->assertJsonStructure([ 'data' => [ 'uuid', diff --git a/tests/Integration/e2e/User/ShowUserE2eTest.php b/tests/Integration/e2e/User/ShowUserE2eTest.php index e3d99bf..aa19b52 100644 --- a/tests/Integration/e2e/User/ShowUserE2eTest.php +++ b/tests/Integration/e2e/User/ShowUserE2eTest.php @@ -4,7 +4,7 @@ use App\Models\User; use Core\Support\Http\HttpApiHeaders; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\WithFaker; @@ -29,7 +29,7 @@ public function test_show_user_success_case_with_same_user_auth() HttpApiHeaders::$headersJson ); //assert response - $response->assertStatus(ResponseStatusCodeEnum::OK->value); + $response->assertStatus(ResponseStatus::OK->value); $response->assertJsonStructure([ 'data' => [ 'uuid' @@ -67,7 +67,7 @@ public function test_show_user_success_access_for_auth_user_as_an_admin() HttpApiHeaders::$headersJson ); //assert response - $response->assertStatus(ResponseStatusCodeEnum::OK->value); + $response->assertStatus(ResponseStatus::OK->value); $response->assertJsonStructure([ 'data' => [ 'uuid' diff --git a/tests/Integration/e2e/User/UpdateUserE2eTest.php b/tests/Integration/e2e/User/UpdateUserE2eTest.php index a90de94..d4b926b 100644 --- a/tests/Integration/e2e/User/UpdateUserE2eTest.php +++ b/tests/Integration/e2e/User/UpdateUserE2eTest.php @@ -4,7 +4,7 @@ use App\Models\User; use Core\Support\Http\HttpApiHeaders; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\UserRoles; use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\WithFaker; @@ -36,7 +36,7 @@ public function test_update_user_success_case() ); //assert response - $response->assertStatus(ResponseStatusCodeEnum::OK->value); + $response->assertStatus(ResponseStatus::OK->value); $response->assertJsonStructure([ 'data' => [ 'uuid' @@ -149,7 +149,7 @@ public function test_update_user_success_case_new_valid_email_when_user_change_t ], HttpApiHeaders::$headersJson ); - $response->assertStatus(ResponseStatusCodeEnum::OK->value); + $response->assertStatus(ResponseStatus::OK->value); $response->assertJsonStructure([ 'data' => [ 'uuid' @@ -171,7 +171,7 @@ public function test_update_user_fail_case_user_not_found() HttpApiHeaders::$headersJson ); //assert response - $response->assertStatus(ResponseStatusCodeEnum::NOT_FOUND->value); + $response->assertStatus(ResponseStatus::NOT_FOUND->value); } public function test_update_user_fail_case_user_is_not_the_same_user_authenticated() @@ -196,7 +196,7 @@ public function test_update_user_fail_case_user_is_not_the_same_user_authenticat HttpApiHeaders::$headersJson ); //assert response - $response->assertStatus(ResponseStatusCodeEnum::FORBIDDEN->value); + $response->assertStatus(ResponseStatus::FORBIDDEN->value); } protected function setUp(): void diff --git a/tests/Unit/Account/AccountEntityTest.php b/tests/Unit/Account/AccountEntityTest.php index c66f085..5e5dba3 100644 --- a/tests/Unit/Account/AccountEntityTest.php +++ b/tests/Unit/Account/AccountEntityTest.php @@ -4,7 +4,7 @@ use Core\Application\Account\Commons\Exceptions\AccountNameInvalidException; use Core\Domain\Entities\Account\AccountEntity; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Tests\TestCase; class AccountEntityTest extends TestCase @@ -25,7 +25,7 @@ public function test_create_account_for_create_name_is_invalid() { // Assert $this->expectException(AccountNameInvalidException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); // Arrange and Act AccountEntity::forCreate( diff --git a/tests/Unit/Account/AccountJoinCodeEntityTest.php b/tests/Unit/Account/AccountJoinCodeEntityTest.php index c55223c..d0cce7c 100644 --- a/tests/Unit/Account/AccountJoinCodeEntityTest.php +++ b/tests/Unit/Account/AccountJoinCodeEntityTest.php @@ -4,7 +4,7 @@ use Core\Application\Account\Commons\Exceptions\AccountJoinCodeInvalidException; use Core\Domain\Entities\Account\AccountJoinCodeEntity; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Tests\TestCase; class AccountJoinCodeEntityTest extends TestCase @@ -25,7 +25,7 @@ public function test_join_code_is_invalid_with_blank_code() { // Assert $this->expectException(AccountJoinCodeInvalidException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); // Arrange $entity = AccountJoinCodeEntity::forDetail(1, '', 1, now()->addDay()); @@ -38,7 +38,7 @@ public function test_join_code_is_invalid_with_code_having_less_than_max_chars() { // Assert $this->expectException(AccountJoinCodeInvalidException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); // Arrange $entity = AccountJoinCodeEntity::forDetail(1, '12345', 1, now()->addDay()); @@ -52,7 +52,7 @@ public function test_join_code_is_invalid_with_code_having_more_than_max_chars() { // Assert $this->expectException(AccountJoinCodeInvalidException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); // Arrange $entity = AccountJoinCodeEntity::forDetail(1, '1234567', 1, now()->addDay()); @@ -65,7 +65,7 @@ public function test_join_code_is_invalid_with_expired_date() { // Assert $this->expectException(AccountJoinCodeInvalidException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); // Arrange $entity = AccountJoinCodeEntity::forDetail(1, '123456', 1, now()->subDay()); diff --git a/tests/Unit/User/Entity/UserEntityRolesTest.php b/tests/Unit/User/Entity/UserEntityRolesTest.php index 0e5a72e..2ca562a 100644 --- a/tests/Unit/User/Entity/UserEntityRolesTest.php +++ b/tests/Unit/User/Entity/UserEntityRolesTest.php @@ -4,7 +4,7 @@ use Core\Domain\Entities\User\UserEntity; use Core\Support\Exceptions\InvalidRoleException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Core\Support\Permissions\Access\GeneralPermissions; use Core\Support\Permissions\UserRoles; use Ramsey\Uuid\Uuid; @@ -88,7 +88,7 @@ public function test_user_entity_roles_as_viewer() public function test_user_entity_roles_as_invalid() { $this->expectException(InvalidRoleException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::INTERNAL_SERVER_ERROR->value); + $this->expectExceptionCode(ResponseStatus::INTERNAL_SERVER_ERROR->value); $this->expectExceptionMessage('Invalid role'); $userEntity = UserEntity::forIdentify( diff --git a/tests/Unit/ValueObjects/EmailValueObjectTest.php b/tests/Unit/ValueObjects/EmailValueObjectTest.php index 654d823..bb93d07 100644 --- a/tests/Unit/ValueObjects/EmailValueObjectTest.php +++ b/tests/Unit/ValueObjects/EmailValueObjectTest.php @@ -4,7 +4,7 @@ use Core\Domain\ValueObjects\EmailValueObject; use Core\Support\Exceptions\InvalidEmailException; -use Core\Support\Http\ResponseStatusCodeEnum; +use Core\Support\Http\ResponseStatus; use Tests\TestCase; class EmailValueObjectTest extends TestCase @@ -18,7 +18,7 @@ public function test_valid_email() public function test_invalid_email() { $this->expectException(InvalidEmailException::class); - $this->expectExceptionCode(ResponseStatusCodeEnum::BAD_REQUEST->value); + $this->expectExceptionCode(ResponseStatus::BAD_REQUEST->value); new EmailValueObject('invalid-email'); }