mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-27 11:20:39 -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:
|
// the opening balance is tricky:
|
||||||
$openingBalanceAmount = null;
|
$openingBalanceAmount = null;
|
||||||
|
|
||||||
if ($openingBalance) {
|
if ($openingBalance) {
|
||||||
$transaction = $openingBalance->transactions()->where('account_id', $account->id)->first();
|
$transaction = $repository->getFirstTransaction($openingBalance, $account);
|
||||||
$openingBalanceAmount = $transaction->amount;
|
$openingBalanceAmount = $transaction->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,18 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return true;
|
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
|
* @param Preference $preference
|
||||||
*
|
*
|
||||||
@ -170,7 +182,7 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function leftOnAccount(Account $account)
|
public function leftOnAccount(Account $account)
|
||||||
{
|
{
|
||||||
$balance = \Steam::balance($account,null,true);
|
$balance = \Steam::balance($account, null, true);
|
||||||
/** @var PiggyBank $p */
|
/** @var PiggyBank $p */
|
||||||
foreach ($account->piggybanks()->get() as $p) {
|
foreach ($account->piggybanks()->get() as $p) {
|
||||||
$balance -= $p->currentRelevantRep()->currentamount;
|
$balance -= $p->currentRelevantRep()->currentamount;
|
||||||
|
@ -5,6 +5,7 @@ namespace FireflyIII\Repositories\Account;
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@ -86,4 +87,13 @@ interface AccountRepositoryInterface
|
|||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function getSavingsAccounts();
|
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()
|
public function first()
|
||||||
{
|
{
|
||||||
return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
return Auth::user()->transactionjournals()->orderBy('date', 'ASC')->first(['transaction_journals.*']);
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace FireflyIII\Repositories\Journal;
|
namespace FireflyIII\Repositories\Journal;
|
||||||
|
|
||||||
use FireflyIII\Models\TransactionJournal;
|
use FireflyIII\Models\TransactionJournal;
|
||||||
|
use FireflyIII\Models\Transaction;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,6 +94,15 @@ class AccountControllerTest extends TestCase
|
|||||||
$this->be($account->user);
|
$this->be($account->user);
|
||||||
$this->assertCount(1, DB::table('accounts')->where('id', $account->id)->whereNull('deleted_at')->get());
|
$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:
|
||||||
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
|
||||||
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
Amount::shouldReceive('getDefaultCurrency')->once()->andReturn($currency);
|
||||||
|
@ -1,6 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
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(
|
FactoryMuffin::define(
|
||||||
'FireflyIII\Models\Account', [
|
'FireflyIII\Models\Account', [
|
||||||
'user_id' => 'factory|FireflyIII\User',
|
'user_id' => 'factory|FireflyIII\User',
|
||||||
@ -29,10 +55,14 @@ FactoryMuffin::define(
|
|||||||
|
|
||||||
FactoryMuffin::define(
|
FactoryMuffin::define(
|
||||||
'FireflyIII\Models\TransactionCurrency', [
|
'FireflyIII\Models\TransactionCurrency', [
|
||||||
'code' => 'EUR',
|
'code' => function () {
|
||||||
'symbol' => 'x',
|
return RandomString::generateRandomString(3);
|
||||||
'name' => 'word'
|
},
|
||||||
]
|
'symbol' => function () {
|
||||||
|
return RandomString::generateRandomString(1);
|
||||||
|
},
|
||||||
|
'name' => 'word'
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
FactoryMuffin::define(
|
FactoryMuffin::define(
|
||||||
@ -40,4 +70,31 @@ FactoryMuffin::define(
|
|||||||
'email' => 'email',
|
'email' => 'email',
|
||||||
'password' => bcrypt('james'),
|
'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