diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index b2b8b6774a01..b1525656173a 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -89,8 +89,6 @@ class StoreClientRequest extends Request protected function prepareForValidation() { $input = $this->all(); - - //@todo implement feature permissions for > 50 clients $settings = ClientSettings::defaults(); @@ -133,6 +131,10 @@ class StoreClientRequest extends Request $input['shipping_country_id'] = $this->getCountryCode($input['shipping_country_code']); } + /* If there is no number, just unset it here. */ + if(array_key_exists('number', $input) && ( is_null($input['number']) || empty($input['number']))) + unset($input['number']); + $this->replace($input); } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index c9494ca3b2b1..ecc16d9f6c8a 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -36,8 +36,6 @@ trait GeneratesCounter //todo in the form validation, we need to ensure that if a prefix and pattern is set we throw a validation error, //only one type is allow else this will cause confusion to the end user - - private function getNextEntityNumber($entity, Client $client, $is_recurring = false) { $prefix = ''; diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index a481c3775f79..0e67928252a4 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -68,6 +68,56 @@ class ClientApiTest extends TestCase } + public function testClientNoneValidation() + { + + $data = [ + 'name' => $this->faker->firstName, + 'number' => '', + ]; + + $response = false; + + 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); + nlog($message); + } + + $response->assertStatus(200); + + } + + + public function testClientNullValidation() + { + + $data = [ + 'name' => $this->faker->firstName, + 'number' => null, + ]; + + $response = false; + + 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); + nlog($message); + } + + $response->assertStatus(200); + + } + + public function testClientCountryCodeValidationTrueIso3() {