File tree Expand file tree Collapse file tree 4 files changed +59
-1
lines changed
Expand file tree Collapse file tree 4 files changed +59
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Http \Controllers ;
4+
5+ use Illuminate \Http \Request ;
6+
7+ class UserController extends Controller
8+ {
9+ public function __construct () {
10+ $ this ->middleware ('auth:api ' );
11+ }
12+
13+ public function updateProfile () {
14+ $ attributes = request ()->validate (['name ' => 'nullable|string ' ]);
15+
16+ auth ()->user ()->update ($ attributes );
17+
18+ return $ this ->respondWithMessage ("User successfully updated " );
19+ }
20+ }
Original file line number Diff line number Diff line change 2727 Route::post ('register ' , 'RegistrationController@register ' );
2828 Route::get ('email/verify/{id} ' , 'VerificationController@verify ' )->name ('verification.verify ' );
2929 Route::get ('email/resend ' , 'VerificationController@resend ' )->name ('verification.resend ' );
30+
31+ Route::patch ('user/profile ' , 'UserController@updateProfile ' );
3032});
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tests \Feature ;
4+
5+ use App \User ;
6+ use Tests \TestCase ;
7+ use JWTAuth ;
8+
9+ class UsersTest extends TestCase
10+ {
11+ /** @test */
12+ public function a_user_can_edit_his_profile () {
13+ $ user = User::first ();
14+
15+ $ token = JWTAuth::fromUser ($ user );
16+
17+ $ attributes = ['name ' => $ this ->faker ->name ];
18+
19+ $ this ->patchJson ('api/user/profile ' , $ attributes , ['Authorization ' => "bearer $ token " ])
20+ ->assertStatus (200 );
21+
22+ $ this ->assertDatabaseHas ($ user ->getTable (), array_merge ($ attributes , [
23+ 'id ' => $ user ->id
24+ ]));
25+ }
26+ }
Original file line number Diff line number Diff line change 33namespace Tests ;
44
55use Illuminate \Foundation \Testing \TestCase as BaseTestCase ;
6+ use Illuminate \Foundation \Testing \WithFaker ;
67
78abstract class TestCase extends BaseTestCase
89{
9- use CreatesApplication;
10+ use CreatesApplication, WithFaker;
11+
12+ protected function setUp () : void {
13+ parent ::setUp ();
14+
15+ $ this ->artisan ('migrate ' );
16+ $ this ->artisan ('db:seed ' );
17+
18+ $ this ->withoutExceptionHandling ();
19+ }
1020}
You can’t perform that action at this time.
0 commit comments