2FAuth/tests/Api/v1/Controllers/Auth/UserControllerTest.php
2022-12-13 12:07:29 +01:00

73 lines
1.6 KiB
PHP

<?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,
]);
}
}