Skip to content

Commit

Permalink
Merge pull request #82 from turbo124/main
Browse files Browse the repository at this point in the history
Add Expense Categories and Group Settings
  • Loading branch information
turbo124 authored Mar 11, 2022
2 parents 252cb51 + fbf0d25 commit a23acf1
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/Endpoints/ExpenseCategories.php
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;
}

}

30 changes: 30 additions & 0 deletions src/Endpoints/GroupSettings.php
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;
}

}

10 changes: 9 additions & 1 deletion src/InvoiceNinja.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use InvoiceNinja\Sdk\Endpoints\Clients;
use InvoiceNinja\Sdk\Endpoints\Companies;
use InvoiceNinja\Sdk\Endpoints\Credits;
use InvoiceNinja\Sdk\Endpoints\ExpenseCategories;
use InvoiceNinja\Sdk\Endpoints\Expenses;
use InvoiceNinja\Sdk\Endpoints\GroupSettings;
use InvoiceNinja\Sdk\Endpoints\Invoices;
use InvoiceNinja\Sdk\Endpoints\Payments;
use InvoiceNinja\Sdk\Endpoints\Products;
Expand Down Expand Up @@ -74,6 +76,10 @@ class InvoiceNinja

public Companies $companies;

public ExpenseCategories $expense_categories;

public GroupSettings $group_settings;

/**
* @param string $token
* @return void
Expand Down Expand Up @@ -105,7 +111,9 @@ private function initialize()
$this->vendors = new Vendors($this);
$this->users = new Users($this);
$this->companies = new Companies($this);

$this->expense_categories = new ExpenseCategories($this);
$this->group_settings = new GroupSettings($this);

return $this;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/CreditsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function testCreditPost()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$credits = $ninja->credits->create(['clint_id' => '7LDdwRb1YK']);
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);

$credits = $ninja->credits->create(['client_id' => $client['data']['id']]);

$this->assertTrue(is_array($credits));

Expand Down
91 changes: 91 additions & 0 deletions tests/ExpenseCategoriesTest.php
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));

}
}
74 changes: 74 additions & 0 deletions tests/GroupSettingsTest.php
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']);

}


}

0 comments on commit a23acf1

Please sign in to comment.