2020-03-03 22:28:03 +01:00
|
|
|
<?php
|
|
|
|
|
2020-03-09 20:24:25 +01:00
|
|
|
namespace Tests\Unit\Settings;
|
2020-03-03 22:28:03 +01:00
|
|
|
|
|
|
|
use App\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class AccountTest extends TestCase
|
|
|
|
{
|
|
|
|
/** @var \App\User */
|
|
|
|
protected $user;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->user = factory(User::class)->create();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test Get user infos via API
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function testGetUserDetails()
|
|
|
|
{
|
|
|
|
$user = User::find(1);
|
|
|
|
|
|
|
|
$response = $this->actingAs($user, 'api')
|
2020-03-09 20:24:25 +01:00
|
|
|
->json('GET', '/api/settings/account')
|
2020-03-03 22:28:03 +01:00
|
|
|
->assertStatus(200)
|
|
|
|
->assertJsonStructure(['name', 'email']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test User update with wrong current password via API
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function testUserUpdateWithWrongCurrentPassword()
|
|
|
|
{
|
|
|
|
$user = User::find(1);
|
|
|
|
|
|
|
|
$response = $this->actingAs($user, 'api')
|
2020-03-09 20:24:25 +01:00
|
|
|
->json('PATCH', '/api/settings/account', [
|
2020-03-03 22:28:03 +01:00
|
|
|
'name' => 'userUpdated',
|
|
|
|
'email' => 'userUpdated@example.org',
|
|
|
|
'password' => 'wrongPassword',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(400)
|
|
|
|
->assertJsonStructure(['message']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test User update via API
|
|
|
|
*
|
|
|
|
* @test
|
|
|
|
*/
|
|
|
|
public function testUserUpdate()
|
|
|
|
{
|
|
|
|
$user = User::find(1);
|
|
|
|
|
|
|
|
$response = $this->actingAs($user, 'api')
|
2020-03-09 20:24:25 +01:00
|
|
|
->json('PATCH', '/api/settings/account', [
|
2020-03-03 22:28:03 +01:00
|
|
|
'name' => 'userUpdated',
|
|
|
|
'email' => 'userUpdated@example.org',
|
|
|
|
'password' => 'password',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$response->assertStatus(200)
|
|
|
|
->assertJsonFragment([
|
|
|
|
'username' => 'userUpdated'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|