Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rigonlucas committed Aug 22, 2024
1 parent 080b7b8 commit b783afb
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ APP_ENV=testing
APP_KEY=base64:dzLwRWVSB10asrK3As1sT/IsoV7MFQ5YGjxIVWfmlvs=
APP_DEBUG=true
APP_TIMEZONE=UTC
APP_URL=http://localhost
APP_URL=http://localhost:8080

APP_LOCALE=en
APP_FALLBACK_LOCALE=en
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/V1/User/ShowUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\V1\User;

use App\Http\Controllers\Controller;
use Core\Application\Account\Commons\Gateways\AccountRepositoryInterface;
use Core\Application\User\Show\ShowUserUseCase;
use Core\Presentation\Http\Errors\ErrorPresenter;
use Core\Presentation\Http\User\UserDetaisPresenter;
Expand All @@ -15,6 +16,7 @@ class ShowUserController extends Controller
{
public function __construct(
private readonly UserRepository $userRepository,
private readonly AccountRepositoryInterface $accountRepository,
private readonly FrameworkContract $frameworkService
) {
}
Expand All @@ -24,7 +26,8 @@ public function __invoke(string $uuid)
try {
$useCase = new ShowUserUseCase(
framework: $this->frameworkService,
userRepository: $this->userRepository
userRepository: $this->userRepository,
accountRepository: $this->accountRepository
);
$userEntity = $useCase->execute(uuid: $uuid);
} catch (OutputErrorException $outputErrorException) {
Expand Down
1 change: 1 addition & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @property mixed|string $email
* @property mixed|string $name
* @property mixed|string $uuid
* @property mixed|int $role
* @property mixed|int $id
* @property mixed accounts
* @property int|mixed|null $account_id
Expand Down
19 changes: 14 additions & 5 deletions infra/Database/User/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserRepository implements UserRepositoryInterface
public function findById(int $id): ?UserEntity
{
$userModel = User::query()
->select(['id', 'name', 'email', 'birthday', 'uuid'])
->select(['id', 'name', 'email', 'birthday', 'uuid', 'account_id', 'role'])
->find($id);
if (!$userModel) {
return null;
Expand All @@ -30,14 +30,18 @@ public function findById(int $id): ?UserEntity
email: $userModel->email,
uuid: FrameworkService::getInstance()->uuid()->uuidFromString($userModel->uuid),
account: AccountEntity::forIdentify($userModel->account_id),
birthday: new DateTime($userModel->birthday)
birthday: new DateTime($userModel->birthday),
role: $userModel->role
);
}

/**
* @throws InvalidEmailException
*/
public function findByUuid(string $uuid): ?UserEntity
{
$userModel = User::query()
->select(['id', 'name', 'email', 'birthday', 'uuid', 'account_id'])
->select(['id', 'name', 'email', 'birthday', 'uuid', 'account_id', 'role'])
->where('uuid', '=', $uuid)
->first();
if (!$userModel) {
Expand All @@ -51,13 +55,17 @@ public function findByUuid(string $uuid): ?UserEntity
uuid: FrameworkService::getInstance()->uuid()->uuidFromString($userModel->uuid),
account: AccountEntity::forIdentify($userModel->account_id),
birthday: new DateTime($userModel->birthday),
role: $userModel->role
);
}

/**
* @throws InvalidEmailException
*/
public function findByEmail(string $email): ?UserEntity
{
$userModel = User::query()
->select(['id', 'name', 'email', 'birthday', 'uuid'])
->select(['id', 'name', 'email', 'birthday', 'uuid', 'account_id', 'role'])
->where('email', '=', $email)
->first();
if (!$userModel) {
Expand All @@ -70,7 +78,8 @@ public function findByEmail(string $email): ?UserEntity
email: $userModel->email,
uuid: FrameworkService::getInstance()->uuid()->uuidFromString($userModel->uuid),
account: AccountEntity::forIdentify($userModel->account_id),
birthday: new DateTime($userModel->birthday)
birthday: new DateTime($userModel->birthday),
role: $userModel->role
);
}

Expand Down
4 changes: 2 additions & 2 deletions routes/Api/V1/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
});
Route::get('/show/{uuid}', [ShowUserController::class, '__invoke'])
->whereUuid('uuid')
->name('v1.user.show');
->name('api.v1.user.show');
Route::put('/user/update/{uuid}', [UpdateUserController::class, '__invoke'])
->whereUuid('uuid')
->name('v1.user.update');
->name('api.v1.user.update');
});
17 changes: 15 additions & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
<?php

