Change filtering of scalars prior to validation

This commit is contained in:
David Bomba 2025-01-15 08:52:17 +11:00
parent 4ff745de82
commit ba24bb78f6
2 changed files with 49 additions and 4 deletions

View File

@ -30,16 +30,16 @@ class BaseSettings
switch ($key) { switch ($key) {
case 'int': case 'int':
case 'integer': case 'integer':
return (int) $value; return is_scalar($value) ? (int) $value : 0;
case 'real': case 'real':
case 'float': case 'float':
case 'double': case 'double':
return (float) $value; return is_scalar($value) ? (float) $value : 0;
case 'string': case 'string':
return is_null($value) ? '' : (string) $value; return is_scalar($value) ? (string) $value : '';
case 'bool': case 'bool':
case 'boolean': case 'boolean':
return boolval($value); return is_scalar($value) ? boolval($value) : false;
case 'object': case 'object':
return json_decode($value); return json_decode($value);
case 'array': case 'array':

View File

@ -52,6 +52,51 @@ class InvoiceTest extends TestCase
$this->makeTestData(); $this->makeTestData();
} }
public function testLineItemValidation()
{
$line_items = [];
$item = new \stdClass();
$item->quantity = 1;
$item->cost = 100000000;
$item->type_id = '1';
$item->tax_name1 = ['tax_name1'];
$item->tax_rate1 = 10;
$item->tax_name2 = 'tax_name2';
$item->tax_rate2 = 10;
$item->tax_name3 = 'tax_name3';
$item->tax_rate3 = 10;
$line_items[] = $item;
$data = [
'status_id' => 1,
'number' => '',
'discount' => 0,
'is_amount_discount' => 1,
'po_number' => '3434343',
'public_notes' => 'notes',
'is_deleted' => 0,
'custom_value1' => 0,
'custom_value2' => 0,
'custom_value3' => 0,
'custom_value4' => 0,
'client_id' => $this->client->hashed_id,
'line_items' => $line_items,
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/invoices?mark_sent=true', $data)
->assertStatus(200);
$arr = $response->json();
}
public function testMaxDiscount() public function testMaxDiscount()
{ {