mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 12:11:19 +00:00
Improved implementation of liability accounts and the option to add or remove accounts from the net-worth calculations.
This commit is contained in:
@@ -199,7 +199,6 @@ class AttachmentControllerTest extends TestCase
|
||||
// test API
|
||||
$response = $this->get('/api/v1/attachments/' . $attachment->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
|
||||
$response->assertSee($attachment->filename); // attachment file name
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
@@ -70,6 +70,7 @@ class EditControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
|
||||
@@ -113,6 +114,7 @@ class EditControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn('');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly');
|
||||
|
@@ -50,7 +50,7 @@ class ReportControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
|
||||
Steam::shouldReceive('balancesByAccounts')->andReturn(['5', '10']);
|
||||
$generator->shouldReceive('singleSet')->andReturn([]);
|
||||
$generator->shouldReceive('multiSet')->andReturn([]);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.report.net-worth', [1, '20120101', '20120131']));
|
||||
|
@@ -24,6 +24,7 @@ namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
@@ -155,12 +156,26 @@ class BoxControllerTest extends TestCase
|
||||
*/
|
||||
public function testNetWorth(): void
|
||||
{
|
||||
$result = [
|
||||
[
|
||||
'currency' => TransactionCurrency::find(1),
|
||||
'balance' => '3',
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$netWorthHelper = $this->mock(NetWorthInterface::class);
|
||||
$netWorthHelper->shouldReceive('setUser')->once();
|
||||
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
@@ -172,12 +187,25 @@ class BoxControllerTest extends TestCase
|
||||
*/
|
||||
public function testNetWorthFuture(): void
|
||||
{
|
||||
$result = [
|
||||
[
|
||||
'currency' => TransactionCurrency::find(1),
|
||||
'balance' => '3',
|
||||
],
|
||||
];
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$netWorthHelper = $this->mock(NetWorthInterface::class);
|
||||
$netWorthHelper->shouldReceive('setUser')->once();
|
||||
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
|
||||
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
|
||||
|
||||
$start = new Carbon;
|
||||
$start->addMonths(6)->startOfMonth();
|
||||
@@ -194,12 +222,25 @@ class BoxControllerTest extends TestCase
|
||||
*/
|
||||
public function testNetWorthNoCurrency(): void
|
||||
{
|
||||
$result = [
|
||||
[
|
||||
'currency' => TransactionCurrency::find(1),
|
||||
'balance' => '3',
|
||||
],
|
||||
];
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$netWorthHelper = $this->mock(NetWorthInterface::class);
|
||||
$netWorthHelper->shouldReceive('setUser')->once();
|
||||
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
|
||||
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(null);
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
@@ -211,14 +252,27 @@ class BoxControllerTest extends TestCase
|
||||
*/
|
||||
public function testNetWorthVirtual(): void
|
||||
{
|
||||
$result = [
|
||||
[
|
||||
'currency' => TransactionCurrency::find(1),
|
||||
'balance' => '3',
|
||||
],
|
||||
];
|
||||
|
||||
$account = $this->user()->accounts()->first();
|
||||
$account->virtual_balance = '1000';
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$netWorthHelper = $this->mock(NetWorthInterface::class);
|
||||
$netWorthHelper->shouldReceive('setUser')->once();
|
||||
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
|
||||
|
||||
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account]));
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset');
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.net-worth'));
|
||||
|
@@ -249,7 +249,7 @@ class SingleControllerTest extends TestCase
|
||||
// mock new account list:
|
||||
$currency = TransactionCurrency::first();
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn(new Collection([$account]))->once();
|
||||
->withArgs([[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]])->andReturn(new Collection([$account]))->once();
|
||||
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency)->times(6);
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -1037,7 +1037,7 @@ class TransactionFactoryTest extends TestCase
|
||||
try {
|
||||
$factory->createPair($withdrawal, $data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertEquals('At least one of the accounts must be an asset account.', $e->getMessage());
|
||||
$this->assertEquals('At least one of the accounts must be an asset account (Expense account, Revenue account).', $e->getMessage());
|
||||
}
|
||||
|
||||
$newCount = $withdrawal->transactions()->count();
|
||||
|
@@ -28,8 +28,8 @@ use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Tests\TestCase;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AttachmentHelperTest
|
||||
@@ -114,15 +114,31 @@ class AttachmentHelperTest extends TestCase
|
||||
public function testSaveAttachmentFromApi(): void
|
||||
{
|
||||
// mock calls:
|
||||
Crypt::shouldReceive('encrypt')->times(2)->andReturn('Some encrypted content');
|
||||
Crypt::shouldReceive('encrypt')->times(6)->andReturn('Some encrypted content');
|
||||
Storage::fake('upload');
|
||||
|
||||
$path = public_path('apple-touch-icon.png');
|
||||
$helper = new AttachmentHelper;
|
||||
$attachment = Attachment::first();
|
||||
$path = public_path('apple-touch-icon.png');
|
||||
$helper = new AttachmentHelper;
|
||||
|
||||
// make new attachment:
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'attachable_id' => $journal->id,
|
||||
'user_id' => $this->user()->id,
|
||||
'attachable_type' => TransactionJournal::class,
|
||||
'md5' => md5('Hello' . random_int(1, 10000)),
|
||||
'filename' => 'file.txt',
|
||||
'title' => 'Some title',
|
||||
'description' => 'Some descr',
|
||||
'mime' => 'text/plain',
|
||||
'size' => 30,
|
||||
'uploaded' => true,
|
||||
]
|
||||
);
|
||||
|
||||
// call helper
|
||||
$result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));
|
||||
$result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
@@ -138,10 +154,26 @@ class AttachmentHelperTest extends TestCase
|
||||
|
||||
$path = public_path('browserconfig.xml');
|
||||
$helper = new AttachmentHelper;
|
||||
$attachment = Attachment::first();
|
||||
|
||||
// make new attachment:
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->first();
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'attachable_id' => $journal->id,
|
||||
'user_id' => $this->user()->id,
|
||||
'attachable_type' => TransactionJournal::class,
|
||||
'md5' => md5('Hello' . random_int(1, 10000)),
|
||||
'filename' => 'file.txt',
|
||||
'title' => 'Some title',
|
||||
'description' => 'Some descr',
|
||||
'mime' => 'text/plain',
|
||||
'size' => 30,
|
||||
'uploaded' => true,
|
||||
]
|
||||
);
|
||||
|
||||
// call helper
|
||||
$result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));
|
||||
$result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));
|
||||
|
||||
$this->assertFalse($result);
|
||||
|
||||
|
Reference in New Issue
Block a user