Skip to content

Commit

Permalink
Faker
Browse files Browse the repository at this point in the history
  • Loading branch information
turbo124 committed Sep 16, 2021
1 parent 7210e3e commit fc64f51
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 15 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"guzzlehttp/guzzle": "^7.3"
},
"require-dev": {
"fakerphp/faker": "^1.16",
"phpunit/phpunit": "^9.5"
},
"autoload-dev": {
Expand Down
18 changes: 15 additions & 3 deletions tests/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ class ClientsTest extends TestCase

public function testClients()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

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

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

$clients = $ninja->clients->all(['balance' => '0:gt']);

$this->assertTrue(is_array($clients));
Expand All @@ -33,11 +36,18 @@ public function testClients()

public function testClientGet()
{

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

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

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

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$clients = $ninja->clients->get('7LDdwRb1YK');
$clients = $ninja->clients->get($client['data']['id']);

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

Expand All @@ -50,7 +60,9 @@ public function testClientPut()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$clients = $ninja->clients->update('7LDdwRb1YK', ['name' => 'A new client name updated']);
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);

$clients = $ninja->clients->update($client['data']['id'], ['name' => 'A new client name updated']);

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

Expand Down
16 changes: 14 additions & 2 deletions tests/InvoicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function testInvoices()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

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

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

$invoices = $ninja->invoices->all();

$this->assertTrue(is_array($invoices));
Expand All @@ -37,7 +41,11 @@ public function testInvoiceGet()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$invoices = $ninja->invoices->get('4w9aAOdvMR');
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);

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

$invoices = $ninja->invoices->get($invoice['data']['id']);

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

Expand All @@ -50,7 +58,11 @@ public function testInvoicePut()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$invoices = $ninja->invoices->update('4w9aAOdvMR', ['discount' => '10']);
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);

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

$invoices = $ninja->invoices->update($invoice['data']['id'], ['discount' => '10']);

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

Expand Down
10 changes: 8 additions & 2 deletions tests/PaymentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function testInvoiceGet()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$payments = $ninja->payments->get('VolejRejNm');
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);
$payment = $ninja->payments->create(['client_id' => $client['data']['id'], 'amount' => 10]);

$payments = $ninja->payments->get($payment['data']['id']);

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

Expand All @@ -50,7 +53,10 @@ public function testInvoicePut()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$payments = $ninja->payments->update('VolejRejNm', ['transaction_reference' => 'ref']);
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);
$payment = $ninja->payments->create(['client_id' => $client['data']['id'], 'amount' => 10]);

$payments = $ninja->payments->update($payment['data']['id'], ['transaction_reference' => 'ref']);

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

Expand Down
8 changes: 6 additions & 2 deletions tests/ProductsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public function testInvoiceGet()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$products = $ninja->products->get('gl9avmeG1v');
$product = $ninja->products->create(['product_key' => 'that']);

$products = $ninja->products->get($product['data']['id']);

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

Expand All @@ -50,7 +52,9 @@ public function testInvoicePut()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$products = $ninja->products->update('gl9avmeG1v', ['product_key' => 'this']);
$product = $ninja->products->create(['product_key' => 'thatx']);

$products = $ninja->products->update($product['data']['id'], ['product_key' => 'this']);

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

Expand Down
14 changes: 11 additions & 3 deletions tests/QuotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function testQuoteGet()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$quotes = $ninja->quotes->get('gl9avmeG1v');
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);
$quote = $ninja->quotes->create(['client_id' => $client['data']['id']]);

$quotes = $ninja->quotes->get($quote['data']['id']);

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

Expand All @@ -50,7 +53,11 @@ public function testQuotePut()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$quotes = $ninja->quotes->update('gl9avmeG1v', ['discount' => '10']);

$client = $ninja->clients->create(['name' => 'Brand spanking new client']);
$quote = $ninja->quotes->create(['client_id' => $client['data']['id']]);

$quotes = $ninja->quotes->update($quote['data']['id'], ['discount' => '10']);

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

Expand All @@ -62,8 +69,9 @@ public function testQuotePost()

$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);
$client = $ninja->clients->create(['name' => 'Brand spanking new client']);

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

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

Expand Down
17 changes: 14 additions & 3 deletions tests/TaxRatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class TaxRatesTest extends TestCase
protected string $token = "company-token-test";
protected string $url = "http://ninja.test:8000";

public $faker;

protected function setUp(): void
{
$this->faker = \Faker\Factory::create();
}

public function testProducts()
{

Expand All @@ -37,7 +44,9 @@ public function testTaxRateGet()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$tax_rates = $ninja->tax_rates->get('Opnel5aKBz');
$tax_rate = $ninja->tax_rates->create(['rate' => 10, 'name' => $this->faker->word()]);

$tax_rates = $ninja->tax_rates->get($tax_rate['data']['id']);

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

Expand All @@ -50,7 +59,9 @@ public function testTaxRatePut()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$tax_rates = $ninja->tax_rates->update('Opnel5aKBz', ['rate' => 10, 'name' => 'GST']);
$tax_rate = $ninja->tax_rates->create(['rate' => 10, 'name' => 'GSTa']);

$tax_rates = $ninja->tax_rates->update($tax_rate['data']['id'], ['rate' => 10, 'name' => $this->faker->word()]);

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

Expand All @@ -63,7 +74,7 @@ public function testTaxRatePost()
$ninja = new InvoiceNinja($this->token);
$ninja->setUrl($this->url);

$tax_rates = $ninja->tax_rates->create(['rate' => 10, 'name' => 'GSTX']);
$tax_rates = $ninja->tax_rates->create(['rate' => 10, 'name' => $this->faker->word()]);

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

Expand Down

0 comments on commit fc64f51

Please sign in to comment.