From 7707f9ac7b9a2dd8d9c1ec16c8eeab6b12eb2c21 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 12 Mar 2022 10:16:37 +1100 Subject: [PATCH] Add group and expense categories --- src/Endpoints/ExpenseCategories.php | 30 ++++++++++ src/Endpoints/GroupSettings.php | 30 ++++++++++ src/InvoiceNinja.php | 10 +++- tests/CreditsTest.php | 4 +- tests/ExpenseCategoriesTest.php | 91 +++++++++++++++++++++++++++++ tests/GroupSettingsTest.php | 74 +++++++++++++++++++++++ 6 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 src/Endpoints/ExpenseCategories.php create mode 100644 src/Endpoints/GroupSettings.php create mode 100644 tests/ExpenseCategoriesTest.php create mode 100644 tests/GroupSettingsTest.php diff --git a/src/Endpoints/ExpenseCategories.php b/src/Endpoints/ExpenseCategories.php new file mode 100644 index 0000000..8866cec --- /dev/null +++ b/src/Endpoints/ExpenseCategories.php @@ -0,0 +1,30 @@ +ninja = $ninja; + } + +} + diff --git a/src/Endpoints/GroupSettings.php b/src/Endpoints/GroupSettings.php new file mode 100644 index 0000000..2dba823 --- /dev/null +++ b/src/Endpoints/GroupSettings.php @@ -0,0 +1,30 @@ +ninja = $ninja; + } + +} + diff --git a/src/InvoiceNinja.php b/src/InvoiceNinja.php index ea3e262..b4a5521 100644 --- a/src/InvoiceNinja.php +++ b/src/InvoiceNinja.php @@ -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; @@ -69,6 +71,10 @@ class InvoiceNinja public Companies $companies; + public ExpenseCategories $expense_categories; + + public GroupSettings $group_settings; + /** * @param string $token * @return void @@ -96,7 +102,9 @@ private function initialize() $this->tasks = new Tasks($this); $this->vendors = new Vendors($this); $this->companies = new Companies($this); - + $this->expense_categories = new ExpenseCategories($this); + $this->group_settings = new GroupSettings($this); + return $this; } /** diff --git a/tests/CreditsTest.php b/tests/CreditsTest.php index 7188aa5..b14d4c5 100644 --- a/tests/CreditsTest.php +++ b/tests/CreditsTest.php @@ -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)); diff --git a/tests/ExpenseCategoriesTest.php b/tests/ExpenseCategoriesTest.php new file mode 100644 index 0000000..d3962a0 --- /dev/null +++ b/tests/ExpenseCategoriesTest.php @@ -0,0 +1,91 @@ +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)); + + } +} \ No newline at end of file diff --git a/tests/GroupSettingsTest.php b/tests/GroupSettingsTest.php new file mode 100644 index 0000000..33b5056 --- /dev/null +++ b/tests/GroupSettingsTest.php @@ -0,0 +1,74 @@ +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']); + + } + + +} \ No newline at end of file