mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01:00
19080933b6
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started. For more information on customizing the code style applied by Shift, [watch this short video][4]. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://github.com/squizlabs/PHP_CodeSniffer [3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 [4]: https://laravelshift.com/videos/shift-code-style
315 lines
9.0 KiB
PHP
315 lines
9.0 KiB
PHP
<?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://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
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);
|
|
}
|
|
}
|