get('/login'); $response->assertStatus(200); } public function test_authenticated_user_is_redirected_from_login_page(): void { $user = User::factory()->create(['role' => Role::MANAGER]); $response = $this->actingAs($user)->get('/login'); $response->assertRedirect('/home'); } // ==================== Login ==================== public function test_user_can_login_with_correct_credentials(): void { $user = User::factory()->create([ 'role' => Role::MANAGER, 'password' => bcrypt('secret123'), ]); $response = $this->post('/login', [ 'email' => $user->email, 'password' => 'secret123', ]); $response->assertRedirect('/order'); $this->assertAuthenticatedAs($user); } public function test_login_fails_with_wrong_password(): void { $user = User::factory()->create([ 'password' => bcrypt('correct-password'), ]); $response = $this->post('/login', [ 'email' => $user->email, 'password' => 'wrong-password', ]); $response->assertSessionHasErrors(); $this->assertGuest(); } public function test_login_fails_with_nonexistent_email(): void { $response = $this->post('/login', [ 'email' => 'nonexistent@example.com', 'password' => 'password', ]); $response->assertSessionHasErrors(); $this->assertGuest(); } public function test_login_requires_email(): void { $response = $this->post('/login', [ 'password' => 'password', ]); $response->assertSessionHasErrors('email'); $this->assertGuest(); } public function test_login_requires_password(): void { $user = User::factory()->create(); $response = $this->post('/login', [ 'email' => $user->email, ]); $response->assertSessionHasErrors('password'); $this->assertGuest(); } // ==================== Logout ==================== public function test_authenticated_user_can_logout(): void { $user = User::factory()->create(['role' => Role::MANAGER]); $response = $this->actingAs($user)->post('/logout'); $response->assertRedirect('/'); $this->assertGuest(); } public function test_guest_cannot_access_protected_route(): void { $response = $this->get('/order'); $response->assertRedirect('/login'); } public function test_guest_redirected_to_login_from_any_auth_route(): void { $routes = ['/order', '/reclamations', '/schedule']; foreach ($routes as $route) { $response = $this->get($route); $response->assertRedirect('/login'); } } }