-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from turbo124/main
Add Expense Categories and Group Settings
- Loading branch information
Showing
6 changed files
with
237 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Invoice Ninja (https://invoiceninja.com). | ||
* | ||
* @link https://github.com/invoiceninja/sdk-php source repository | ||
* | ||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) | ||
* | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace InvoiceNinja\Sdk\Endpoints; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use InvoiceNinja\Sdk\InvoiceNinja; | ||
|
||
class ExpenseCategories extends BaseEntity | ||
{ | ||
|
||
protected InvoiceNinja $ninja; | ||
|
||
protected string $uri = "/api/v1/expense_categories"; | ||
|
||
public function __construct(InvoiceNinja $ninja) | ||
{ | ||
$this->ninja = $ninja; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Invoice Ninja (https://invoiceninja.com). | ||
* | ||
* @link https://github.com/invoiceninja/sdk-php source repository | ||
* | ||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) | ||
* | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace InvoiceNinja\Sdk\Endpoints; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
use InvoiceNinja\Sdk\InvoiceNinja; | ||
|
||
class GroupSettings extends BaseEntity | ||
{ | ||
|
||
protected InvoiceNinja $ninja; | ||
|
||
protected string $uri = "/api/v1/group_settings"; | ||
|
||
public function __construct(InvoiceNinja $ninja) | ||
{ | ||
$this->ninja = $ninja; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Invoice Ninja (https://invoiceninja.com). | ||
* | ||
* @link https://github.com/invoiceninja/sdk-php source repository | ||
* | ||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) | ||
* | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace InvoiceNinja\Sdk\Tests; | ||
|
||
use InvoiceNinja\Sdk\InvoiceNinja; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ExpenseCategoriesTest extends TestCase | ||
{ | ||
protected string $token = "company-token-test"; | ||
protected string $url = "http://ninja.test:8000"; | ||
|
||
|
||
public function setUp() :void | ||
{ | ||
parent::setUp(); | ||
$this->faker = \Faker\Factory::create(); | ||
|
||
} | ||
|
||
public function testExpenseCategoriesPost() | ||
{ | ||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
$expense_categories = $ninja->expense_categories->create(['name' => $this->faker->firstName]); | ||
|
||
$this->assertTrue(is_array($expense_categories)); | ||
|
||
$expense_categories = $ninja->expense_categories->all(); | ||
|
||
$this->assertTrue(is_array($expense_categories)); | ||
|
||
} | ||
|
||
public function testExpenseCategoryGet() | ||
{ | ||
|
||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
$expense_categories = $ninja->expense_categories->create(['name' => $this->faker->firstName]); | ||
|
||
$this->assertTrue(is_array($expense_categories)); | ||
|
||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
$expense_categories = $ninja->expense_categories->get($expense_categories['data']['id']); | ||
|
||
$this->assertTrue(is_array($expense_categories)); | ||
|
||
} | ||
|
||
|
||
public function testExpenseCategoryPut() | ||
{ | ||
|
||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
$expense_categories = $ninja->expense_categories->create(['name' => $this->faker->firstName]); | ||
|
||
$expense_categories = $ninja->expense_categories->update($expense_categories['data']['id'], ['name' => $this->faker->firstName]); | ||
|
||
$this->assertTrue(is_array($expense_categories)); | ||
|
||
} | ||
|
||
|
||
public function testExpenseCategoryPost() | ||
{ | ||
|
||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
$expense_categories = $ninja->expense_categories->create(['name' => $this->faker->firstName]); | ||
|
||
$this->assertTrue(is_array($expense_categories)); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Invoice Ninja (https://invoiceninja.com). | ||
* | ||
* @link https://github.com/invoiceninja/sdk-php source repository | ||
* | ||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com) | ||
* | ||
* @license https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
namespace InvoiceNinja\Sdk\Tests; | ||
|
||
use InvoiceNinja\Sdk\InvoiceNinja; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GroupSettingsTest extends TestCase | ||
{ | ||
protected string $token = "company-token-test"; | ||
protected string $url = "http://ninja.test:8000"; | ||
|
||
|
||
public function setUp() :void | ||
{ | ||
parent::setUp(); | ||
$this->faker = \Faker\Factory::create(); | ||
|
||
} | ||
|
||
public function testAddGroupSetting() | ||
{ | ||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
|
||
$settings = new \stdClass; | ||
$settings->currency_id = '1'; | ||
|
||
$group_setting = $ninja->group_settings->create(['name' => $this->faker->firstName, 'settings' => $settings]); | ||
|
||
$this->assertTrue(is_array($group_setting)); | ||
|
||
$group_settings = $ninja->group_settings->all(); | ||
|
||
$this->assertTrue(is_array($group_settings)); | ||
|
||
} | ||
|
||
|
||
public function testUpdateGroupSetting() | ||
{ | ||
$ninja = new InvoiceNinja($this->token); | ||
$ninja->setUrl($this->url); | ||
|
||
$settings = new \stdClass; | ||
$settings->currency_id = '1'; | ||
|
||
$new_name = $this->faker->firstName; | ||
$group_setting = $ninja->group_settings->create(['name' => $new_name, 'settings' => $settings]); | ||
$this->assertTrue(is_array($group_setting)); | ||
|
||
$newer_name = $this->faker->firstName; | ||
$settings = new \stdClass; | ||
$settings->currency_id = '2'; | ||
|
||
$updated_group_setting = $ninja->group_settings->update($group_setting['data']['id'], ['name' => $newer_name, 'settings' => $settings]); | ||
|
||
$this->assertEquals($newer_name, $updated_group_setting['data']['name']); | ||
$this->assertEquals('2', $updated_group_setting['data']['settings']['currency_id']); | ||
|
||
} | ||
|
||
|
||
} |