Updated tests

This commit is contained in:
James Cole
2017-03-05 11:18:34 +01:00
parent 884d6c59a2
commit e5a2e1a8c7
8 changed files with 318 additions and 111 deletions

View File

@@ -13,8 +13,12 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -26,9 +30,13 @@ class BudgetControllerTest extends TestCase
*/
public function testAmount()
{
$data = [
'amount' => 200,
];
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
$data = ['amount' => 200,];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response->assertStatus(200);
@@ -39,6 +47,10 @@ class BudgetControllerTest extends TestCase
*/
public function testCreate()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('budgets.create'));
$response->assertStatus(200);
@@ -51,6 +63,10 @@ class BudgetControllerTest extends TestCase
*/
public function testDelete()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('budgets.delete', [1]));
$response->assertStatus(200);
@@ -63,11 +79,14 @@ class BudgetControllerTest extends TestCase
*/
public function testDestroy()
{
$this->session(['budgets.delete.url' => 'http://localhost']);
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
$this->session(['budgets.delete.url' => 'http://localhost']);
$this->be($this->user());
$response = $this->post(route('budgets.destroy', [1]));
$response->assertStatus(302);
@@ -79,6 +98,10 @@ class BudgetControllerTest extends TestCase
*/
public function testEdit()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('budgets.edit', [1]));
$response->assertStatus(200);
@@ -96,7 +119,13 @@ class BudgetControllerTest extends TestCase
*/
public function testIndex(string $range)
{
$repository = $this->mock(BudgetRepositoryInterface::class);
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('cleanupBudgets');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
@@ -119,10 +148,11 @@ class BudgetControllerTest extends TestCase
*/
public function testNoBudget(string $range)
{
$date = new Carbon();
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -131,6 +161,9 @@ class BudgetControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$date = new Carbon();
$this->session(['start' => $date, 'end' => clone $date]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.no-budget'));
@@ -144,9 +177,13 @@ class BudgetControllerTest extends TestCase
*/
public function testPostUpdateIncome()
{
$data = [
'amount' => '200',
];
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('setAvailableBudget');
$data = ['amount' => '200',];
$this->be($this->user());
$response = $this->post(route('budgets.income.post'), $data);
$response->assertStatus(302);
@@ -161,21 +198,11 @@ class BudgetControllerTest extends TestCase
*/
public function testShow(string $range)
{
$date = new Carbon();
$date->subDay();
$this->session(['first' => $date]);
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
// mock account repository
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
// mock budget repository
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
// mock journal collector:
$collector = $this->mock(JournalCollectorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -184,6 +211,16 @@ class BudgetControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
$repository->shouldReceive('spentInPeriod')->andReturn('1');
$date = new Carbon();
$date->subDay();
$this->session(['first' => $date]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -200,10 +237,15 @@ class BudgetControllerTest extends TestCase
*/
public function testShowByBudgetLimit(string $range)
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
// mock account repository
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
// mock budget repository
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
@@ -233,6 +275,13 @@ class BudgetControllerTest extends TestCase
*/
public function testStore()
{
// mock stuff
$budget = factory(Budget::class)->make();
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('find')->andReturn($budget);
$repository->shouldReceive('store')->andReturn($budget);
$this->session(['budgets.create.url' => 'http://localhost']);
$data = [
@@ -249,6 +298,14 @@ class BudgetControllerTest extends TestCase
*/
public function testUpdate()
{
// mock stuff
$budget = factory(Budget::class)->make();
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('find')->andReturn($budget);
$repository->shouldReceive('update');
$this->session(['budgets.edit.url' => 'http://localhost']);
$data = [
@@ -266,6 +323,12 @@ class BudgetControllerTest extends TestCase
*/
public function testUpdateIncome()
{
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
// must be in list
$this->be($this->user());
$response = $this->get(route('budgets.income', [1]));