mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-21 11:48:53 +00:00
Refactored a lot of tests.
This commit is contained in:
@@ -23,14 +23,14 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
use Amount;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -57,15 +57,18 @@ class JavascriptControllerTest extends TestCase
|
||||
*/
|
||||
public function testAccounts(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$account = factory(Account::class)->make();
|
||||
$account = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$pref = new Preference;
|
||||
$pref->data = 'EUR';
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))
|
||||
->withArgs(
|
||||
[[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]]
|
||||
)->once();
|
||||
$currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(new TransactionCurrency);
|
||||
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
|
||||
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))->withArgs([[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]])->once();
|
||||
$currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn($euro);
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -78,10 +81,10 @@ class JavascriptControllerTest extends TestCase
|
||||
*/
|
||||
public function testCurrencies(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$currency = factory(TransactionCurrency::class)->make();
|
||||
$repository->shouldReceive('get')->andReturn(new Collection([$currency]));
|
||||
|
||||
$euro = $this->getEuro();
|
||||
$repository->shouldReceive('get')->andReturn(new Collection([$euro]));
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('javascript.currencies'));
|
||||
@@ -98,11 +101,17 @@ class JavascriptControllerTest extends TestCase
|
||||
*/
|
||||
public function testVariables(string $range): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$account = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
|
||||
$accountRepos->shouldReceive('findNull')->andReturn($account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn($euro);
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
Amount::shouldReceive('getJsConfig')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('javascript.variables'));
|
||||
@@ -118,11 +127,16 @@ class JavascriptControllerTest extends TestCase
|
||||
*/
|
||||
public function testVariablesCustom(string $range): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$account = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
|
||||
|
||||
$accountRepos->shouldReceive('findNull')->andReturn($account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn($euro);
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
Amount::shouldReceive('getJsConfig')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -140,12 +154,15 @@ class JavascriptControllerTest extends TestCase
|
||||
*/
|
||||
public function testVariablesNull(string $range): void
|
||||
{
|
||||
Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1))->times(2);
|
||||
$this->mockDefaultSession();
|
||||
$account = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
//Amount::shouldReceive('getDefaultCurrency')->andReturn($euro)->times(2);
|
||||
Amount::shouldReceive('getJsConfig')->andReturn([])->once();
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('findNull')->andReturn(new Account);
|
||||
$accountRepos->shouldReceive('findNull')->andReturn($account);
|
||||
$currencyRepos->shouldReceive('findNull')->andReturn(null);
|
||||
|
||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
Reference in New Issue
Block a user