mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Tests for types
This commit is contained in:
parent
e56aac5e73
commit
859efb9445
@ -75,6 +75,7 @@ trait CompanySettingsSaver
|
||||
|
||||
/*Catch all filter */
|
||||
if($this->checkAttribute($value, $settings->{$key})){
|
||||
\Log::error("System says true {$key} a {$value} = ".$settings->{$key});
|
||||
}
|
||||
else {
|
||||
unset($settings->{$key});
|
||||
@ -98,7 +99,7 @@ trait CompanySettingsSaver
|
||||
case 'real':
|
||||
case 'float':
|
||||
case 'double':
|
||||
return is_float($value);
|
||||
return is_float($value) || is_numeric(strval($value));
|
||||
case 'string':
|
||||
return method_exists($value, '__toString' ) || is_null($value) || is_string($value);
|
||||
case 'bool':
|
||||
|
@ -65,12 +65,14 @@ class CompanySettingsTest extends TestCase
|
||||
$this->assertEquals($arr['data']['settings']['timezone_id'],15);
|
||||
}
|
||||
|
||||
public function testSettingCasts()
|
||||
public function testIntegerEdgeCases()
|
||||
{
|
||||
$settings = $this->company->settings;
|
||||
|
||||
$settings->client_number_counter = "a";
|
||||
$settings->invoice_number_counter = 1000;
|
||||
$settings->quote_number_counter = 1.2;
|
||||
$settings->credit_number_counter = 10.1;
|
||||
|
||||
$this->company->settings = $settings;
|
||||
|
||||
@ -82,9 +84,38 @@ class CompanySettingsTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
\Log::error($arr);
|
||||
|
||||
$this->assertEquals($arr['data']['settings']['client_number_counter'],1);
|
||||
$this->assertEquals($arr['data']['settings']['quote_number_counter'],1);
|
||||
$this->assertEquals($arr['data']['settings']['credit_number_counter'],1);
|
||||
$this->assertEquals($arr['data']['settings']['invoice_number_counter'],1000);
|
||||
}
|
||||
|
||||
public function testFloatEdgeCases()
|
||||
{
|
||||
$settings = $this->company->settings;
|
||||
|
||||
$settings->default_task_rate = "a";
|
||||
$settings->tax_rate1 = 10.0;
|
||||
$settings->tax_rate2 = "10.0";
|
||||
$settings->tax_rate3 = "10.5";
|
||||
|
||||
$this->company->settings = $settings;
|
||||
|
||||
$response = $this->withHeaders([
|
||||
'X-API-SECRET' => config('ninja.api_secret'),
|
||||
'X-API-Token' => $this->token,
|
||||
])->put('/api/v1/companies/'.$this->encodePrimaryKey($this->company->id), $this->company->toArray());
|
||||
|
||||
$response->assertStatus(200);
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
$this->assertEquals($arr['data']['settings']['default_task_rate'],0);
|
||||
$this->assertEquals($arr['data']['settings']['tax_rate1'],10.0);
|
||||
$this->assertEquals($arr['data']['settings']['tax_rate2'],10.0);
|
||||
$this->assertEquals($arr['data']['settings']['tax_rate3'],10.5);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user