2015-10-20 19:12:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Codeception\Util\Fixtures;
|
|
|
|
use Faker\Factory;
|
|
|
|
|
2015-10-21 14:40:31 +02:00
|
|
|
class CheckBalanceCest
|
2015-10-20 19:12:34 +02:00
|
|
|
{
|
|
|
|
private $faker;
|
|
|
|
|
|
|
|
public function _before(AcceptanceTester $I)
|
|
|
|
{
|
|
|
|
$I->checkIfLogin($I);
|
|
|
|
|
|
|
|
$this->faker = Factory::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function checkBalance(AcceptanceTester $I)
|
|
|
|
{
|
|
|
|
$I->wantTo('ensure the balance is correct');
|
|
|
|
|
|
|
|
$clientEmail = $this->faker->safeEmail;
|
|
|
|
$productKey = $this->faker->text(10);
|
|
|
|
$productPrice = $this->faker->numberBetween(1, 20);
|
|
|
|
|
|
|
|
// create client
|
|
|
|
$I->amOnPage('/clients/create');
|
2015-10-28 20:22:07 +01:00
|
|
|
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
|
2015-10-20 19:12:34 +02:00
|
|
|
$I->click('Save');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->see($clientEmail);
|
|
|
|
|
|
|
|
$clientId = $I->grabFromCurrentUrl('~clients/(\d+)~');
|
|
|
|
|
|
|
|
// create product
|
|
|
|
$I->amOnPage('/products/create');
|
|
|
|
$I->fillField(['name' => 'product_key'], $productKey);
|
|
|
|
$I->fillField(['name' => 'notes'], $this->faker->text(80));
|
|
|
|
$I->fillField(['name' => 'cost'], $productPrice);
|
|
|
|
$I->click('Save');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->see($productKey);
|
|
|
|
|
|
|
|
// create invoice
|
|
|
|
$I->amOnPage('/invoices/create');
|
|
|
|
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
|
|
|
|
$I->fillField('table.invoice-table tbody tr:nth-child(1) #product_key', $productKey);
|
|
|
|
$I->click('Save');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->see($clientEmail);
|
|
|
|
$invoiceId = $I->grabFromCurrentUrl('~invoices/(\d+)~');
|
|
|
|
$I->amOnPage("/clients/{$clientId}");
|
|
|
|
$I->see('Balance $' . $productPrice);
|
|
|
|
|
|
|
|
// update the invoice
|
|
|
|
$I->amOnPage('/invoices/' . $invoiceId);
|
2015-10-28 20:22:07 +01:00
|
|
|
$I->fillField(['name' => 'invoice_items[0][qty]'], 2);
|
2015-10-20 19:12:34 +02:00
|
|
|
$I->click('Save');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->amOnPage("/clients/{$clientId}");
|
|
|
|
$I->see('Balance $' . ($productPrice * 2));
|
|
|
|
|
|
|
|
// enter payment
|
|
|
|
$I->amOnPage("/payments/create/{$clientId}/{$invoiceId}");
|
|
|
|
$I->click('Save');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->see('Balance $0.00');
|
|
|
|
$I->see('Paid to Date $' . ($productPrice * 2));
|
|
|
|
|
|
|
|
// archive the invoice
|
|
|
|
$I->amOnPage('/invoices/' . $invoiceId);
|
2015-10-28 20:22:07 +01:00
|
|
|
$I->executeJS('submitBulkAction("archive")');
|
2015-10-20 19:12:34 +02:00
|
|
|
$I->wait(1);
|
|
|
|
$I->amOnPage("/clients/{$clientId}");
|
|
|
|
$I->see('Balance $0.00');
|
|
|
|
$I->see('Paid to Date $' . ($productPrice * 2));
|
|
|
|
|
|
|
|
// delete the invoice
|
|
|
|
$I->amOnPage('/invoices/' . $invoiceId);
|
2015-10-28 20:22:07 +01:00
|
|
|
$I->executeJS('submitBulkAction("delete")');
|
2015-10-20 19:12:34 +02:00
|
|
|
$I->wait(1);
|
|
|
|
$I->amOnPage("/clients/{$clientId}");
|
|
|
|
$I->see('Balance $0.00');
|
|
|
|
$I->see('Paid to Date $0.00');
|
2015-10-30 13:56:25 +01:00
|
|
|
|
|
|
|
// restore the invoice
|
|
|
|
$I->amOnPage('/invoices/' . $invoiceId);
|
|
|
|
$I->executeJS('submitBulkAction("restore")');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->amOnPage("/clients/{$clientId}");
|
|
|
|
$I->see('Balance $0.00');
|
|
|
|
$I->see('Paid to Date $' . ($productPrice * 2));
|
2015-10-20 19:12:34 +02:00
|
|
|
}
|
|
|
|
}
|