2020-08-02 08:31:55 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
namespace Tests\Feature;
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
use App\DataMapper\Settings\SettingsData;
|
2020-08-02 08:31:55 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-09-06 11:38:10 +02:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Support\Facades\Session;
|
2023-11-26 08:41:42 +01:00
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
class GroupSettingTest extends TestCase
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
use MockAccountData;
|
|
|
|
|
2023-10-20 07:30:11 +02:00
|
|
|
public $faker;
|
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp(): void
|
2020-08-02 08:31:55 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
Session::start();
|
|
|
|
|
|
|
|
$this->faker = \Faker\Factory::create();
|
|
|
|
|
|
|
|
Model::reguard();
|
|
|
|
|
|
|
|
$this->makeTestData();
|
|
|
|
}
|
|
|
|
|
2023-10-20 07:30:11 +02:00
|
|
|
public function testCastingMagic()
|
|
|
|
{
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
$settings->tax_name1 = '';
|
|
|
|
$settings->tax_rate1 = 0;
|
|
|
|
$s = new SettingsData();
|
|
|
|
$settings = $s->cast($settings)->toObject();
|
|
|
|
|
|
|
|
$this->assertEquals("", $settings->tax_name1);
|
|
|
|
$settings = null;
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
$settings->tax_name1 = "1";
|
|
|
|
$settings->tax_rate1 = 0;
|
|
|
|
|
|
|
|
$settings = $s->cast($settings)->toObject();
|
|
|
|
|
|
|
|
$this->assertEquals("1", $settings->tax_name1);
|
|
|
|
|
|
|
|
$settings = $s->cast($settings)->toArray();
|
|
|
|
$this->assertEquals("1", $settings['tax_name1']);
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
$settings->tax_name1 = [];
|
|
|
|
$settings->tax_rate1 = 0;
|
|
|
|
|
|
|
|
$settings = $s->cast($settings)->toObject();
|
|
|
|
|
|
|
|
$this->assertEquals("", $settings->tax_name1);
|
|
|
|
|
|
|
|
$settings = $s->cast($settings)->toArray();
|
|
|
|
$this->assertEquals("", $settings['tax_name1']);
|
|
|
|
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
$settings->tax_name1 = new \stdClass;
|
|
|
|
$settings->tax_rate1 = 0;
|
|
|
|
|
|
|
|
$settings = $s->cast($settings)->toObject();
|
|
|
|
|
|
|
|
$this->assertEquals("", $settings->tax_name1);
|
|
|
|
|
|
|
|
$settings = $s->cast($settings)->toArray();
|
|
|
|
$this->assertEquals("", $settings['tax_name1']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// nlog(json_encode($settings));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTaxNameInGroupFilters()
|
|
|
|
{
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
$settings->tax_name1 = '';
|
|
|
|
$settings->tax_rate1 = 0;
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'name' => 'testX',
|
|
|
|
'settings' => $settings,
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->postJson('/api/v1/group_settings', $data);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
2023-11-26 08:41:42 +01:00
|
|
|
$this->assertEquals("", (string)null);
|
2023-10-20 07:30:11 +02:00
|
|
|
$this->assertNotNull($arr['data']['settings']['tax_name1']);
|
|
|
|
}
|
|
|
|
|
2023-04-29 01:44:34 +02:00
|
|
|
|
|
|
|
public function testAddGroupFilters()
|
|
|
|
{
|
|
|
|
$settings = new \stdClass;
|
|
|
|
$settings->currency_id = '1';
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'name' => 'testX',
|
|
|
|
'settings' => $settings,
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->postJson('/api/v1/group_settings', $data);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$this->assertEquals('testX', $arr['data']['name']);
|
|
|
|
$this->assertEquals(0, $arr['data']['archived_at']);
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->get('/api/v1/group_settings?name=fdfdfd');
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$this->assertCount(0, $arr['data']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
public function testAddGroupSettings()
|
|
|
|
{
|
|
|
|
$settings = new \stdClass;
|
2020-11-17 11:26:45 +01:00
|
|
|
$settings->currency_id = '1';
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
$data = [
|
2020-09-08 12:44:32 +02:00
|
|
|
'name' => 'testX',
|
2020-09-06 11:38:10 +02:00
|
|
|
'settings' => $settings,
|
2020-08-02 08:31:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-24 03:55:41 +02:00
|
|
|
])->postJson('/api/v1/group_settings', $data);
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
$arr = $response->json();
|
|
|
|
|
2020-09-08 12:44:32 +02:00
|
|
|
$this->assertEquals('testX', $arr['data']['name']);
|
2020-08-02 08:31:55 +02:00
|
|
|
$this->assertEquals(0, $arr['data']['archived_at']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testArchiveGroupSettings()
|
|
|
|
{
|
|
|
|
$settings = new \stdClass;
|
2020-11-17 11:26:45 +01:00
|
|
|
$settings->currency_id = '1';
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
$data = [
|
2020-09-08 12:44:32 +02:00
|
|
|
'name' => 'testY',
|
2020-09-06 11:38:10 +02:00
|
|
|
'settings' => $settings,
|
2020-08-02 08:31:55 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-24 03:55:41 +02:00
|
|
|
])->postJson('/api/v1/group_settings', $data);
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
$arr = $response->json();
|
2023-04-29 13:10:26 +02:00
|
|
|
$id = $arr['data']['id'];
|
|
|
|
|
|
|
|
$this->assertEquals(0, $arr['data']['archived_at']);
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'action' => 'archive',
|
2023-04-29 13:10:26 +02:00
|
|
|
'ids' => [$id],
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->postJson('/api/v1/group_settings/bulk', $data);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$this->assertNotNull($arr['data'][0]['archived_at']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'action' => 'restore',
|
|
|
|
'ids' => [$id],
|
|
|
|
];
|
|
|
|
|
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
|
|
|
])->postJson('/api/v1/group_settings/bulk', $data);
|
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
|
|
|
|
|
|
|
$this->assertEquals(0, $arr['data'][0]['archived_at']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'action' => 'delete',
|
|
|
|
'ids' => [$id],
|
2020-08-02 08:31:55 +02:00
|
|
|
];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
$response = $this->withHeaders([
|
|
|
|
'X-API-SECRET' => config('ninja.api_secret'),
|
|
|
|
'X-API-TOKEN' => $this->token,
|
2022-06-24 03:55:41 +02:00
|
|
|
])->postJson('/api/v1/group_settings/bulk', $data);
|
2020-08-02 08:31:55 +02:00
|
|
|
|
|
|
|
$response->assertStatus(200);
|
|
|
|
|
|
|
|
$arr = $response->json();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-02 12:34:16 +02:00
|
|
|
$this->assertNotNull($arr['data'][0]['archived_at']);
|
2023-04-29 13:10:26 +02:00
|
|
|
$this->assertTrue($arr['data'][0]['is_deleted']);
|
|
|
|
|
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
}
|
2023-04-29 13:10:26 +02:00
|
|
|
|
2020-08-02 08:31:55 +02:00
|
|
|
}
|