use App\Http\Controllers\V1\User\CreateUserController;
use App\Http\Controllers\V1\User\ShowUserController;
use App\Http\Controllers\V1\User\UpdateUserController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('v1/register', [CreateUserController::class, '__invoke'])
->name('v1.user.create');
->name('api.v1.user.create');
Route::prefix('v1')
->middleware('auth:sanctum')
->group(function () {
require __DIR__ . '/Api/V1/user.php';
Route::prefix('user')->group(function () {
Route::get('/auth', function (Request $request) {
return $request;
});
Route::get('/show/{uuid}', [ShowUserController::class, '__invoke'])
->whereUuid('uuid')
->name('api.v1.user.show');
Route::put('/user/update/{uuid}', [UpdateUserController::class, '__invoke'])
->whereUuid('uuid')
->name('api.v1.user.update');
});
});


14 changes: 7 additions & 7 deletions tests/Integration/e2e/User/CreateUserE2eTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CreateUserE2eTest extends TestCase
public function test_create_user_success_case()
{
$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand All @@ -47,7 +47,7 @@ public function test_create_user_join_into_an_account_success_case()
]);

$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand All @@ -74,7 +74,7 @@ public function test_create_user_join_into_an_account_code_already_used()
]);

$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand All @@ -97,7 +97,7 @@ public function test_create_user_join_into_an_account_code_expired()
]);

$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand All @@ -114,7 +114,7 @@ public function test_create_user_join_into_an_account_code_expired()
public function test_create_user_join_into_an_account_code_not_found()
{
$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand All @@ -134,7 +134,7 @@ public function test_create_user_fail_case_email_exists_and_birthdate_less_than_
'email' => $this->faker->userName . '@gmail.com'
]);
$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $userMoodel->name,
'email' => $userMoodel->email,
Expand All @@ -157,7 +157,7 @@ public function test_create_user_fail_case_email_exists_and_birthdate_less_than_
public function test_create_user_fail_case_password_less_than_8_characters()
{
$response = $this->postJson(
route('v1.user.create'),
route('api.v1.user.create'),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/e2e/User/ShowUserE2eTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function test_update_user_success_case()
{
//update user
$response = $this->getJson(
route('v1.user.show', ['uuid' => $this->user->uuid]),
route('api.v1.user.show', ['uuid' => $this->user->uuid]),
HttpApiHeaders::$headersJson
);
//assert response
Expand Down
12 changes: 6 additions & 6 deletions tests/Integration/e2e/User/UpdateUserE2eTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function test_update_user_success_case()
{
//update user
$response = $this->putJson(
route('v1.user.update', ['uuid' => $this->user->uuid]),
route('api.v1.user.update', ['uuid' => $this->user->uuid]),
[
'name' => $this->faker->name . 'updated',
'email' => $this->faker->userName . '[email protected]',
Expand Down Expand Up @@ -52,7 +52,7 @@ public function test_update_user_fail_case_email_exists_and_birthdate_less_than_

//update user
$response = $this->putJson(
route('v1.user.update', ['uuid' => $this->user->uuid]),
route('api.v1.user.update', ['uuid' => $this->user->uuid]),
[
'name' => $userMoodel->name,
'email' => $userMoodel->email,
Expand All @@ -76,7 +76,7 @@ public function test_update_user_fail_case_password_less_than_8_characters()
{
//update user
$response = $this->putJson(
route('v1.user.update', ['uuid' => $this->user->uuid]),
route('api.v1.user.update', ['uuid' => $this->user->uuid]),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand Down Expand Up @@ -105,7 +105,7 @@ public function test_update_user_fail_case_email_exists()

//update user
$response = $this->putJson(
route('v1.user.update', ['uuid' => $this->user->uuid]),
route('api.v1.user.update', ['uuid' => $this->user->uuid]),
[
'name' => $otherUser->name,
'email' => $otherUser->email,
Expand Down Expand Up @@ -139,7 +139,7 @@ public function test_update_user_success_case_new_valid_email()

//update user
$response = $this->putJson(
route('v1.user.update', ['uuid' => $this->user->uuid]),
route('api.v1.user.update', ['uuid' => $this->user->uuid]),
[
'name' => $otherUser->name,
'email' => $this->faker->userName . '@gmail.com',
Expand All @@ -161,7 +161,7 @@ public function test_update_user_fail_case_user_not_found()
{
//update user
$response = $this->putJson(
route('v1.user.update', ['uuid' => $this->faker->uuid]),
route('api.v1.user.update', ['uuid' => $this->faker->uuid]),
[
'name' => $this->faker->name,
'email' => $this->faker->userName . '@gmail.com',
Expand Down

0 comments on commit b783afb

Please sign in to comment.