2020-02-28 13:11:56 +01:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-02-28 13:11:56 +01:00
|
|
|
namespace Tests\Integration;
|
|
|
|
|
|
|
|
use App\Models\CompanyUser;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2020-02-29 22:03:43 +01:00
|
|
|
* @covers App\Http\Controllers\CompanyUserController
|
2020-02-28 13:11:56 +01:00
|
|
|
*/
|
|
|
|
class UpdateCompanyUserTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use MockAccountData;
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
|
|
|
public function setUp() :void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdatingCompanyUserAsAdmin()
|
|
|
|
{
|
|
|
|
User::unguard();
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->invoice = 'ninja';
|
|
|
|
|
|
|
|
$company_user = CompanyUser::whereUserId($this->user->id)->whereCompanyId($this->company->id)->first();
|
|
|
|
$company_user->settings = $settings;
|
|
|
|
|
|
|
|
$this->user->company_user = $company_user;
|
|
|
|
|
|
|
|
$user['company_user'] = $company_user->toArray();
|
|
|
|
|
|
|
|
$response = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->put('/api/v1/company_users/'.$this->encodePrimaryKey($this->user->id), $user);
|
2020-03-21 06:37:30 +01:00
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$message = json_decode($e->validator->getMessageBag(), 1);
|
2020-02-28 13:11:56 +01:00
|
|
|
$this->assertNotNull($message);
|
|
|
|
}
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$this->assertEquals('ninja', $arr['data']['settings']['invoice']);
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|