This commit is contained in:
David Bomba 2019-03-27 19:38:01 +11:00
parent 08e4f9724f
commit 1986714927
6 changed files with 36 additions and 9 deletions

View File

@ -16,8 +16,6 @@ class EditClientRequest extends Request
public function authorize() public function authorize()
{ {
return $this->user()->can('edit', $this->client); return $this->user()->can('edit', $this->client);
//return true;
// return ! auth()->user(); //todo permissions
} }
public function sanitize() public function sanitize()

View File

@ -27,10 +27,12 @@ class UpdateClientRequest extends Request
$contacts = request('contacts'); $contacts = request('contacts');
for ($i = 0; $i < count($contacts); $i++) { if(is_array($contacts))
$rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . $contacts[$i]['id']; {
for ($i = 0; $i < count($contacts); $i++) {
$rules['contacts.' . $i . '.email'] = 'required|email|unique:client_contacts,email,' . $contacts[$i]['id'];
}
} }
return $rules; return $rules;

View File

@ -30,7 +30,7 @@ class RouteServiceProvider extends ServiceProvider
Route::bind('client', function ($value) { Route::bind('client', function ($value) {
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404); $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; return $client;
}); });

View File

@ -11,7 +11,7 @@ use App\Models\ClientContact;
class ClientContactRepository extends BaseRepository class ClientContactRepository extends BaseRepository
{ {
public function save(array $contacts, Client $client) : void public function save($contacts, Client $client) : void
{ {
/* Convert array to collection */ /* Convert array to collection */

View File

@ -32,6 +32,9 @@ class AccountTest extends TestCase
Model::reguard(); Model::reguard();
} }
/*
* @covers AccountController
*/
public function testAccountCreation() public function testAccountCreation()
{ {
$data = [ $data = [

View File

@ -70,7 +70,10 @@ class ClientTest extends TestCase
} }
public function testClientShow() /*
* @covers ClientController
*/
public function testClientRestEndPoints()
{ {
$data = [ $data = [
@ -118,6 +121,7 @@ class ClientTest extends TestCase
}); });
$client = $account->default_company->clients()->first(); $client = $account->default_company->clients()->first();
$client->load('contacts');
$response = $this->withHeaders([ $response = $this->withHeaders([
@ -133,7 +137,27 @@ class ClientTest extends TestCase
])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id).'/edit'); ])->get('/api/v1/clients/'.$this->encodePrimaryKey($client->id).'/edit');
$response->assertStatus(200); $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);
}
} }