mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
More tests for Client REST api endpoints
This commit is contained in:
parent
74a01f8731
commit
1c3f0c590c
@ -19,7 +19,6 @@ use App\Models\Currency;
|
||||
use App\Models\Size;
|
||||
use App\Repositories\ClientRepository;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
@ -30,7 +29,6 @@ use Illuminate\Support\Facades\Cache;
|
||||
*/
|
||||
class ClientController extends Controller
|
||||
{
|
||||
use UserSessionAttributes;
|
||||
use MakesHash;
|
||||
|
||||
/**
|
||||
@ -74,7 +72,6 @@ class ClientController extends Controller
|
||||
])
|
||||
];
|
||||
|
||||
//return response()->json($data);
|
||||
return redirect()->route('clients.edit', ['id' => $this->encodePrimarykey($client->id)]);
|
||||
}
|
||||
|
||||
@ -121,7 +118,7 @@ class ClientController extends Controller
|
||||
*/
|
||||
public function create(CreateClientRequest $request)
|
||||
{
|
||||
$client = ClientFactory::create(auth()->user()->company(), auth()->user()->id);
|
||||
$client = ClientFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||
|
||||
$data = [
|
||||
'client' => $client,
|
||||
@ -141,7 +138,7 @@ class ClientController extends Controller
|
||||
public function store(StoreClientRequest $request)
|
||||
{
|
||||
|
||||
$client = StoreClient::dispatchNow($request, new Client);
|
||||
$client = StoreClient::dispatchNow($request, ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$client->load('contacts', 'primary_contact');
|
||||
|
||||
|
@ -15,7 +15,7 @@ class CreateClientRequest extends Request
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return $this->user()->can('create', Client::Class);
|
||||
return auth()->user()->can('create', Client::Class);
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ class EditClientRequest extends Request
|
||||
|
||||
public function authorize()
|
||||
{
|
||||
return $this->user()->can('edit', $this->client);
|
||||
return auth()->user()->can('edit', $this->client);
|
||||
}
|
||||
|
||||
public function sanitize()
|
||||
|
@ -15,7 +15,7 @@ class ShowClientRequest extends Request
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return $this->user()->can('view', $this->client);
|
||||
return auth()->user()->can('view', $this->client);
|
||||
}
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ class StoreClientRequest extends Request
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return $this->user()->can('create', Client::class);
|
||||
return auth()->user()->can('create', Client::class);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\ViewComposers;
|
||||
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
@ -11,7 +10,6 @@ use Illuminate\View\View;
|
||||
*/
|
||||
class HeaderComposer
|
||||
{
|
||||
use UserSessionAttributes;
|
||||
|
||||
/**
|
||||
* Bind data to the view.
|
||||
@ -40,7 +38,7 @@ class HeaderComposer
|
||||
});
|
||||
|
||||
$data['companies'] = $companies->reject(function ($company){
|
||||
return $company->id == auth()->user()->company->id;
|
||||
return $company->id == auth()->user()->company()->id;
|
||||
});
|
||||
|
||||
return $data;
|
||||
|
@ -114,10 +114,8 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
public function user_company()
|
||||
{
|
||||
$ct = CompanyToken::whereToken(request()->header('X-API-TOKEN'))->first();
|
||||
|
||||
return $ct->company;
|
||||
//return $this->user_companies->where('company_id', $this->getCurrentCompanyId())->first();
|
||||
return $this->user_companies->where('company_id', $this->getCurrentCompanyId())->first();
|
||||
|
||||
}
|
||||
|
||||
@ -169,7 +167,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function isAdmin() : bool
|
||||
{
|
||||
|
||||
return (bool) $this->company()->is_admin;
|
||||
return (bool) $this->user_company()->is_admin;
|
||||
|
||||
}
|
||||
|
||||
|
@ -103,6 +103,8 @@ class ClientTest extends TestCase
|
||||
|
||||
$user = User::find($company_user->user_id);
|
||||
|
||||
$this->assertTrue($user->isAdmin());
|
||||
|
||||
factory(\App\Models\Client::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||
|
||||
factory(\App\Models\ClientContact::class,1)->create([
|
||||
@ -157,6 +159,18 @@ class ClientTest extends TestCase
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-TOKEN' => $token,
|
||||
])->post('/api/v1/clients/', ['name' => 'New Client'])
|
||||
->assertJson([
|
||||
'name' => 'New Client'
|
||||
]);
|
||||
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user