mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
New test for edit form that is more inclusive.
This commit is contained in:
parent
72fc88f3c6
commit
e3b11a9eb2
@ -93,8 +93,9 @@ class AccountController extends Controller
|
||||
|
||||
// the opening balance is tricky:
|
||||
$openingBalanceAmount = null;
|
||||
|
||||
if ($openingBalance) {
|
||||
$transaction = $openingBalance->transactions()->where('account_id', $account->id)->first();
|
||||
$transaction = $repository->getFirstTransaction($openingBalance, $account);
|
||||
$openingBalanceAmount = $transaction->amount;
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,18 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public function getFirstTransaction(TransactionJournal $journal, Account $account)
|
||||
{
|
||||
|
||||
return $journal->transactions()->where('account_id', $account->id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
*
|
||||
@ -170,7 +182,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
*/
|
||||
public function leftOnAccount(Account $account)
|
||||
{
|
||||
$balance = \Steam::balance($account,null,true);
|
||||
$balance = \Steam::balance($account, null, true);
|
||||
/** @var PiggyBank $p */
|
||||
foreach ($account->piggybanks()->get() as $p) {
|
||||
$balance -= $p->currentRelevantRep()->currentamount;
|
||||
|
@ -5,6 +5,7 @@ namespace FireflyIII\Repositories\Account;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@ -86,4 +87,13 @@ interface AccountRepositoryInterface
|
||||
* @return Collection
|
||||
*/
|
||||
public function getSavingsAccounts();
|
||||
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Transaction
|
||||
*/
|
||||
public function getFirstTransaction(TransactionJournal $journal, Account $account);
|
||||
}
|
||||
|
@ -274,4 +274,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
public function first()
|
||||
{
|
||||
return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
||||
}}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace FireflyIII\Repositories\Journal;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
|
@ -94,6 +94,15 @@ class AccountControllerTest extends TestCase
|
||||
$this->be($account->user);
|
||||
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
|
||||
|
||||
// create a transaction journal that will act as opening balance:
|
||||
$openingBalance = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||
$repository->shouldReceive('openingBalanceTransaction')->andReturn($openingBalance);
|
||||
|
||||
// create a transaction that will be returned for the opening balance transaction:
|
||||
$openingBalanceTransaction = FactoryMuffin::create('FireflyIII\Models\Transaction');
|
||||
$repository->shouldReceive('getFirstTransaction')->andReturn($openingBalanceTransaction);
|
||||
|
||||
// CURRENCY:
|
||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
||||
|
@ -1,6 +1,32 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
|
||||
if (!class_exists('RandomString')) {
|
||||
/**
|
||||
* Class RandomString
|
||||
*/
|
||||
class RandomString
|
||||
{
|
||||
/**
|
||||
* @param int $length
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function generateRandomString($length = 10)
|
||||
{
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\Models\Account', [
|
||||
'user_id' => 'factory|FireflyIII\User',
|
||||
@ -29,10 +55,14 @@ FactoryMuffin::define(
|
||||
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\Models\TransactionCurrency', [
|
||||
'code' => 'EUR',
|
||||
'symbol' => 'x',
|
||||
'name' => 'word'
|
||||
]
|
||||
'code' => function () {
|
||||
return RandomString::generateRandomString(3);
|
||||
},
|
||||
'symbol' => function () {
|
||||
return RandomString::generateRandomString(1);
|
||||
},
|
||||
'name' => 'word'
|
||||
]
|
||||
);
|
||||
|
||||
FactoryMuffin::define(
|
||||
@ -40,4 +70,31 @@ FactoryMuffin::define(
|
||||
'email' => 'email',
|
||||
'password' => bcrypt('james'),
|
||||
]
|
||||
);
|
||||
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\Models\Transaction', [
|
||||
'transaction_journal_id' => 'factory|FireflyIII\Models\TransactionJournal',
|
||||
'amount' => 'integer',
|
||||
'account_id' => 'factory|FireflyIII\Models\Account'
|
||||
]
|
||||
);
|
||||
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\Models\TransactionType', [
|
||||
'type' => 'word',
|
||||
]
|
||||
);
|
||||
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\Models\TransactionJournal', [
|
||||
'user_id' => 'factory|FireflyIII\User',
|
||||
'transaction_type_id' => 'factory|FireflyIII\Models\TransactionType',
|
||||
'transaction_currency_id' => 'factory|FireflyIII\Models\TransactionCurrency',
|
||||
'description' => 'sentence',
|
||||
'completed' => '1',
|
||||
'date' => 'date',
|
||||
'encrypted' => '1',
|
||||
'order' => '0',
|
||||
]
|
||||
);
|
Loading…
Reference in New Issue
Block a user