2021-11-22 01:09:54 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Api\v1\Controllers\Auth;
|
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
use App\Models\User;
|
2021-11-22 01:09:54 +01:00
|
|
|
use Tests\FeatureTestCase;
|
|
|
|
|
|
|
|
class UserControllerTest extends FeatureTestCase
|
|
|
|
{
|
|
|
|
/**
|
2021-12-02 13:15:53 +01:00
|
|
|
* @var \App\Models\User
|
2022-11-22 15:15:52 +01:00
|
|
|
*/
|
2021-11-22 01:09:54 +01:00
|
|
|
protected $user;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
2022-11-22 15:15:52 +01:00
|
|
|
public function setUp() : void
|
2021-11-22 01:09:54 +01:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
2021-12-02 13:15:53 +01:00
|
|
|
$this->user = User::factory()->create();
|
2021-11-22 01:09:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_show_existing_user_when_authenticated_returns_success()
|
|
|
|
{
|
2022-03-31 08:38:35 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api-guard')
|
2021-11-22 01:09:54 +01:00
|
|
|
->json('GET', '/api/v1/user')
|
|
|
|
->assertOk()
|
|
|
|
->assertExactJson([
|
|
|
|
'name' => $this->user->name,
|
2022-03-31 08:38:35 +02:00
|
|
|
'id' => $this->user->id,
|
2021-11-22 01:09:54 +01:00
|
|
|
'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([
|
2022-11-22 15:15:52 +01:00
|
|
|
'name' => $this->user->name,
|
2021-11-22 01:09:54 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function test_show_missing_user_returns_success_with_null_name()
|
|
|
|
{
|
|
|
|
User::destroy($this->user->id);
|
|
|
|
|
2022-03-31 08:38:35 +02:00
|
|
|
$response = $this->actingAs($this->user, 'api-guard')
|
2021-11-22 01:09:54 +01:00
|
|
|
->json('GET', '/api/v1/user')
|
|
|
|
->assertOk()
|
|
|
|
->assertExactJson([
|
2022-03-31 08:38:35 +02:00
|
|
|
'name' => $this->user->name,
|
|
|
|
'id' => $this->user->id,
|
2021-11-22 01:09:54 +01:00
|
|
|
'email' => $this->user->email,
|
|
|
|
]);
|
|
|
|
}
|
2022-11-22 15:15:52 +01:00
|
|
|
}
|