File tree 2 files changed +48
-6
lines changed
2 files changed +48
-6
lines changed Original file line number Diff line number Diff line change
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
+
Original file line number Diff line number Diff line change 8
8
use Illuminate \Support \Facades \Hash ;
9
9
use Tests \TestCase ;
10
10
11
- class SignupControllerTest extends TestCase
11
+ class SignupTest extends TestCase
12
12
{
13
13
use RefreshDatabase, WithFaker;
14
14
15
- /**
16
- * Test user registration and email verification.
17
- *
18
- * @return void
19
- */
15
+
20
16
public function testUserRegistration ()
21
17
{
22
18
$ userData = [
You can’t perform that action at this time.
0 commit comments