From c773eb2975ecafbc44f7ee9e10259ff544d63314 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 19 Mar 2017 17:44:35 +0200 Subject: [PATCH] Working on tests --- docs/api.rst | 8 ++++++- tests/_support/AcceptanceTester.php | 5 +---- tests/acceptance/GatewayFeesCest.php | 30 +++++++++++++++----------- tests/acceptance/OnlinePaymentCest.php | 5 ++++- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 6d9203a2c2..890268b639 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -19,7 +19,7 @@ Here’s an example of reading the list of clients using cURL from the command l curl -X GET ninja.dev/api/v1/clients -H "X-Ninja-Token: TOKEN" -For invoices, quotes, tasks and payments simply change the object type. ie, +For invoices, quotes, tasks and payments simply change the object type. .. code-block:: shell @@ -31,6 +31,12 @@ To load a single record specify the Id in the URL. Note: you can add ?invoice_nu curl -X GET ninja.dev/api/v1/invoices/1 -H "X-Ninja-Token: TOKEN" +You can specify additional relationships to load using the ``include`` parameter. + +.. code-block:: shell + + curl -X GET ninja.dev/api/v1/clients/1?include=invoices.invitations -H "X-Ninja-Token: TOKEN" + You can download a PDF using the following URL .. code-block:: shell diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 61af11e812..4ce2397bb6 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -110,11 +110,8 @@ class AcceptanceTester extends \Codeception\Actor $I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable'); } - function createOnlinePayment(\AcceptanceTester $I, $invoiceNumber) + function createOnlinePayment(\AcceptanceTester $I, $invitationKey) { - $invoiceId = $I->grabFromDatabase('invoices', 'id', ['invoice_number' => $invoiceNumber]); - $invitationKey = $I->grabFromDatabase('invitations', 'invitation_key', ['invoice_id' => $invoiceId]); - $clientSession = $I->haveFriend('client'); $clientSession->does(function(AcceptanceTester $I) use ($invitationKey) { $I->amOnPage('/view/' . $invitationKey); diff --git a/tests/acceptance/GatewayFeesCest.php b/tests/acceptance/GatewayFeesCest.php index dd3b32279a..07c4ac2247 100644 --- a/tests/acceptance/GatewayFeesCest.php +++ b/tests/acceptance/GatewayFeesCest.php @@ -70,8 +70,8 @@ class GatewayFeesCest // partial invoice - $invoiceNumber = $this->createInvoice($I, $clientName, $productKey, $total, $partialFeeWithTax, $total / 2); - $this->createPayment($I, $invoiceNumber, $total + $partialFeeWithTax, 0, $partialFeeWithTax); + $invitationKey = $this->createInvoice($I, $clientName, $productKey, $total, $partialFeeWithTax, $total / 2); + $this->createPayment($I, $invitationKey, $total + $partialFeeWithTax, 0, $partialFeeWithTax); } private function configureGatewayFeeTax($I, $taxName = '', $taxRate = '') @@ -155,17 +155,18 @@ class GatewayFeesCest $I->click('Mark Sent'); $I->see($clientEmail); - $balance = $partial ? ($amount - $partial) : 0; - $this->createPayment($I, $invoiceNumber, $amount, $balance, $fee); - - return $invoiceNumber; - } - - private function createPayment($I, $invoiceNumber, $amount, $balance, $fee) - { - $invoiceId = $I->grabFromDatabase('invoices', 'id', ['invoice_number' => $invoiceNumber]); + $clientId = $I->grabFromDatabase('contacts', 'client_id', ['email' => $clientEmail]); + $invoiceId = $I->grabFromDatabase('invoices', 'id', ['client_id' => $clientId, 'invoice_number' => $invoiceNumber]); $invitationKey = $I->grabFromDatabase('invitations', 'invitation_key', ['invoice_id' => $invoiceId]); + $balance = $partial ? ($amount - $partial) : 0; + $this->createPayment($I, $invitationKey, $amount, $balance, $fee); + + return $invitationKey; + } + + private function createPayment($I, $invitationKey, $amount, $balance, $fee) + { // check we correctly remove/add back the gateway fee $I->amOnPage('/view/' . $invitationKey); $I->click('Pay Now'); @@ -181,9 +182,12 @@ class GatewayFeesCest $I->see('$' . number_format($fee, 2) . ' Fee'); $I->see('$' . number_format($fee * 2, 2) . ' Fee'); - $I->createOnlinePayment($I, $invoiceNumber); + $I->createOnlinePayment($I, $invitationKey); + + $invoiceId = $I->grabFromDatabase('invitations', 'invoice_id', ['invitation_key' => $invitationKey]); + $I->seeInDatabase('invoices', [ - 'invoice_number' => $invoiceNumber, + 'invoice_id' => $invoiceId, 'amount' => ($amount + $fee), 'balance' => $balance ]); diff --git a/tests/acceptance/OnlinePaymentCest.php b/tests/acceptance/OnlinePaymentCest.php index ad414d9ac5..3fd1f3e823 100644 --- a/tests/acceptance/OnlinePaymentCest.php +++ b/tests/acceptance/OnlinePaymentCest.php @@ -35,6 +35,7 @@ class OnlinePaymentCest // create invoice $I->amOnPage('/invoices/create'); + $invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value'); $I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle'); $I->fillField('table.invoice-table tbody tr:nth-child(1) #product_key', $productKey); $I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable'); @@ -43,7 +44,9 @@ class OnlinePaymentCest // enter payment $clientId = $I->grabFromDatabase('contacts', 'client_id', ['email' => $clientEmail]); - $invoiceNumber = $I->grabFromDatabase('invoices', 'invoice_number', ['client_id' => $clientId]); + $invoiceId = $I->grabFromDatabase('invoices', 'id', ['client_id' => $clientId, 'invoice_number' => $invoiceNumber]); + $invitationKey = $I->grabFromDatabase('invitations', 'invitation_key', ['invoice_id' => $invoiceId]); + $I->createOnlinePayment($I, $invoiceNumber); /*