Skip to content

Commit

Permalink
Merge pull request #55 from IT-Academy-BCN/feature/Login
Browse files Browse the repository at this point in the history
Feature/login
  • Loading branch information
CloudSalander authored May 25, 2023
2 parents 698d9a7 + 43948ca commit 8f08d50
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion tests/Feature/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
}


}

0 comments on commit 8f08d50

Please sign in to comment.