mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 01:04:34 -04:00
Clean up for tests
This commit is contained in:
parent
25b26a2e5d
commit
7d86c8306a
@ -6,6 +6,7 @@ use App\Http\Requests\Account\CreateAccountRequest;
|
|||||||
use App\Jobs\Account\CreateAccount;
|
use App\Jobs\Account\CreateAccount;
|
||||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class AccountController extends Controller
|
class AccountController extends Controller
|
||||||
{
|
{
|
||||||
@ -48,8 +49,6 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
$user = CreateAccount::dispatchNow($request->all());
|
$user = CreateAccount::dispatchNow($request->all());
|
||||||
|
|
||||||
//todo redirect to localization setup workflow
|
|
||||||
//return redirect()->route('dashboard.index');
|
|
||||||
return response()->json($user);
|
return response()->json($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ class ClientController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function create(CreateClientRequest $request)
|
public function create(CreateClientRequest $request)
|
||||||
{
|
{
|
||||||
$client = ClientFactory::create(auth()->user()->getCompany()->id, auth()->user()->id);
|
$client = ClientFactory::create(auth()->user()->company()->id, auth()->user()->id);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
@ -138,7 +138,7 @@ class ClientController extends Controller
|
|||||||
public function store(StoreClientRequest $request)
|
public function store(StoreClientRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$client = StoreClient::dispatchNow($request, ClientFactory::create(auth()->user()->getCompany()->id, auth()->user()->id));
|
$client = StoreClient::dispatchNow($request, ClientFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||||
|
|
||||||
$client->load('contacts', 'primary_contact');
|
$client->load('contacts', 'primary_contact');
|
||||||
|
|
||||||
|
@ -25,11 +25,16 @@ class StoreClientRequest extends Request
|
|||||||
|
|
||||||
$contacts = request('contacts');
|
$contacts = request('contacts');
|
||||||
|
|
||||||
|
if(is_array($contacts))
|
||||||
|
{
|
||||||
|
|
||||||
for ($i = 0; $i < count($contacts); $i++) {
|
for ($i = 0; $i < count($contacts); $i++) {
|
||||||
$rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . isset($contacts[$i]['id']);
|
$rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . isset($contacts[$i]['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rules;
|
}
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,16 +29,16 @@ class HeaderComposer
|
|||||||
{
|
{
|
||||||
if(!auth()->user())
|
if(!auth()->user())
|
||||||
return [];
|
return [];
|
||||||
|
/
|
||||||
//companies
|
//companies
|
||||||
$companies = auth()->user()->companies;
|
$companies = auth()->user()->companies;
|
||||||
|
|
||||||
$data['current_company'] = $companies->first(function ($company){
|
$data['current_company'] = $companies->first(function ($company){
|
||||||
return $company->id == auth()->user()->getCompany()->id;
|
return $company->id == auth()->user()->company()->id;
|
||||||
});
|
});
|
||||||
|
|
||||||
$data['companies'] = $companies->reject(function ($company){
|
$data['companies'] = $companies->reject(function ($company){
|
||||||
return $company->id == auth()->user()->getCompany()->id;
|
return $company->id == auth()->user()->company()->id;
|
||||||
});
|
});
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -12,12 +12,12 @@ use App\Utils\Traits\UserSessionAttributes;
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class CreateAccount
|
class CreateAccount
|
||||||
{
|
{
|
||||||
|
|
||||||
use Dispatchable;
|
use Dispatchable;
|
||||||
use UserSessionAttributes;
|
|
||||||
|
|
||||||
protected $request;
|
protected $request;
|
||||||
|
|
||||||
@ -43,7 +43,6 @@ class CreateAccount
|
|||||||
* Create account
|
* Create account
|
||||||
*/
|
*/
|
||||||
$account = Account::create($this->request);
|
$account = Account::create($this->request);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create company
|
* Create company
|
||||||
*/
|
*/
|
||||||
@ -65,11 +64,6 @@ class CreateAccount
|
|||||||
*/
|
*/
|
||||||
$company_token = CreateCompanyToken::dispatchNow($company, $user);
|
$company_token = CreateCompanyToken::dispatchNow($company, $user);
|
||||||
|
|
||||||
/*
|
|
||||||
* Set current company
|
|
||||||
*/
|
|
||||||
$this->setCurrentCompanyId($user->companies()->first()->account->default_company_id);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Login user
|
* Login user
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,7 @@ use App\Filters\QueryFilters;
|
|||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
use Hashids\Hashids;
|
use Hashids\Hashids;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class BaseModel extends Model
|
class BaseModel extends Model
|
||||||
{
|
{
|
||||||
@ -30,7 +31,8 @@ class BaseModel extends Model
|
|||||||
|
|
||||||
public function scopeScope($query)
|
public function scopeScope($query)
|
||||||
{
|
{
|
||||||
$query->where($this->getTable() .'.company_id', '=', auth()->user()->getCompany()->id);
|
|
||||||
|
$query->where($this->getTable() .'.company_id', '=', auth()->user()->company()->id);
|
||||||
|
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -84,13 +84,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getCompany()
|
public function company()
|
||||||
{
|
{
|
||||||
//$ct = CompanyToken::whereToken(request()->header('X-API-TOKEN'))->first();
|
return $this->tokens()->whereRaw("BINARY `token`= ?", [request()->header('X-API-TOKEN')])->first()->company;
|
||||||
//Log::error($this->tokens()->whereRaw("BINARY `token`= ?", [request()->header('X-API-TOKEN')])->first()->company);
|
|
||||||
//return $this->tokens()->whereRaw("BINARY `token`= ?", [request()->header('X-API-TOKEN')])->first()->company;
|
|
||||||
Log::error('the request header = '.request()->header('X-API-TOKEN'));
|
|
||||||
return $this->tokens()->first()->company;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,11 +108,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function user_company()
|
public function user_company()
|
||||||
{
|
{
|
||||||
// Log::error('user_co 1'.$this->company()->id);
|
|
||||||
// Log::error('coco');
|
|
||||||
// Log::error('user_co '.$this->company());
|
|
||||||
Log::error('the company id = '.$this->companyId());
|
|
||||||
// return $this->user_companies->whereCompanyId($this->company()->id)->first();
|
|
||||||
return $this->user_companies->where('company_id', $this->companyId())->first();
|
return $this->user_companies->where('company_id', $this->companyId())->first();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -129,7 +121,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
public function companyId() :int
|
public function companyId() :int
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->getCompany()->id;
|
return $this->company()->id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ class ComposerServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot()
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
view()->composer('*', 'App\Http\ViewComposers\HeaderComposer');
|
view()->composer('*', 'App\Http\ViewComposers\HeaderComposer');
|
||||||
|
|
||||||
view()->composer(
|
view()->composer(
|
||||||
@ -21,6 +22,7 @@ class ComposerServiceProvider extends ServiceProvider
|
|||||||
],
|
],
|
||||||
'App\Http\ViewComposers\TranslationComposer'
|
'App\Http\ViewComposers\TranslationComposer'
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,6 +12,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\WithFaker;
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ class ClientTest extends TestCase
|
|||||||
|
|
||||||
$account = Account::find($acc['id']);
|
$account = Account::find($acc['id']);
|
||||||
|
|
||||||
$token = $account->default_company->tokens()->first()->token;
|
$token = $account->default_company->tokens->first()->token;
|
||||||
|
|
||||||
$response = $this->withHeaders([
|
$response = $this->withHeaders([
|
||||||
'X-API-SECRET' => config('ninja.api_secret'),
|
'X-API-SECRET' => config('ninja.api_secret'),
|
||||||
@ -108,9 +109,7 @@ class ClientTest extends TestCase
|
|||||||
$this->assertNotNull($token);
|
$this->assertNotNull($token);
|
||||||
$this->assertNotNull($user);
|
$this->assertNotNull($user);
|
||||||
$this->assertNotNull($company);
|
$this->assertNotNull($company);
|
||||||
$this->assertNotNull($user->tokens()->first()->company);
|
$this->assertNotNull($user->tokens->first()->company);
|
||||||
|
|
||||||
$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\Client::class, 20)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user