|
|
|
|
@@ -29,6 +29,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
|
|
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
|
|
|
|
use Laravel\Passport\Passport;
|
|
|
|
|
use Log;
|
|
|
|
|
use Mockery;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -43,7 +44,7 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
Passport::actingAs($this->user());
|
|
|
|
|
Log::debug('Now in Api/AccountControllerTest.');
|
|
|
|
|
Log::debug(sprintf('Now in %s.', get_class($this)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -85,9 +86,14 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
|
|
|
|
|
|
|
|
|
// mock calls:
|
|
|
|
|
$repository->shouldReceive('setUser')->once();
|
|
|
|
|
$repository->shouldReceive('setUser');
|
|
|
|
|
$repository->shouldReceive('getAccountsByType')->withAnyArgs()->andReturn($accounts)->once();
|
|
|
|
|
$currencyRepos->shouldReceive('setUser')->once();
|
|
|
|
|
$currencyRepos->shouldReceive('setUser');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
|
|
|
|
$repository->shouldReceive('getNoteText')->withArgs([Mockery::any()])->andReturn('Hello');
|
|
|
|
|
|
|
|
|
|
// test API
|
|
|
|
|
$response = $this->get('/api/v1/accounts');
|
|
|
|
|
@@ -244,6 +250,12 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
$currencyRepos->shouldReceive('setUser')->once();
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceAmount')->andReturn('10')->once();
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01')->once();
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
|
|
|
|
$repository->shouldReceive('getNoteText')->withArgs([Mockery::any()])->andReturn('Hello');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// test API
|
|
|
|
|
$response = $this->get('/api/v1/accounts/' . $account->id);
|
|
|
|
|
@@ -316,6 +328,12 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01');
|
|
|
|
|
$currencyRepos->shouldReceive('setUser')->once();
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
|
|
|
|
$repository->shouldReceive('getNoteText')->withArgs([Mockery::any()])->andReturn('Hello');
|
|
|
|
|
|
|
|
|
|
// data to submit
|
|
|
|
|
$data = [
|
|
|
|
|
'name' => 'Some new asset account #' . rand(1, 10000),
|
|
|
|
|
@@ -356,6 +374,12 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01');
|
|
|
|
|
$currencyRepos->shouldReceive('findByCodeNull')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
|
|
|
|
$repository->shouldReceive('getNoteText')->withArgs([Mockery::any()])->andReturn('Hello');
|
|
|
|
|
|
|
|
|
|
// functions to expect:
|
|
|
|
|
|
|
|
|
|
// data to submit
|
|
|
|
|
@@ -394,6 +418,12 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceAmount')->andReturn('10');
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01');
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
|
|
|
|
$repository->shouldReceive('getNoteText')->withArgs([Mockery::any()])->andReturn('Hello');
|
|
|
|
|
|
|
|
|
|
$account = $this->user()->accounts()->first();
|
|
|
|
|
// data to submit
|
|
|
|
|
$data = [
|
|
|
|
|
@@ -432,6 +462,12 @@ class AccountControllerTest extends TestCase
|
|
|
|
|
$repository->shouldReceive('getOpeningBalanceDate')->andReturn('2018-01-01');
|
|
|
|
|
$currencyRepos->shouldReceive('findByCodeNull')->andReturn(TransactionCurrency::find(1));
|
|
|
|
|
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1');
|
|
|
|
|
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC');
|
|
|
|
|
$repository->shouldReceive('getNoteText')->withArgs([Mockery::any()])->andReturn('Hello');
|
|
|
|
|
|
|
|
|
|
$account = $this->user()->accounts()->first();
|
|
|
|
|
// data to submit
|
|
|
|
|
$data = [
|
|
|
|
|
|