mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 08:04:33 -04:00
Fixes for client tests
This commit is contained in:
parent
cf1b790786
commit
0d5ee8269d
@ -37,6 +37,15 @@ class ClientSettings extends BaseSettings
|
|||||||
'size_id' => 'string',
|
'size_id' => 'string',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static $property_casts = [
|
||||||
|
'language_id' => 'string',
|
||||||
|
'currency_id' => 'string',
|
||||||
|
'payment_terms' => 'string',
|
||||||
|
'valid_until' => 'string',
|
||||||
|
'default_task_rate' => 'float',
|
||||||
|
'send_reminders' => 'bool',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast object values and return entire class
|
* Cast object values and return entire class
|
||||||
* prevents missing properties from not being returned
|
* prevents missing properties from not being returned
|
||||||
|
@ -28,7 +28,11 @@ class CloneQuoteToInvoiceFactory
|
|||||||
unset($quote_array['invoice_id']);
|
unset($quote_array['invoice_id']);
|
||||||
unset($quote_array['id']);
|
unset($quote_array['id']);
|
||||||
unset($quote_array['invitations']);
|
unset($quote_array['invitations']);
|
||||||
unset($quote_array['terms']);
|
|
||||||
|
//preserve terms if they exist on Quotes
|
||||||
|
if(strlen($quote_array['terms']) < 2)
|
||||||
|
unset($quote_array['terms']);
|
||||||
|
|
||||||
// unset($quote_array['public_notes']);
|
// unset($quote_array['public_notes']);
|
||||||
unset($quote_array['footer']);
|
unset($quote_array['footer']);
|
||||||
unset($quote_array['design_id']);
|
unset($quote_array['design_id']);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Utils\Traits;
|
namespace App\Utils\Traits;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
use App\DataMapper\CompanySettings;
|
use App\DataMapper\CompanySettings;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
|
|
||||||
@ -63,15 +64,6 @@ trait ClientGroupSettingsSaver
|
|||||||
$entity_settings->{$key} = $value;
|
$entity_settings->{$key} = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this pass will handle any null values that are in the translations
|
|
||||||
// foreach ($settings->translations as $key => $value) {
|
|
||||||
// if (is_null($settings->translations[$key])) {
|
|
||||||
// $settings->translations[$key] = '';
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $entity_settings->translations = $settings->translations;
|
|
||||||
|
|
||||||
$entity->settings = $entity_settings;
|
$entity->settings = $entity_settings;
|
||||||
$entity->save();
|
$entity->save();
|
||||||
|
|
||||||
@ -92,6 +84,8 @@ trait ClientGroupSettingsSaver
|
|||||||
$settings = (object) $settings;
|
$settings = (object) $settings;
|
||||||
$casts = CompanySettings::$casts;
|
$casts = CompanySettings::$casts;
|
||||||
|
|
||||||
|
// $casts = ClientSettings::$property_casts;
|
||||||
|
|
||||||
ksort($casts);
|
ksort($casts);
|
||||||
|
|
||||||
if(property_exists($settings, 'translations'))
|
if(property_exists($settings, 'translations'))
|
||||||
@ -121,7 +115,7 @@ trait ClientGroupSettingsSaver
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*Separate loop if it is a _id field which is an integer cast as a string*/
|
/*Separate loop if it is a _id field which is an integer cast as a string*/
|
||||||
elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') {
|
elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter' || $key == 'payment_terms' || $key == 'valid_until') {
|
||||||
$value = 'integer';
|
$value = 'integer';
|
||||||
|
|
||||||
if (! property_exists($settings, $key)) {
|
if (! property_exists($settings, $key)) {
|
||||||
@ -170,7 +164,7 @@ trait ClientGroupSettingsSaver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*Separate loop if it is a _id field which is an integer cast as a string*/
|
/*Separate loop if it is a _id field which is an integer cast as a string*/
|
||||||
if (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') {
|
if (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter' || $key == 'payment_terms' || $key == 'valid_until') {
|
||||||
$value = 'integer';
|
$value = 'integer';
|
||||||
|
|
||||||
if (! property_exists($settings, $key)) {
|
if (! property_exists($settings, $key)) {
|
||||||
|
@ -52,7 +52,7 @@ trait SettingsSaver
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/*Separate loop if it is a _id field which is an integer cast as a string*/
|
/*Separate loop if it is a _id field which is an integer cast as a string*/
|
||||||
elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') {
|
elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter' || $key == 'payment_terms' || $key == 'valid_until') {
|
||||||
$value = 'integer';
|
$value = 'integer';
|
||||||
|
|
||||||
if($key == 'gmail_sending_user_id')
|
if($key == 'gmail_sending_user_id')
|
||||||
|
337
tests/Unit/ClientSettingsTest.php
Normal file
337
tests/Unit/ClientSettingsTest.php
Normal file
@ -0,0 +1,337 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use App\DataMapper\ClientSettings;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Tests\MockAccountData;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
class ClientSettingsTest extends TestCase
|
||||||
|
{
|
||||||
|
use MockAccountData;
|
||||||
|
use DatabaseTransactions;
|
||||||
|
|
||||||
|
public function setUp() :void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->makeTestData();
|
||||||
|
|
||||||
|
$this->faker = \Faker\Factory::create();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testClientBaseline()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
];
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals("1", $arr['data']['settings']['currency_id']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testClientValidSettings()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => 10,
|
||||||
|
'send_reminders' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertEquals("1", $arr['data']['settings']['currency_id']);
|
||||||
|
$this->assertEquals("1", $arr['data']['settings']['language_id']);
|
||||||
|
$this->assertEquals("1", $arr['data']['settings']['payment_terms']);
|
||||||
|
$this->assertEquals(10, $arr['data']['settings']['default_task_rate']);
|
||||||
|
$this->assertEquals(true, $arr['data']['settings']['send_reminders']);
|
||||||
|
$this->assertEquals("1", $arr['data']['settings']['valid_until']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientIllegalCurrency()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => 'a',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => 10,
|
||||||
|
'send_reminders' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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(302);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientIllegalLanguage()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => 'a',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => 10,
|
||||||
|
'send_reminders' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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(302);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientIllegalPaymenTerms()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => 'a',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => 10,
|
||||||
|
'send_reminders' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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(302);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testClientIllegalValidUntil()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => 'a',
|
||||||
|
'default_task_rate' => 10,
|
||||||
|
'send_reminders' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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(302);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientIllegalDefaultTaskRate()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => "a",
|
||||||
|
'send_reminders' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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);
|
||||||
|
$arr = $response->json();
|
||||||
|
|
||||||
|
$this->assertFalse(array_key_exists('default_task_rate', $arr));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientIllegalSendReminderBool()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => "a",
|
||||||
|
'send_reminders' => "faaalse"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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(302);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testClientSettingBools()
|
||||||
|
{
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => $this->faker->firstName,
|
||||||
|
'id_number' => 'Coolio',
|
||||||
|
'settings' => [
|
||||||
|
'currency_id' => '1',
|
||||||
|
'language_id' => '1',
|
||||||
|
'payment_terms' => '1',
|
||||||
|
'valid_until' => '1',
|
||||||
|
'default_task_rate' => "a",
|
||||||
|
'send_reminders' => "true"
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user