-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Valentin Sickert <[email protected]>
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Http\Response; | ||
use Tests\TestCase; | ||
|
||
class AuthControllerTest extends TestCase | ||
{ | ||
use RefreshDatabase, WithFaker; | ||
|
||
/** | ||
* Test login with valid credentials. | ||
* | ||
* @return void | ||
*/ | ||
public function test_login_with_valid_credentials(): void | ||
{ | ||
|
||
$user = User::factory()->create([ | ||
'email' => '[email protected]', | ||
'password' => bcrypt('ValidPassword'), | ||
]); | ||
|
||
$response = $this->postJson('/api/v1/login', [ | ||
'email' => '[email protected]', | ||
'password' => 'ValidPassword', | ||
]); | ||
|
||
$response->assertStatus(Response::HTTP_OK) | ||
->assertJsonStructure([ | ||
'user' => [ | ||
'id', | ||
'name', | ||
'email', | ||
'email_verified_at', | ||
'created_at', | ||
'updated_at', | ||
], | ||
'access_token', | ||
]); | ||
|
||
$this->assertAuthenticatedAs($user); | ||
} | ||
|
||
/** | ||
* Test login with invalid credentials. | ||
* | ||
* @return void | ||
*/ | ||
public function test_login_with_invalid_credentials(): void | ||
{ | ||
$response = $this->postJson('/api/v1/login', [ | ||
'email' => '[email protected]', | ||
'password' => 'invalidpassword', | ||
]); | ||
|
||
$response->assertStatus(Response::HTTP_UNAUTHORIZED) | ||
->assertJson([ | ||
'message' => 'Invalid login credentials', | ||
]); | ||
|
||
$this->assertGuest(); | ||
} | ||
} |