From 1986714927e8fee84fec7523e3e91d1d554e79b6 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 27 Mar 2019 19:38:01 +1100 Subject: [PATCH] fixeS --- .../Requests/Client/EditClientRequest.php | 2 -- .../Requests/Client/UpdateClientRequest.php | 8 ++++-- app/Providers/RouteServiceProvider.php | 2 +- app/Repositories/ClientContactRepository.php | 2 +- tests/Feature/AccountTest.php | 3 ++ tests/Feature/ClientTest.php | 28 +++++++++++++++++-- 6 files changed, 36 insertions(+), 9 deletions(-) diff --git a/app/Http/Requests/Client/EditClientRequest.php b/app/Http/Requests/Client/EditClientRequest.php index 9795729f1594..f4c98a506f39 100644 --- a/app/Http/Requests/Client/EditClientRequest.php +++ b/app/Http/Requests/Client/EditClientRequest.php @@ -16,8 +16,6 @@ class EditClientRequest extends Request public function authorize() { return $this->user()->can('edit', $this->client); - //return true; - // return ! auth()->user(); //todo permissions } public function sanitize() diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index d972cd12dd9a..09ff311f8b58 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -27,10 +27,12 @@ class UpdateClientRequest extends Request $contacts = request('contacts'); - for ($i = 0; $i < count($contacts); $i++) { - $rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . $contacts[$i]['id']; + if(is_array($contacts)) + { + for ($i = 0; $i < count($contacts); $i++) { + $rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . $contacts[$i]['id']; + } } - return $rules; diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index acb0285d5fe1..cdf639d437e5 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -30,7 +30,7 @@ class RouteServiceProvider extends ServiceProvider Route::bind('client', function ($value) { $client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); - //$client->load('contacts', 'primary_contact'); + $client->with('contacts', 'primary_contact','country'); return $client; }); diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index 1c0e82a5b4ee..318c59bf6f09 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -11,7 +11,7 @@ use App\Models\ClientContact; class ClientContactRepository extends BaseRepository { - public function save(array $contacts, Client $client) : void + public function save($contacts, Client $client) : void { /* Convert array to collection */ diff --git a/tests/Feature/AccountTest.php b/tests/Feature/AccountTest.php index 28904acef1a5..2ee3aec4e681 100644 --- a/tests/Feature/AccountTest.php +++ b/tests/Feature/AccountTest.php @@ -32,6 +32,9 @@ class AccountTest extends TestCase Model::reguard(); } + /* + * @covers AccountController + */ public function testAccountCreation() { $data = [ diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 0383af77ec92..046f8b83d9f9 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -70,7 +70,10 @@ class ClientTest extends TestCase } - public function testClientShow() + /* + * @covers ClientController + */ + public function testClientRestEndPoints() { $data = [ @@ -118,6 +121,7 @@ class ClientTest extends TestCase }); $client = $account->default_company->clients()->first(); + $client->load('contacts'); $response = $this->withHeaders([ @@ -133,7 +137,27 @@ class ClientTest extends TestCase ])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id).'/edit'); $response->assertStatus(200); - } + + $client_update = [ + 'name' => 'A Funky Name' + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $token, + ])->put('/api/v1/clients/'.$this->encodePrimaryKey($client->id), $client_update) + ->assertJson([ + 'name' => 'A Funky Name' + ]); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $token, + ])->delete('/api/v1/clients/'.$this->encodePrimaryKey($client->id)); + + $response->assertStatus(200); + + } }