create([ 'email' => 'test@example.com', 'password' => bcrypt('password'), ]); $response = $this->postJson('/api/auth/login', [ 'login' => 'test@example.com', 'password' => 'password', ]); $response->assertStatus(200) ->assertJsonStructure([ 'token', 'user' => [ 'id', 'name', 'email', 'role', ], ]); } public function test_user_can_login_with_account(): void { $user = User::factory()->create([ 'account' => 'testuser', 'password' => bcrypt('password'), ]); $response = $this->postJson('/api/auth/login', [ 'login' => 'testuser', 'password' => 'password', ]); $response->assertStatus(200) ->assertJsonStructure([ 'token', 'user' => [ 'id', 'name', 'email', 'role', ], ]); } public function test_user_cannot_login_with_incorrect_credentials(): void { $user = User::factory()->create(); $response = $this->postJson('/api/auth/login', [ 'login' => $user->email, 'password' => 'wrong-password', ]); $response->assertStatus(422); } }