|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Binaryk\LaravelRestify\Tests\Controllers; |
| 4 | + |
| 5 | +use Binaryk\LaravelRestify\Tests\Fixtures\User\User; |
| 6 | +use Binaryk\LaravelRestify\Tests\IntegrationTest; |
| 7 | +use Illuminate\Http\UploadedFile; |
| 8 | +use Illuminate\Support\Facades\Storage; |
| 9 | + |
| 10 | +class ProfileControllerTest extends IntegrationTest |
| 11 | +{ |
| 12 | + protected function setUp(): void |
| 13 | + { |
| 14 | + parent::setUp(); |
| 15 | + |
| 16 | + $this->authenticate(factory(User::class)->create([ |
| 17 | + 'name' => 'Eduard Lupacescu', |
| 18 | + |
| 19 | + ])); |
| 20 | + } |
| 21 | + |
| 22 | + public function test_profile_returns_authenticated_user() |
| 23 | + { |
| 24 | + $response = $this->getJson('/restify-api/profile') |
| 25 | + ->assertStatus(200) |
| 26 | + ->assertJsonStructure([ |
| 27 | + 'data' |
| 28 | + ]); |
| 29 | + |
| 30 | + $response->assertJsonFragment([ |
| 31 | + 'email' => $this->authenticatedAs->email, |
| 32 | + ]); |
| 33 | + } |
| 34 | + |
| 35 | + public function test_profile_update() |
| 36 | + { |
| 37 | + $response = $this->putJson('restify-api/profile', [ |
| 38 | + |
| 39 | + 'name' => 'Eduard', |
| 40 | + ]) |
| 41 | + ->assertStatus(200); |
| 42 | + |
| 43 | + $response->assertJsonFragment([ |
| 44 | + |
| 45 | + 'name' => 'Eduard', |
| 46 | + ]); |
| 47 | + } |
| 48 | + |
| 49 | + public function test_profile_update_unique_email() |
| 50 | + { |
| 51 | + factory(User::class)->create([ |
| 52 | + |
| 53 | + ]); |
| 54 | + |
| 55 | + $this->putJson('restify-api/profile', [ |
| 56 | + |
| 57 | + 'name' => 'Eduard', |
| 58 | + ])->assertStatus(400); |
| 59 | + } |
| 60 | + |
| 61 | + public function test_profile_upload_avatar() |
| 62 | + { |
| 63 | + $file = UploadedFile::fake()->image($this->getTestJpg())->size(100); |
| 64 | + |
| 65 | + $this->postJson('restify-api/profile/avatar', [ |
| 66 | + 'avatar' => $file |
| 67 | + ]) |
| 68 | + ->assertStatus(200); |
| 69 | + } |
| 70 | +} |
0 commit comments