mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -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 Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class AccountController extends Controller
|
||||
{
|
||||
@ -48,8 +49,6 @@ class AccountController extends Controller
|
||||
|
||||
$user = CreateAccount::dispatchNow($request->all());
|
||||
|
||||
//todo redirect to localization setup workflow
|
||||
//return redirect()->route('dashboard.index');
|
||||
return response()->json($user);
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ class ClientController extends Controller
|
||||
*/
|
||||
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 = [
|
||||
'client' => $client,
|
||||
@ -138,7 +138,7 @@ class ClientController extends Controller
|
||||
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');
|
||||
|
||||
|
@ -25,11 +25,16 @@ class StoreClientRequest extends Request
|
||||
|
||||
$contacts = request('contacts');
|
||||
|
||||
if(is_array($contacts))
|
||||
{
|
||||
|
||||
for ($i = 0; $i < count($contacts); $i++) {
|
||||
$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())
|
||||
return [];
|
||||
|
||||
/
|
||||
//companies
|
||||
$companies = auth()->user()->companies;
|
||||
|
||||
$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){
|
||||
return $company->id == auth()->user()->getCompany()->id;
|
||||
return $company->id == auth()->user()->company()->id;
|
||||
});
|
||||
|
||||
return $data;
|
||||
|
@ -12,12 +12,12 @@ use App\Utils\Traits\UserSessionAttributes;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateAccount
|
||||
{
|
||||
|
||||
use Dispatchable;
|
||||
use UserSessionAttributes;
|
||||
|
||||
protected $request;
|
||||
|
||||
@ -43,7 +43,6 @@ class CreateAccount
|
||||
* Create account
|
||||
*/
|
||||
$account = Account::create($this->request);
|
||||
|
||||
/*
|
||||
* Create company
|
||||
*/
|
||||
@ -65,11 +64,6 @@ class CreateAccount
|
||||
*/
|
||||
$company_token = CreateCompanyToken::dispatchNow($company, $user);
|
||||
|
||||
/*
|
||||
* Set current company
|
||||
*/
|
||||
$this->setCurrentCompanyId($user->companies()->first()->account->default_company_id);
|
||||
|
||||
/*
|
||||
* Login user
|
||||
*/
|
||||
|
@ -6,6 +6,7 @@ use App\Filters\QueryFilters;
|
||||
use App\Utils\Traits\UserSessionAttributes;
|
||||
use Hashids\Hashids;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
@ -30,7 +31,8 @@ class BaseModel extends Model
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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();
|
||||
//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;
|
||||
return $this->tokens()->whereRaw("BINARY `token`= ?", [request()->header('X-API-TOKEN')])->first()->company;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,11 +108,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
@ -129,7 +121,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
||||
public function companyId() :int
|
||||
{
|
||||
|
||||
return $this->getCompany()->id;
|
||||
return $this->company()->id;
|
||||
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ class ComposerServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
/*
|
||||
view()->composer('*', 'App\Http\ViewComposers\HeaderComposer');
|
||||
|
||||
view()->composer(
|
||||
@ -21,6 +22,7 @@ class ComposerServiceProvider extends ServiceProvider
|
||||
],
|
||||
'App\Http\ViewComposers\TranslationComposer'
|
||||
);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -12,6 +12,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -59,7 +60,7 @@ class ClientTest extends TestCase
|
||||
|
||||
$account = Account::find($acc['id']);
|
||||
|
||||
$token = $account->default_company->tokens()->first()->token;
|
||||
$token = $account->default_company->tokens->first()->token;
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
@ -108,9 +109,7 @@ class ClientTest extends TestCase
|
||||
$this->assertNotNull($token);
|
||||
$this->assertNotNull($user);
|
||||
$this->assertNotNull($company);
|
||||
$this->assertNotNull($user->tokens()->first()->company);
|
||||
|
||||
$this->assertTrue($user->isAdmin());
|
||||
$this->assertNotNull($user->tokens->first()->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