1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/tests/Unit/ClientSettingsTest.php

427 lines
13 KiB
PHP
Raw Normal View History

2022-04-18 13:02:06 +02:00
<?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
2022-04-18 13:02:06 +02:00
*/
2022-04-18 13:02:06 +02:00
namespace Tests\Unit;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Validation\ValidationException;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
*/
class ClientSettingsTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
2023-09-14 13:12:41 +02:00
public $faker;
protected function setUp() :void
2022-04-18 13:02:06 +02:00
{
parent::setUp();
$this->makeTestData();
$this->faker = \Faker\Factory::create();
}
2023-09-14 13:12:41 +02:00
public function testClientValidSettingsWithBadProps()
{
$data = [
'name' => $this->faker->firstName(),
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '43',
'language_id' => '1',
'website' => null,
'address1' => null,
'address2' => null,
'city' => null,
'state' => null,
'postal_code' => null,
'phone' => null,
'email' => null,
'vat_number' => null,
'id_number' => null,
'purchase_order_terms' => null,
'purchase_order_footer' => null,
'besr_id' => null,
'qr_iban' => null,
'name' => 'frank',
'custom_value1' => null,
'custom_value2' => null,
'custom_value3' => null,
'custom_value4' => null,
'invoice_terms' => null,
'quote_terms' =>null,
'quote_footer' => null,
'credit_terms' => null,
'credit_footer' => null,
],
];
$response = false;
2023-11-26 08:41:42 +01:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/clients/', $data);
2023-09-14 13:12:41 +02:00
$response->assertStatus(200);
$arr = $response->json();
$this->assertEquals('frank', $arr['data']['settings']['name']);
$client_id = $arr['data']['id'];
$data = [
'name' => $this->faker->firstName(),
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '43',
'language_id' => '1',
'name' => 'white',
],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson('/api/v1/clients/'.$client_id, $data);
$response->assertStatus(200);
$arr = $response->json();
2023-09-14 13:12:41 +02:00
$this->assertEquals('white', $arr['data']['settings']['name']);
$data = [
'name' => $this->faker->firstName(),
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '43',
'language_id' => '1',
'website' => null,
'address1' => null,
'besr_id' => null,
'qr_iban' => null,
'name' => 'white',
'custom_value1' => null,
'custom_value2' => null,
'custom_value3' => null,
'custom_value4' => null,
'invoice_terms' => null,
'quote_terms' =>null,
'quote_footer' => null,
'credit_terms' => null,
'credit_footer' => null,
],
];
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->putJson('/api/v1/clients/'.$client_id, $data);
$response->assertStatus(200);
$arr = $response->json();
$this->assertEquals('white', $arr['data']['settings']['name']);
// $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']);
}
2022-04-18 13:02:06 +02:00
public function testClientBaseline()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'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);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
}
$response->assertStatus(200);
$arr = $response->json();
$this->assertEquals('1', $arr['data']['settings']['currency_id']);
2022-04-18 13:02:06 +02:00
}
public function testClientValidSettings()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => '1',
'payment_terms' => '1',
'valid_until' => '1',
'default_task_rate' => 10,
'send_reminders' => true,
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
}
$response->assertStatus(200);
$arr = $response->json();
2022-06-23 05:12:28 +02:00
$this->assertEquals('1', $arr['data']['settings']['currency_id']);
$this->assertEquals('1', $arr['data']['settings']['language_id']);
$this->assertEquals('1', $arr['data']['settings']['payment_terms']);
2022-04-18 13:02:06 +02:00
$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']);
2022-04-18 13:02:06 +02:00
}
public function testClientIllegalCurrency()
2022-06-23 05:12:28 +02:00
{
2022-04-18 13:02:06 +02:00
$data = [
'name' => $this->faker->firstName(),
2022-06-23 01:24:56 +02:00
'id_number' => 'Cooliox2',
2022-04-18 13:02:06 +02:00
'settings' => [
2022-06-23 05:12:28 +02:00
'currency_id' => 'a',
2022-04-18 13:02:06 +02:00
'language_id' => '1',
'payment_terms' => '1',
2022-06-23 01:24:56 +02:00
'valid_until' => '2',
2022-04-18 13:02:06 +02:00
'default_task_rate' => 10,
'send_reminders' => true,
],
2022-04-18 13:02:06 +02:00
];
$response = false;
2023-11-26 08:41:42 +01:00
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->postJson('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
$response->assertStatus(422);
2022-04-18 13:02:06 +02:00
}
public function testClientIllegalLanguage()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => 'a',
'payment_terms' => '1',
'valid_until' => '1',
'default_task_rate' => 10,
'send_reminders' => true,
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
2024-02-04 05:06:24 +01:00
// nlog($message);
2022-04-18 13:02:06 +02:00
}
$response->assertStatus(302);
}
public function testClientIllegalPaymenTerms()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => '1',
'payment_terms' => 'a',
'valid_until' => '1',
'default_task_rate' => 10,
'send_reminders' => true,
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
nlog($message);
}
$response->assertStatus(302);
}
public function testClientIllegalValidUntil()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => '1',
'payment_terms' => '1',
'valid_until' => 'a',
'default_task_rate' => 10,
'send_reminders' => true,
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
nlog($message);
}
$response->assertStatus(302);
}
public function testClientIllegalDefaultTaskRate()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => '1',
'payment_terms' => '1',
'valid_until' => '1',
'default_task_rate' => 'a',
'send_reminders' => true,
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} 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(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => '1',
'payment_terms' => '1',
'valid_until' => '1',
'default_task_rate' => 'a',
'send_reminders' => 'faaalse',
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
nlog($message);
}
$response->assertStatus(302);
}
public function testClientSettingBools()
{
$data = [
'name' => $this->faker->firstName(),
2022-04-18 13:02:06 +02:00
'id_number' => 'Coolio',
'settings' => [
'currency_id' => '1',
'language_id' => '1',
'payment_terms' => '1',
'valid_until' => '1',
'default_task_rate' => 'a',
'send_reminders' => 'true',
],
2022-04-18 13:02:06 +02:00
];
$response = false;
try {
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $this->token,
])->post('/api/v1/clients/', $data);
2022-04-18 13:02:06 +02:00
} catch (ValidationException $e) {
$message = json_decode($e->validator->getMessageBag(), 1);
nlog($message);
}
$response->assertStatus(200);
}
}