Fixes for client store request

This commit is contained in:
David Bomba 2022-01-14 21:24:20 +11:00
parent c28bf391fb
commit e844abf27d
3 changed files with 54 additions and 4 deletions

View File

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

View File

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

View File

@ -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()
{