1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
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()
{
return $this->user()->can('edit', $this->client);
//return true;
// return ! auth()->user(); //todo permissions
}
public function sanitize()

View File

@ -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;

View File

@ -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;
});

View File

@ -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 */

View File

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

View File

@ -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);
}
}