1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

FIxes for client validation

This commit is contained in:
David Bomba 2021-08-13 18:45:19 +10:00
parent 756039fcc3
commit 8484b3e024
2 changed files with 58 additions and 0 deletions

View File

@ -54,6 +54,7 @@ class StoreClientRequest extends Request
/* Ensure we have a client name, and that all emails are unique*/ /* Ensure we have a client name, and that all emails are unique*/
//$rules['name'] = 'required|min:1'; //$rules['name'] = 'required|min:1';
$rules['settings'] = new ValidClientGroupSettingsRule(); $rules['settings'] = new ValidClientGroupSettingsRule();
$rules['contacts'] = 'array';
$rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email'; $rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email';
$rules['contacts.*.password'] = [ $rules['contacts.*.password'] = [
'nullable', 'nullable',

View File

@ -263,6 +263,63 @@ class ClientTest extends TestCase
$this->assertEquals($this->client->contacts->count(), 3); $this->assertEquals($this->client->contacts->count(), 3);
} }
public function testClientCreationWithIllegalContactObject()
{
$account = Account::factory()->create();
$company = Company::factory()->create([
'account_id' => $account->id,
]);
$account->default_company_id = $company->id;
$account->save();
$user = User::factory()->create([
'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default')),
'email' => 'whiz@gmail.com',
]);
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'notifications' => CompanySettings::notificationDefaults(),
'permissions' => '',
'settings' => '',
'is_locked' => 0,
]);
$company_token = new CompanyToken;
$company_token->user_id = $user->id;
$company_token->company_id = $company->id;
$company_token->account_id = $account->id;
$company_token->name = $user->first_name.' '.$user->last_name;
$company_token->token = Str::random(64);
$company_token->save();
$this->token = $company_token->token;
$data = [
'name' => 'A loyal Client',
'contacts' => $this->faker->unique()->safeEmail,
];
try{
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
}catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
$this->assertNotNull($message);
}
}
public function testCreatingClientAndContacts() public function testCreatingClientAndContacts()
{ {
$account = Account::factory()->create(); $account = Account::factory()->create();