mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Fixed tests.
This commit is contained in:
@@ -159,6 +159,7 @@ class CategoryControllerTest extends TestCase
|
||||
|
||||
Amount::shouldReceive('format')->andReturn('xx');
|
||||
Amount::shouldReceive('getCurrencyCode')->andReturn('xx');
|
||||
Amount::shouldReceive('formatJournal')->andReturn('xx');
|
||||
|
||||
$this->call('GET', '/categories/show/' . $category->id);
|
||||
$this->assertResponseOk();
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
if (!class_exists('RandomString')) {
|
||||
@@ -198,10 +200,15 @@ FactoryMuffin::define(
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
FactoryMuffin::define(
|
||||
'FireflyIII\User',
|
||||
[
|
||||
'email' => 'email',
|
||||
'email' => function () {
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
return $faker->email;
|
||||
},
|
||||
'password' => bcrypt('james'),
|
||||
]
|
||||
);
|
||||
@@ -286,5 +293,27 @@ FactoryMuffin::define(
|
||||
'date' => 'date',
|
||||
'encrypted' => '1',
|
||||
'order' => '0',
|
||||
]
|
||||
], function (TransactionJournal $object, $saved) {
|
||||
if ($saved) {
|
||||
$one = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$two = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $one->id,
|
||||
'transaction_journal_id' => $object->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $two->id,
|
||||
'transaction_journal_id' => $object->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
@@ -61,23 +61,6 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
||||
$rep->forceDelete();
|
||||
}
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
// two transactions:
|
||||
|
||||
|
||||
$event = new JournalCreated($journal, $piggyBank->id);
|
||||
$class = new ConnectJournalToPiggyBank();
|
||||
@@ -141,21 +124,6 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
$event = new JournalCreated($journal, $piggyBank->id);
|
||||
$class = new ConnectJournalToPiggyBank();
|
||||
$result = $class->handle($event);
|
||||
@@ -202,21 +170,6 @@ class ConnectJournalToPiggyBankTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
|
||||
$event = new JournalCreated($journal, $piggyBank->id);
|
||||
$class = new ConnectJournalToPiggyBank();
|
||||
$result = $class->handle($event);
|
||||
|
@@ -122,20 +122,6 @@ class ReportHelperTest extends TestCase
|
||||
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $left->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(-100, 100)
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $right->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(-100, 100)
|
||||
]
|
||||
);
|
||||
$journals->push($journal);
|
||||
}
|
||||
|
||||
@@ -257,25 +243,11 @@ class ReportHelperTest extends TestCase
|
||||
$journal->transaction_type_id = $type->id;
|
||||
$journal->user_id = $user->id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $left->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $right->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// test!
|
||||
$object = $this->object->getExpenseReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
|
||||
$this->assertCount(1, $object->getExpenses());
|
||||
$this->assertCount(5, $object->getExpenses());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -322,25 +294,11 @@ class ReportHelperTest extends TestCase
|
||||
$journal->transaction_type_id = $type->id;
|
||||
$journal->user_id = $user->id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $left->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $right->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// test!
|
||||
$object = $this->object->getIncomeReport(Carbon::now()->startOfMonth(), Carbon::now()->endOfMonth(), true);
|
||||
$this->assertCount(1, $object->getIncomes());
|
||||
$this->assertCount(5, $object->getIncomes());
|
||||
|
||||
}
|
||||
|
||||
|
@@ -80,21 +80,15 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = -100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = 100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
@@ -149,21 +143,14 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = -100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = 100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
@@ -271,21 +258,14 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = 100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = -100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
@@ -339,21 +319,14 @@ class ReportQueryTest extends TestCase
|
||||
]
|
||||
);
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100
|
||||
]
|
||||
);
|
||||
// update both transactions
|
||||
$journal->transactions[0]->account_id = $account1->id;
|
||||
$journal->transactions[0]->amount = -100;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal->transactions[1]->account_id = $account2->id;
|
||||
$journal->transactions[1]->amount = 100;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
}
|
||||
$this->be($user);
|
||||
|
@@ -47,13 +47,11 @@ class TransactionJournalModelTest extends TestCase
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 123.45
|
||||
]
|
||||
);
|
||||
$journal->transactions[0]->amount = '123.45';
|
||||
$journal->transactions[0]->save();
|
||||
$journal->transactions[1]->amount = '-123.45';
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
$amount = $journal->actual_amount;
|
||||
$this->assertEquals('123.45', $amount);
|
||||
}
|
||||
@@ -88,13 +86,22 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// for withdrawal, asset to expense account and reversed: //89,88
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
// transactions are already in place, update them:
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -89.88]);
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 89.88]);
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
$deposit->transactions[0]->account_id = $revenue->id;
|
||||
$deposit->transactions[0]->amount = -89.88;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $asset->id;
|
||||
$deposit->transactions[1]->amount = 89.88;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
@@ -138,17 +145,27 @@ class TransactionJournalModelTest extends TestCase
|
||||
|
||||
// make accounts:
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset2 = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset2->account_type_id = $asset->account_type_id;
|
||||
$asset2->save();
|
||||
$revenue->account_type_id = $asset->account_type_id;
|
||||
$revenue->save();
|
||||
|
||||
// make transactions:
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -123.45]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 123.45]);
|
||||
// transactions are already in place, update them:
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -123.45;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
Transaction::create(['account_id' => $asset2->id, 'transaction_journal_id' => $transfer->id, 'amount' => -123.45]);
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $transfer->id, 'amount' => 123.45]);
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->amount = 123.45;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
$transfer->transactions[0]->account_id = $revenue->id;
|
||||
$transfer->transactions[0]->amount = -123.45;
|
||||
$transfer->transactions[0]->save();
|
||||
|
||||
$transfer->transactions[1]->account_id = $asset->id;
|
||||
$transfer->transactions[1]->amount = 123.45;
|
||||
$transfer->transactions[1]->save();
|
||||
|
||||
$amount = $withdrawal->amount;
|
||||
|
||||
@@ -161,15 +178,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
public function testGetAmountAttributeNoTags()
|
||||
{
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 123.45
|
||||
]
|
||||
);
|
||||
$journal->transactions[0]->amount = 123.45;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
$journal->transactions[1]->amount = -123.45;
|
||||
$journal->transactions[1]->save();
|
||||
|
||||
$amount = $journal->amount;
|
||||
$this->assertEquals('123.45', $amount);
|
||||
}
|
||||
@@ -195,8 +210,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
// connect to tag:
|
||||
$tag->transactionJournals()->save($withdrawal);
|
||||
@@ -224,8 +244,15 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
// update transactions
|
||||
$deposit->transactions[0]->account_id = $asset->id;
|
||||
$deposit->transactions[0]->amount = 300;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->asset_account;
|
||||
@@ -240,19 +267,24 @@ class TransactionJournalModelTest extends TestCase
|
||||
{
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// make withdrawal
|
||||
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$deposit->transaction_type_id = $depositType->id;
|
||||
$deposit->save();
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$deposit->transactions[0]->account_id = $asset->id;
|
||||
$deposit->transactions[0]->amount = 300;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->asset_account;
|
||||
@@ -265,18 +297,25 @@ class TransactionJournalModelTest extends TestCase
|
||||
*/
|
||||
public function testGetAssetAccountAttributeWithdrawal()
|
||||
{
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
// make withdrawal
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
|
||||
$withdrawal->transactions[0]->account_id = $asset->id;
|
||||
$withdrawal->transactions[0]->amount = -300;
|
||||
$withdrawal->transactions[0]->save();
|
||||
|
||||
$withdrawal->transactions[1]->account_id = $expense->id;
|
||||
$withdrawal->transactions[1]->amount = 300;
|
||||
$withdrawal->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $withdrawal->asset_account;
|
||||
@@ -284,58 +323,6 @@ class TransactionJournalModelTest extends TestCase
|
||||
$this->assertEquals($asset->id, $result->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectedActualAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectedActualAmountAttributeDeposit()
|
||||
{
|
||||
|
||||
FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$depositType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$deposit = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$deposit->transaction_type_id = $depositType->id;
|
||||
$deposit->save();
|
||||
|
||||
// make accounts
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->corrected_actual_amount;
|
||||
|
||||
$this->assertEquals('300', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getCorrectedActualAmountAttribute
|
||||
*/
|
||||
public function testGetCorrectedActualAmountAttributeWithdrawal()
|
||||
{
|
||||
|
||||
// make withdrawal
|
||||
$withdrawalType = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||
$withdrawal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$withdrawal->transaction_type_id = $withdrawalType->id;
|
||||
$withdrawal->save();
|
||||
|
||||
// make accounts
|
||||
$expense = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $expense->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $withdrawal->id, 'amount' => -300]);
|
||||
|
||||
// get asset account:
|
||||
$result = $withdrawal->corrected_actual_amount;
|
||||
|
||||
$this->assertEquals('-300', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Models\TransactionJournal::getDestinationAccountAttribute
|
||||
*/
|
||||
@@ -352,8 +339,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => 300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
$deposit->transactions[0]->account_id = $asset->id;
|
||||
$deposit->transactions[0]->amount = 300;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->destination_account;
|
||||
@@ -377,8 +369,13 @@ class TransactionJournalModelTest extends TestCase
|
||||
$revenue = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$asset = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
|
||||
Transaction::create(['account_id' => $asset->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
Transaction::create(['account_id' => $revenue->id, 'transaction_journal_id' => $deposit->id, 'amount' => -300]);
|
||||
$deposit->transactions[0]->account_id = $asset->id;
|
||||
$deposit->transactions[0]->amount = -300;
|
||||
$deposit->transactions[0]->save();
|
||||
|
||||
$deposit->transactions[1]->account_id = $revenue->id;
|
||||
$deposit->transactions[1]->amount = -300;
|
||||
$deposit->transactions[1]->save();
|
||||
|
||||
// get asset account:
|
||||
$result = $deposit->destination_account;
|
||||
|
@@ -2,8 +2,6 @@
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountRepository;
|
||||
@@ -117,30 +115,18 @@ class AccountRepositoryTest extends TestCase
|
||||
{
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$first = $journal->transactions()->orderBy('date', 'DESC')->first();
|
||||
$first->account_id = $account->id;
|
||||
$first->save();
|
||||
|
||||
// two matching transactions:
|
||||
$first = Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100,
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => -100,
|
||||
]
|
||||
);
|
||||
|
||||
// login
|
||||
$this->be($account->user);
|
||||
|
||||
$oldest = $this->object->getFirstTransaction($journal, $account);
|
||||
|
||||
$this->assertEquals($oldest->amount, $first->amount);
|
||||
$this->assertEquals($oldest->id, $first->id);
|
||||
$this->assertEquals($first->amount, $oldest->amount);
|
||||
$this->assertEquals($first->id, $oldest->id);
|
||||
|
||||
}
|
||||
|
||||
@@ -215,28 +201,12 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal2->save();
|
||||
$journal3->save();
|
||||
|
||||
// transactions to match the dates (one per journal will do)
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal3->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->save();
|
||||
$journal3->transactions[0]->account_id = $account->id;
|
||||
$journal3->transactions[0]->save();
|
||||
|
||||
// be user
|
||||
$this->be($journal1->user);
|
||||
@@ -277,28 +247,12 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal2->save();
|
||||
$journal3->save();
|
||||
|
||||
// transactions to match the dates (one per journal will do)
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal3->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->save();
|
||||
$journal3->transactions[0]->account_id = $account->id;
|
||||
$journal3->transactions[0]->save();
|
||||
|
||||
// be user
|
||||
$this->be($journal1->user);
|
||||
@@ -329,14 +283,8 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal->user_id = $account->user_id;
|
||||
$journal->save();
|
||||
|
||||
// transaction to match the date (one will do)
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
$journal->transactions[0]->account_id = $account->id;
|
||||
$journal->transactions[0]->save();
|
||||
|
||||
// be user
|
||||
$this->be($journal->user);
|
||||
@@ -478,28 +426,25 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal2->transaction_type_id = $journal1->transaction_type_id;
|
||||
$journal3->transaction_type_id = $journal1->transaction_type_id;
|
||||
|
||||
// three transactions:
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal3->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
// transactions are already present, update them!
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[0]->amount = 100;
|
||||
$journal1->transactions[1]->account_id = $account->id;
|
||||
$journal1->transactions[1]->amount = 100;
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->amount = 100;
|
||||
$journal2->transactions[1]->account_id = $account->id;
|
||||
$journal2->transactions[1]->amount = 100;
|
||||
$journal3->transactions[0]->account_id = $account->id;
|
||||
$journal3->transactions[0]->amount = 100;
|
||||
$journal3->transactions[1]->account_id = $account->id;
|
||||
$journal3->transactions[1]->amount = 100;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
$journal3->transactions[0]->save();
|
||||
$journal3->transactions[1]->save();
|
||||
|
||||
// check date:
|
||||
$start = new Carbon('2014-01-01');
|
||||
@@ -557,21 +502,6 @@ class AccountRepositoryTest extends TestCase
|
||||
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
// two transactions:
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal1->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal2->id,
|
||||
'amount' => 100
|
||||
]
|
||||
);
|
||||
|
||||
// dates
|
||||
$one = new Carbon('2013-01-15');
|
||||
@@ -582,6 +512,18 @@ class AccountRepositoryTest extends TestCase
|
||||
$journal1->user_id = $account->user_id;
|
||||
$journal2->date = $two;
|
||||
$journal2->user_id = $account->user_id;
|
||||
|
||||
// add account things:
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[1]->account_id = $account->id;
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[1]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
|
||||
|
||||
$journal1->save();
|
||||
$journal2->save();
|
||||
|
||||
|
@@ -176,13 +176,8 @@ class BillRepositoryTest extends TestCase
|
||||
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
$journal->user_id = $bill1->user_id;
|
||||
$journal->save();
|
||||
Transaction::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
'amount' => rand(101, 999),
|
||||
]
|
||||
);
|
||||
$journal->transactions[0]->account_id = $account->id;
|
||||
$journal->transactions[0]->save();
|
||||
}
|
||||
$this->be($bill1->user);
|
||||
|
||||
|
@@ -129,7 +129,8 @@ class CategoryRepositoryTest extends TestCase
|
||||
$this->assertCount(10, $set);
|
||||
reset($set);
|
||||
|
||||
$this->assertEquals(0, current($set)['sum']);
|
||||
// every journal has amount 100.
|
||||
$this->assertEquals(100, current($set)['sum']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -180,9 +180,14 @@ class TagRepositoryTest extends TestCase
|
||||
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
|
||||
// transactions for both:
|
||||
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => $journal1->id, 'amount' => 100]);
|
||||
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => $journal2->id, 'amount' => 100]);
|
||||
|
||||
$journal1->transactions[0]->account_id = $account->id;
|
||||
$journal2->transactions[0]->account_id = $account->id;
|
||||
$journal1->transactions[1]->account_id = $account->id;
|
||||
$journal2->transactions[1]->account_id = $account->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
||||
@@ -228,8 +233,14 @@ class TagRepositoryTest extends TestCase
|
||||
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||
|
||||
// transactions for both:
|
||||
Transaction::create(['account_id' => $account1->id, 'transaction_journal_id' => $journal1->id, 'amount' => 100]);
|
||||
Transaction::create(['account_id' => $account2->id, 'transaction_journal_id' => $journal2->id, 'amount' => 100]);
|
||||
$journal1->transactions[0]->account_id = $account1->id;
|
||||
$journal2->transactions[0]->account_id = $account2->id;
|
||||
$journal1->transactions[1]->account_id = $account1->id;
|
||||
$journal2->transactions[1]->account_id = $account2->id;
|
||||
$journal1->transactions[0]->save();
|
||||
$journal2->transactions[0]->save();
|
||||
$journal1->transactions[1]->save();
|
||||
$journal2->transactions[1]->save();
|
||||
|
||||
|
||||
$tag = FactoryMuffin::create('FireflyIII\Models\Tag');
|
||||
|
Reference in New Issue
Block a user