diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index 2e00faf..7caccfc 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -48,7 +48,7 @@ public function test_a_user_can_be_logged_in(): void * A user can not be logged in successfully with a invalid credentials * */ - public function test_a_user_can_not_be_logged_in(): void + public function test_a_user_can_not_be_logged_in_with_both_fields_wrong(): void { \Artisan::call('passport:install'); @@ -77,4 +77,81 @@ public function test_a_user_can_not_be_logged_in(): void $this->assertGuest(); } + /** + * A user can not be logged in successfully with missing fields + * + */ + public function test_a_user_cannot_be_logged_in_with_missing_fields(): void + { + $response = $this->postJson(route('login'), []); + + $response->assertStatus(422); + + } + + /** + * A user can not be logged in successfully with an incorrect password + */ + public function test_a_user_cannot_be_logged_in_with_wrong_password(): void + { + \Artisan::call('passport:install'); + + User::create([ + 'name' => 'Gabriela', + 'email' => 'gaby@gmail.com', + 'dni' => '39986946S', + 'password' => bcrypt('password'), + 'status' => 'ACTIVE', + 'role' => 'ADMIN', + ]); + + $response = $this->postJson(route('login'), [ + 'dni' => '39986946S', + 'password' => 'wrongPassword' + ]); + + $response->assertStatus(401); + $response->assertJson([ + 'result' => [ + 'message' => 'Invalid credentials' + ], + 'status' => false + ]); + + $this->assertGuest(); + } + + /** + * A user cannot be logged in successfully with an incorrect DNI + */ + public function test_a_user_cannot_be_logged_in_with_wrong_dni(): void + { + \Artisan::call('passport:install'); + + User::create([ + 'name' => 'Gabriela', + 'email' => 'gaby@gmail.com', + 'dni' => '39986946S', + 'password' => bcrypt('password'), + 'status' => 'ACTIVE', + 'role' => 'ADMIN', + ]); + + $response = $this->postJson(route('login'), [ + 'dni' => '39986987N', + 'password' => 'password' + ]); + + $response->assertStatus(401); + $response->assertJson([ + 'result' => [ + 'message' => 'Invalid credentials' + ], + 'status' => false + ]); + + $this->assertGuest(); + } + + }