diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php
index cb5e138c15..bb6f0fe79e 100644
--- a/app/Http/Controllers/Transaction/SplitController.php
+++ b/app/Http/Controllers/Transaction/SplitController.php
@@ -143,9 +143,6 @@ class SplitController extends Controller
}
$data = $request->getAll();
$journal = $this->repository->update($journal, $data);
- var_dump($request->all());
- var_dump($data);
- exit;
/** @var array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
@@ -161,7 +158,7 @@ class SplitController extends Controller
// @codeCoverageIgnoreEnd
$type = strtolower($this->repository->getTransactionType($journal));
- Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $data['journal_description']])));
+ Session::flash('success', strval(trans('firefly.updated_' . $type, ['description' => $data['description']])));
Preferences::mark();
// @codeCoverageIgnoreStart
diff --git a/app/Http/Requests/SplitJournalFormRequest.php b/app/Http/Requests/SplitJournalFormRequest.php
index 80f9004bdf..a15a9ac203 100644
--- a/app/Http/Requests/SplitJournalFormRequest.php
+++ b/app/Http/Requests/SplitJournalFormRequest.php
@@ -84,7 +84,7 @@ class SplitJournalFormRequest extends Request
'destination_id' => $destinationId,
'destination_name' => $destinationName,
'foreign_amount' => $foreignAmount,
- 'foreign_currency_id' => $foreignCurrency,
+ 'foreign_currency_id' => null,
'foreign_currency_code' => null,
'reconciled' => false,
'identifier' => $index,
diff --git a/tests/Feature/Controllers/Transaction/SingleControllerTest.php b/tests/Feature/Controllers/Transaction/SingleControllerTest.php
index f9f357c3f5..703d891eb2 100644
--- a/tests/Feature/Controllers/Transaction/SingleControllerTest.php
+++ b/tests/Feature/Controllers/Transaction/SingleControllerTest.php
@@ -129,19 +129,26 @@ class SingleControllerTest extends TestCase
*/
public function testEdit()
{
+ $account = $this->user()->accounts()->first();
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
- $note = new Note();
- $note->id = 5;
- $note->text = 'I see you...';
- $repository = $this->mock(JournalRepositoryInterface::class);
- $repository->shouldReceive('getNote')->andReturn($note)->once();
- $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('countTransactions')->andReturn(2);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $journalRepos->shouldReceive('countTransactions')->andReturn(2)->once();
+ $journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal')->once();
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some Note')->once();
+ $journalRepos->shouldReceive('getFirstPosTransaction')->andReturn(new Transaction)->once();
+ $journalRepos->shouldReceive('getJournalDate')->withAnyArgs()->andReturn('2017-09-01');
+ $journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturn('')->once();
+ $journalRepos->shouldReceive('getJournalCategoryName')->once()->andReturn('');
+ $journalRepos->shouldReceive('getJournalBudgetId')->once()->andReturn(0);
+ $journalRepos->shouldReceive('getTags')->once()->andReturn([]);
$this->be($this->user());
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
@@ -163,14 +170,33 @@ class SingleControllerTest extends TestCase
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
+ $account = $this->user()->accounts()->first();
+ $cash = $this->user()->accounts()->where('account_type_id', 2)->first();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+
+ $journalRepos->shouldReceive('countTransactions')->andReturn(2)->once();
+ $journalRepos->shouldReceive('getTransactionType')->andReturn('Deposit')->once();
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$cash]))->once();
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some Note')->once();
+ $journalRepos->shouldReceive('getFirstPosTransaction')->andReturn(new Transaction)->once();
+ $journalRepos->shouldReceive('getJournalDate')->withAnyArgs()->andReturn('2017-09-01');
+ $journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturn('')->once();
+ $journalRepos->shouldReceive('getJournalCategoryName')->once()->andReturn('');
+ $journalRepos->shouldReceive('getJournalBudgetId')->once()->andReturn(0);
+ $journalRepos->shouldReceive('getTags')->once()->andReturn([]);
+
$this->be($this->user());
- $withdrawal = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
- ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
- ->where('accounts.account_type_id', 2)
- ->where('transaction_journals.transaction_type_id', 2)
- ->whereNull('transaction_journals.deleted_at')
- ->where('transaction_journals.user_id', $this->user()->id)->first(['transactions.transaction_journal_id']);
- $response = $this->get(route('transactions.edit', [$withdrawal->transaction_journal_id]));
+ $deposit = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
+ ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
+ ->where('accounts.account_type_id', 2)
+ ->where('transaction_journals.transaction_type_id', 2)
+ ->whereNull('transaction_journals.deleted_at')
+ ->where('transaction_journals.user_id', $this->user()->id)->first(['transactions.*']);
+
+ $journalRepos->shouldReceive('first')->once()->andReturn($deposit->transactionJournal);
+
+ $response = $this->get(route('transactions.edit', [$deposit->transaction_journal_id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('
');
@@ -189,14 +215,33 @@ class SingleControllerTest extends TestCase
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
+ $account = $this->user()->accounts()->first();
+ $cash = $this->user()->accounts()->where('account_type_id', 2)->first();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+
+ $journalRepos->shouldReceive('countTransactions')->andReturn(2)->once();
+ $journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal')->once();
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$cash]))->once();
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some Note')->once();
+ $journalRepos->shouldReceive('getFirstPosTransaction')->andReturn(new Transaction)->once();
+ $journalRepos->shouldReceive('getJournalDate')->withAnyArgs()->andReturn('2017-09-01');
+ $journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturn('')->once();
+ $journalRepos->shouldReceive('getJournalCategoryName')->once()->andReturn('');
+ $journalRepos->shouldReceive('getJournalBudgetId')->once()->andReturn(0);
+ $journalRepos->shouldReceive('getTags')->once()->andReturn([]);
+
$this->be($this->user());
$withdrawal = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('accounts.account_type_id', 2)
->where('transaction_journals.transaction_type_id', 1)
->whereNull('transaction_journals.deleted_at')
- ->where('transaction_journals.user_id', $this->user()->id)->first(['transactions.transaction_journal_id']);
- $response = $this->get(route('transactions.edit', [$withdrawal->transaction_journal_id]));
+ ->where('transaction_journals.user_id', $this->user()->id)->first(['transactions.*']);
+ $journalRepos->shouldReceive('first')->once()->andReturn($withdrawal->transactionJournal);
+
+ $response = $this->get(route('transactions.edit', [$withdrawal->transaction_journal_id]));
+
$response->assertStatus(200);
// has bread crumb
$response->assertSee('');
@@ -209,14 +254,20 @@ class SingleControllerTest extends TestCase
*/
public function testEditReconcile()
{
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $repository->shouldReceive('getTransactionType')->andReturn('Reconciliation')->once();
+
$this->be($this->user());
- $withdrawal = TransactionJournal::where('transaction_type_id', 5)
- ->whereNull('transaction_journals.deleted_at')
- ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
- ->groupBy('transaction_journals.id')
- ->orderBy('ct', 'DESC')
- ->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
- $response = $this->get(route('transactions.edit', [$withdrawal->id]));
+ $reconcile = TransactionJournal::where('transaction_type_id', 5)
+ ->whereNull('transaction_journals.deleted_at')
+ ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
+ ->groupBy('transaction_journals.id')
+ ->orderBy('ct', 'DESC')
+ ->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
+
+ $repository->shouldReceive('first')->once()->andReturn($reconcile);
+
+ $response = $this->get(route('transactions.edit', [$reconcile->id]));
$response->assertStatus(302);
}
@@ -226,6 +277,8 @@ class SingleControllerTest extends TestCase
*/
public function testEditRedirect()
{
+ $repository = $this->mock(JournalRepositoryInterface::class);
+
$this->be($this->user());
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
->whereNull('transaction_journals.deleted_at')
@@ -233,7 +286,12 @@ class SingleControllerTest extends TestCase
->groupBy('transaction_journals.id')
->orderBy('ct', 'DESC')
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
- $response = $this->get(route('transactions.edit', [$withdrawal->id]));
+ $repository->shouldReceive('first')->once()->andReturn($withdrawal);
+ $repository->shouldReceive('getTransactionType')->andReturn('Withdrawal');
+ $repository->shouldReceive('countTransactions')->andReturn(3);
+ $response = $this->get(route('transactions.edit', [$withdrawal->id]));
+
+
$response->assertStatus(302);
}
@@ -260,7 +318,23 @@ class SingleControllerTest extends TestCase
->where('user_id', $this->user()->id)
->whereNotNull('transactions.foreign_amount')
->first(['transaction_journals.*']);
- $response = $this->get(route('transactions.edit', [$withdrawal->id]));
+
+ $account = $this->user()->accounts()->first();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn($withdrawal);
+ $journalRepos->shouldReceive('countTransactions')->andReturn(2)->once();
+ $journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer')->once();
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some Note')->once();
+ $journalRepos->shouldReceive('getFirstPosTransaction')->andReturn(new Transaction)->once();
+ $journalRepos->shouldReceive('getJournalDate')->withAnyArgs()->andReturn('2017-09-01');
+ $journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturn('')->once();
+ $journalRepos->shouldReceive('getJournalCategoryName')->once()->andReturn('');
+ $journalRepos->shouldReceive('getJournalBudgetId')->once()->andReturn(0);
+ $journalRepos->shouldReceive('getTags')->once()->andReturn([]);
+
+ $response = $this->get(route('transactions.edit', [$withdrawal->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('');
@@ -289,7 +363,24 @@ class SingleControllerTest extends TestCase
->where('user_id', $this->user()->id)
->whereNotNull('transactions.foreign_amount')
->first(['transaction_journals.*']);
- $response = $this->get(route('transactions.edit', [$withdrawal->id]));
+
+ $account = $this->user()->accounts()->first();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn($withdrawal);
+ $journalRepos->shouldReceive('countTransactions')->andReturn(2)->once();
+ $journalRepos->shouldReceive('getTransactionType')->andReturn('Withdrawal')->once();
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->once();
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some Note')->once();
+ $journalRepos->shouldReceive('getFirstPosTransaction')->andReturn(new Transaction)->once();
+ $journalRepos->shouldReceive('getJournalDate')->withAnyArgs()->andReturn('2017-09-01');
+ $journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturn('')->once();
+ $journalRepos->shouldReceive('getJournalCategoryName')->once()->andReturn('');
+ $journalRepos->shouldReceive('getJournalBudgetId')->once()->andReturn(0);
+ $journalRepos->shouldReceive('getTags')->once()->andReturn([]);
+
+
+ $response = $this->get(route('transactions.edit', [$withdrawal->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('');
diff --git a/tests/Feature/Controllers/Transaction/SplitControllerTest.php b/tests/Feature/Controllers/Transaction/SplitControllerTest.php
index b66b932c3e..98eb4be79d 100644
--- a/tests/Feature/Controllers/Transaction/SplitControllerTest.php
+++ b/tests/Feature/Controllers/Transaction/SplitControllerTest.php
@@ -58,11 +58,23 @@ class SplitControllerTest extends TestCase
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$transactions = factory(Transaction::class, 3)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn($deposit);
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
+ $journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
+ $journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
+ $journalRepos->shouldReceive('getMetaField')->andReturn('');
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
+ $journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
+ $journalRepos->shouldReceive('getCategoryName')->andReturn('');
+
+
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
->andReturn(new Collection([$account]))->once();
@@ -88,6 +100,7 @@ class SplitControllerTest extends TestCase
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
@@ -100,6 +113,17 @@ class SplitControllerTest extends TestCase
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$tasker->shouldReceive('getTransactionsOverview')->andReturn($transactions->toArray());
+ $journalRepos->shouldReceive('first')->once()->andReturn($deposit);
+ $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
+ $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
+ $journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
+ $journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
+ $journalRepos->shouldReceive('getMetaField')->andReturn('');
+ $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
+ $journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
+ $journalRepos->shouldReceive('getCategoryName')->andReturn('');
+
+
$old = [
'transactions' => [
[
@@ -165,7 +189,10 @@ class SplitControllerTest extends TestCase
*/
public function testEditOpeningBalance()
{
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
+ $journalRepos->shouldReceive('first')->once()->andReturn($opening);
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$opening->id]));
$response->assertStatus(302);
@@ -184,17 +211,21 @@ class SplitControllerTest extends TestCase
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
- $note = new Note();
- $note->id = 1;
- $note->text = 'Hallo';
$transactions = factory(Transaction::class, 1)->make();
$tasker = $this->mock(JournalTaskerInterface::class);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
- $repository->shouldReceive('getNote')->andReturn($note);
- $repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('first')->once()->andReturn($deposit);
+ $repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
+ $repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
+ $repository->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
+ $repository->shouldReceive('getJournalDate')->once()->andReturn('2018-01-01');
+ $repository->shouldReceive('getMetaField')->andReturn('');
+ $repository->shouldReceive('getNoteText')->andReturn('Some note')->once();
+ $repository->shouldReceive('getJournalBudgetId')->andReturn(0);
+ $repository->shouldReceive('getCategoryName')->andReturn('');
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
@@ -240,8 +271,9 @@ class SplitControllerTest extends TestCase
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
- $repository->shouldReceive('updateSplitJournal')->andReturn($deposit);
- $repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
+ $repository->shouldReceive('update')->andReturn($deposit);
+ $repository->shouldReceive('first')->andReturn($deposit);
+ $repository->shouldReceive('getTransactionType')->andReturn('Deposit');
$attachmentRepos = $this->mock(AttachmentHelperInterface::class);
$attachmentRepos->shouldReceive('saveAttachmentsForModel');
@@ -252,13 +284,6 @@ class SplitControllerTest extends TestCase
$response->assertStatus(302);
$response->assertRedirect(route('index'));
$response->assertSessionHas('success');
-
- // journal is updated?
- $response = $this->get(route('transactions.show', [$deposit->id]));
- $response->assertStatus(200);
- $response->assertSee('Updated salary');
- // has bread crumb
- $response->assertSee('');
}
/**
@@ -267,11 +292,12 @@ class SplitControllerTest extends TestCase
*/
public function testUpdateOpeningBalance()
{
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$this->session(['transactions.edit-split.uri' => 'http://localhost']);
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
$data = [
'id' => $opening->id,
- 'what' => 'deposit',
+ 'what' => 'opening balance',
'journal_description' => 'Updated salary',
'journal_currency_id' => 1,
'journal_destination_account_id' => 1,
@@ -288,6 +314,18 @@ class SplitControllerTest extends TestCase
],
],
];
+
+ $journalRepos->shouldReceive('first')->once()->andReturn($opening);
+// $journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
+// $journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
+ //$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Opening balance');
+// $journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
+// $journalRepos->shouldReceive('getMetaField')->andReturn('');
+// $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->once();
+// $journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
+// $journalRepos->shouldReceive('getCategoryName')->andReturn('');
+
+
$this->be($this->user());
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
$response->assertStatus(302);