Fix gravatar url check

This commit is contained in:
Nabeel Shahzad 2020-03-24 18:54:04 -04:00
parent 62cea3eb0c
commit eafea01e22
3 changed files with 18 additions and 3 deletions

View File

@ -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,

View File

@ -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([

View File

@ -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);
}
}