From e6bc63b2c290e5f99801a7b77fb9aec34714cdba Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 27 Jun 2020 12:35:11 +1000 Subject: [PATCH 1/5] fixes for tests --- app/PaymentDrivers/Authorize/AuthorizeCreditCard.php | 2 +- tests/Feature/UserTest.php | 2 +- tests/MockAccountData.php | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 160790415bac..1eeb7b5cabaf 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -120,7 +120,7 @@ class AuthorizeCreditCard $payment->client_id = $this->authorize->client->id; $payment->company_gateway_id = $this->authorize->company_gateway->id; $payment->status_id = Payment::STATUS_COMPLETED; - $payment->gateway_type_id = $this->authorize->payment_method; + $payment->gateway_type_id = GatewayType::CREDIT_CARD; $payment->type_id = PaymentType::CREDIT_CARD_OTHER; $payment->currency_id = $this->authorize->client->getSetting('currency_id'); $payment->date = Carbon::now(); diff --git a/tests/Feature/UserTest.php b/tests/Feature/UserTest.php index 5c9057fb7a4a..aa86249793f0 100644 --- a/tests/Feature/UserTest.php +++ b/tests/Feature/UserTest.php @@ -96,7 +96,7 @@ class UserTest extends TestCase $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, - 'X-API-PASSWORD' => 'ALongAndBriliantPassword', + 'X-API-PASSWORD' => 'ALongAndBriliantPassword', ])->post('/api/v1/users/'.$this->encodePrimaryKey($user->id).'/attach_to_company?include=company_user'); $response->assertStatus(200); diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index b73505faf8a4..62b96fa5e553 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -120,11 +120,12 @@ trait MockAccountData if (!$this->user) { $this->user = factory(\App\Models\User::class)->create([ 'account_id' => $this->account->id, - 'password' => Hash::make('ALongAndBriliantPassword'), 'confirmation_code' => $this->createDbHash(config('database.default')) ]); } + $this->user->password = Hash::make('ALongAndBriliantPassword'); + $cu = CompanyUserFactory::create($this->user->id, $this->company->id, $this->account->id); $cu->is_owner = true; $cu->is_admin = true; From ae8a61cbcd4e307b8bb901be9aea0b259fe876aa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 27 Jun 2020 14:09:16 +1000 Subject: [PATCH 2/5] Fixes for tests --- app/Http/Requests/User/StoreUserRequest.php | 13 +++++++++++-- app/Models/User.php | 18 +++++++++++++++--- .../components/general/footer.blade.php | 2 +- tests/Feature/UserTest.php | 17 ++++++++++++----- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/app/Http/Requests/User/StoreUserRequest.php b/app/Http/Requests/User/StoreUserRequest.php index ce8b5c9d6dae..ead2e5b1a76e 100644 --- a/app/Http/Requests/User/StoreUserRequest.php +++ b/app/Http/Requests/User/StoreUserRequest.php @@ -28,7 +28,15 @@ class StoreUserRequest extends Request */ public function authorize() : bool - { + { + // info(print_r(auth()->user()->toArray(),1)); + // info(print_r(auth()->user()->company_user->toArray(),1)); + // + $queries = \DB::getQueryLog(); + $count = count($queries); + + info(request()->method() . ' - ' . request()->url() . ": $count queries - "); + return auth()->user()->isAdmin(); } @@ -43,8 +51,9 @@ class StoreUserRequest extends Request $rules['email'] = new ValidUserForCompany(); } - if(auth()->user()->company()->account->isFreeHostedClient()) + if(auth()->user()->company()->account->isFreeHostedClient()){ $rules['hosted_users'] = new CanAddUserRule(auth()->user()->company()->account); + } return $rules; } diff --git a/app/Models/User.php b/app/Models/User.php index 73c14a4adedf..55e8550e1310 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -196,9 +196,21 @@ class User extends Authenticatable implements MustVerifyEmail $this->id = auth()->user()->id; } - return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id') - ->where('company_user.user_id', $this->id) - ->withTrashed(); + return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id') + ->where('company_user.user_id', $this->id) + ->withTrashed(); + + // if(request()->header('X-API-TOKEN')){ + // return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id') + // ->where('company_tokens.token', request()->header('X-API-TOKEN')) + // ->withTrashed(); + // } + // else { + + // return $this->hasOneThrough(CompanyUser::class, CompanyToken::class, 'user_id', 'company_id', 'id', 'company_id') + // ->where('company_user.user_id', $this->id) + // ->withTrashed(); + // } } /** diff --git a/resources/views/portal/ninja2020/components/general/footer.blade.php b/resources/views/portal/ninja2020/components/general/footer.blade.php index 9b96d6e78a3e..f9933daa30fb 100644 --- a/resources/views/portal/ninja2020/components/general/footer.blade.php +++ b/resources/views/portal/ninja2020/components/general/footer.blade.php @@ -1,6 +1,6 @@