Skip to content

Commit 5e8a18d

Browse files
Login Test
1 parent 965a9ec commit 5e8a18d

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

tests/Feature/LoginTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Tests\Feature;
4+
5+
use App\Models\User;
6+
use Illuminate\Foundation\Testing\RefreshDatabase;
7+
use Illuminate\Foundation\Testing\WithFaker;
8+
use Illuminate\Support\Facades\Hash;
9+
use Laravel\Sanctum\Sanctum;
10+
use Tests\TestCase;
11+
12+
class LoginTest extends TestCase
13+
{
14+
use RefreshDatabase, WithFaker;
15+
16+
public function testUserLogin()
17+
{
18+
$password = 'password123';
19+
$user = User::factory()->create([
20+
'password' => Hash::make($password),
21+
]);
22+
23+
$response = $this->postJson('/api/user/login', [
24+
'email' => $user->email,
25+
'password' => $password,
26+
]);
27+
28+
$response->assertStatus(200);
29+
30+
// Assert that the response contains the user's data and a token
31+
$response->assertJsonStructure([
32+
'data' => [
33+
'user' => [
34+
'id',
35+
'name',
36+
'email',
37+
'token',
38+
],
39+
],
40+
]);
41+
42+
$responseData = $response->json();
43+
$this->assertNotNull($responseData['data']['user']['token']);
44+
}
45+
}
46+

tests/Feature/SignupControllerTest.php renamed to tests/Feature/SignupTest.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
use Illuminate\Support\Facades\Hash;
99
use Tests\TestCase;
1010

11-
class SignupControllerTest extends TestCase
11+
class SignupTest extends TestCase
1212
{
1313
use RefreshDatabase, WithFaker;
1414

15-
/**
16-
* Test user registration and email verification.
17-
*
18-
* @return void
19-
*/
15+
2016
public function testUserRegistration()
2117
{
2218
$userData = [

0 commit comments

Comments
 (0)