123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Tests\Api\v1\Controllers\Auth;
- use App\Models\User;
- use Tests\FeatureTestCase;
- /**
- * @covers \App\Api\v1\Controllers\UserController
- * @covers \App\Api\v1\Resources\UserResource
- */
- class UserControllerTest extends FeatureTestCase
- {
- /**
- * @var \App\Models\User
- */
- protected $user;
- /**
- * @test
- */
- public function setUp(): void
- {
- parent::setUp();
- $this->user = User::factory()->create();
- }
- /**
- * @test
- */
- public function test_show_existing_user_when_authenticated_returns_success()
- {
- $response = $this->actingAs($this->user, 'api-guard')
- ->json('GET', '/api/v1/user')
- ->assertOk()
- ->assertExactJson([
- 'name' => $this->user->name,
- 'id' => $this->user->id,
- 'email' => $this->user->email,
- ]);
- }
- /**
- * @test
- */
- public function test_show_existing_user_when_anonymous_returns_success()
- {
- $response = $this->json('GET', '/api/v1/user/name')
- ->assertOk()
- ->assertExactJson([
- 'name' => $this->user->name,
- ]);
- }
- /**
- * @test
- */
- public function test_show_missing_user_returns_success_with_null_name()
- {
- User::destroy($this->user->id);
- $response = $this->actingAs($this->user, 'api-guard')
- ->json('GET', '/api/v1/user')
- ->assertOk()
- ->assertExactJson([
- 'name' => $this->user->name,
- 'id' => $this->user->id,
- 'email' => $this->user->email,
- ]);
- }
- }
|