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; }