From eafea01e2240d803483252134479a7475180b649 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Tue, 24 Mar 2020 18:54:04 -0400 Subject: [PATCH] Fix gravatar url check --- app/Http/Resources/User.php | 2 +- app/Models/User.php | 4 +++- tests/ApiTest.php | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/Http/Resources/User.php b/app/Http/Resources/User.php index 2df6fee8..49649bd1 100644 --- a/app/Http/Resources/User.php +++ b/app/Http/Resources/User.php @@ -15,7 +15,7 @@ class User extends Resource $res = [ 'id' => $this->id, 'pilot_id' => $this->pilot_id, - 'avatar' => $this->avatar, + 'avatar' => $this->avatar->url, 'ident' => $this->ident, 'name' => $this->name, 'email' => $this->email, diff --git a/app/Models/User.php b/app/Models/User.php index 364bae4e..671406fa 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -143,7 +143,9 @@ class User extends Authenticatable public function getAvatarAttribute() { if (!$this->attributes['avatar']) { - return $this->gravatar(); + return new File([ + 'path' => $this->gravatar(), + ]); } return new File([ diff --git a/tests/ApiTest.php b/tests/ApiTest.php index de57fdb6..16aa3253 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -266,9 +266,22 @@ class ApiTest extends TestCase public function testGetUser() { - $this->user = factory(App\Models\User::class)->create(); + $this->user = factory(App\Models\User::class)->create([ + 'avatar' => '/assets/avatar.jpg', + ]); + $res = $this->get('/api/user')->assertStatus(200); $user = $res->json('data'); $this->assertNotNull($user); + $this->assertTrue(strpos($user['avatar'], 'http') !== -1); + + // Should go to gravatar + + $this->user = factory(App\Models\User::class)->create(); + + $res = $this->get('/api/user')->assertStatus(200); + $user = $res->json('data'); + $this->assertNotNull($user); + $this->assertTrue(strpos($user['avatar'], 'gravatar') !== -1); } }