diff --git a/bootstrap/app.php b/bootstrap/app.php index 5d50a49..79c3c77 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -14,7 +14,9 @@ health: '/up', ) ->withMiddleware(function (Middleware $middleware) { + $middleware->redirectGuestsTo('/'); $middleware->web(CheckBannedMiddleware::class); + $middleware->trustProxies(at: ['127.0.0.1', '192.168.65.1/16']); }) ->withExceptions(function (Exceptions $exceptions) { // diff --git a/phpunit.xml b/phpunit.xml index e90c904..1349e68 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,27 +1,27 @@ - - - ./tests/Unit - - - ./tests/Feature - - - - - - - - - - - - - - - - ./app - - + + + ./tests/Unit + + + ./tests/Feature + + + + + + + + + + + + + + + + ./app + + diff --git a/routes/admin-api.php b/routes/admin-api.php index 5791da9..6f63e06 100644 --- a/routes/admin-api.php +++ b/routes/admin-api.php @@ -13,11 +13,11 @@ }); Route::group(['prefix' => 'users', 'middleware' => ['auth:web', 'can:is-admin']], function () { - Route::get('/', [AdminUsersController::class, 'index'])->name('admin-auth.users.index'); - Route::get('/list-filters', [AdminUsersController::class, 'listFilters'])->name('admin-auth.users.list-filters'); - Route::post('/create', [AdminUsersController::class, 'create'])->name('admin-auth.users.create'); - Route::post('/update', [AdminUsersController::class, 'update'])->name('admin-auth.users.update'); - Route::get('/get-user-form/{id}', [AdminUsersController::class, 'editUserFormData'])->name('admin-auth.users.edit-user-form'); - Route::get('/get-form-params', [AdminUsersController::class, 'getFormParams'])->name('admin-auth.users.get-form-params'); - Route::post('/delete/{id}', [AdminUsersController::class, 'delete'])->name('admin-auth.users.delete'); + Route::get('/', [AdminUsersController::class, 'index'])->name('admin.users.index'); + Route::get('/list-filters', [AdminUsersController::class, 'listFilters'])->name('admin.users.list-filters'); + Route::post('/create', [AdminUsersController::class, 'create'])->name('admin.users.create'); + Route::post('/update', [AdminUsersController::class, 'update'])->name('admin.users.update'); + Route::get('/get-user-form/{id}', [AdminUsersController::class, 'editUserFormData'])->name('admin.users.edit-user-form'); + Route::get('/get-form-params', [AdminUsersController::class, 'getFormParams'])->name('admin.users.get-form-params'); + Route::post('/delete/{id}', [AdminUsersController::class, 'delete'])->name('admin.users.delete'); }); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index bf8d700..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Feature/Users/AdminUsersTest.php b/tests/Feature/Users/AdminUsersTest.php new file mode 100644 index 0000000..6fee37d --- /dev/null +++ b/tests/Feature/Users/AdminUsersTest.php @@ -0,0 +1,50 @@ +get(route('admin.users.index')); + $response->assertRedirect('/'); + } + + public function testIndexPage(): void + { + $user = User::query()->find(1); + $this->actingAs($user, 'web'); + $response = $this->get(route('admin.users.index')); + + $response->assertStatus(200) + ->assertJsonStructure( + [ + 'data' => [ + '*' => [ + 'id', + 'name', + 'active', + 'email', + 'role', + 'createdAt', + 'updatedAt', + 'createdBy', + 'updatedBy', + ], + ], + 'current_page', + 'last_page', + 'total', + 'per_page', + ] + ); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 5341116..6358e31 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -9,4 +9,6 @@ abstract class TestCase extends BaseTestCase { use CreatesApplication; + + protected bool $seed = true; } diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index 38d50e1..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertTrue(true); - } -} diff --git a/tests/Unit/Users/Services/UsersServiceTest.php b/tests/Unit/Users/Services/UsersServiceTest.php new file mode 100644 index 0000000..ffe889e --- /dev/null +++ b/tests/Unit/Users/Services/UsersServiceTest.php @@ -0,0 +1,54 @@ +create($userDTO); + + $this->assertTrue($createdUser->active); + $this->assertEquals('UserName', $createdUser->name); + $this->assertEquals('user-email@example.com', $createdUser->email); + $this->assertEquals('admin', $createdUser->role); + $this->assertNotEmpty($createdUser->password); + + + $updateRequest = new AdminUpdateUserRequestDTO( + $createdUser->id, + false, + 'UpdateUserName', + 'updated-user-email@example.com', + 'user', + Hash::make('password2') + ); + + $updatedUser = $userService->update($updateRequest); + + $this->assertFalse($updatedUser->active); + $this->assertEquals('UpdateUserName', $updatedUser->name); + $this->assertEquals('updated-user-email@example.com', $updatedUser->email); + $this->assertEquals('user', $updatedUser->role); + $this->assertNotEmpty($updatedUser->password); + } +}