diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index a27df9afb5d6..dbf51b660336 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -54,6 +54,7 @@ class StoreClientRequest extends Request /* Ensure we have a client name, and that all emails are unique*/ //$rules['name'] = 'required|min:1'; $rules['settings'] = new ValidClientGroupSettingsRule(); + $rules['contacts'] = 'array'; $rules['contacts.*.email'] = 'bail|nullable|distinct|sometimes|email'; $rules['contacts.*.password'] = [ 'nullable', diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 92253807588e..f39bf0f9f037 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -263,6 +263,63 @@ class ClientTest extends TestCase $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() { $account = Account::factory()->create();