From ae6f767c86ca7ae1c279b12949dbe195eb728d55 Mon Sep 17 00:00:00 2001 From: Toy Rik Date: Wed, 11 Feb 2026 13:57:37 +0300 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B0=D1=83?= =?UTF-8?q?=D1=82=D0=B5=D0=BD=D1=82=D0=B8=D1=84=D0=B8=D0=BA=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 4 ++ src/database/factories/RoleFactory.php | 4 +- src/database/factories/UserFactory.php | 2 + src/tests/Feature/AuthTest.php | 58 ++++++++++++++++++++++++++ src/tests/TestCase.php | 2 +- 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/tests/Feature/AuthTest.php diff --git a/Makefile b/Makefile index b5ce2f8..2bf5d29 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ up: docker-up down: docker-down reload: docker-down docker-up +restart: docker-restart init: docker-down-clear docker-pull docker-build docker-up app-init app-db-seed docker-up: @@ -12,6 +13,9 @@ docker-down: docker-down-clear: docker compose down -v --remove-orphans +docker-restart: + docker compose up -d --force-recreate + docker-pull: docker compose pull diff --git a/src/database/factories/RoleFactory.php b/src/database/factories/RoleFactory.php index b825646..e799704 100644 --- a/src/database/factories/RoleFactory.php +++ b/src/database/factories/RoleFactory.php @@ -17,7 +17,9 @@ class RoleFactory extends Factory public function definition(): array { return [ - // + 'name' => fake()->word(), + 'code' => fake()->unique()->word(), + 'description' => fake()->sentence(), ]; } } diff --git a/src/database/factories/UserFactory.php b/src/database/factories/UserFactory.php index 584104c..2d3445e 100644 --- a/src/database/factories/UserFactory.php +++ b/src/database/factories/UserFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Models\Role; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; @@ -29,6 +30,7 @@ class UserFactory extends Factory 'email_verified_at' => now(), 'password' => static::$password ??= Hash::make('password'), 'remember_token' => Str::random(10), + 'role_uuid' => Role::factory()->create()->uuid, ]; } diff --git a/src/tests/Feature/AuthTest.php b/src/tests/Feature/AuthTest.php new file mode 100644 index 0000000..4fae8fd --- /dev/null +++ b/src/tests/Feature/AuthTest.php @@ -0,0 +1,58 @@ +assertStatus(200); + $response->assertSee('Email:'); + $response->assertSee('Password:'); + $response->assertSee('Войти'); +}); + +it('can authenticate a user', function () { + $user = User::factory()->create([ + 'password' => bcrypt('password123'), + ]); + + $response = post('/login', [ + 'email' => $user->email, + 'password' => 'password123', + ]); + + $response->assertRedirect('/dashboard'); + expect(auth()->check())->toBeTrue(); +}); + +it('cannot authenticate a user with invalid credentials', function () { + $user = User::factory()->create([ + 'password' => bcrypt('password123'), + ]); + + $response = post('/login', [ + 'email' => $user->email, + 'password' => 'wrongpassword', + ]); + + $response->assertSessionHasErrors(); + expect(auth()->check())->toBeFalse(); +}); + +it('can logout a user', function () { + $user = User::factory()->create(); + + $response = $this->actingAs($user)->post('/logout'); + + $response->assertRedirect('/'); + expect(auth()->check())->toBeFalse(); +}); \ No newline at end of file diff --git a/src/tests/TestCase.php b/src/tests/TestCase.php index 6ac0072..1e0d980 100644 --- a/src/tests/TestCase.php +++ b/src/tests/TestCase.php @@ -8,5 +8,5 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { - // + use CreateApplication; }