mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve test coverage.
This commit is contained in:
@@ -126,6 +126,86 @@ class BudgetControllerTest extends TestCase
|
|||||||
$response->assertSee('<ol class="breadcrumb">');
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
||||||
|
* @covers \FireflyIII\Http\Controllers\BudgetController::collectBudgetInformation
|
||||||
|
* @covers \FireflyIII\Http\Controllers\BudgetController::__construct
|
||||||
|
* @dataProvider dateRangeProvider
|
||||||
|
*
|
||||||
|
* @param string $range
|
||||||
|
*/
|
||||||
|
public function testIndexWithDate(string $range)
|
||||||
|
{
|
||||||
|
// mock stuff
|
||||||
|
$budget = factory(Budget::class)->make();
|
||||||
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||||
|
|
||||||
|
// set budget limit to current month:
|
||||||
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||||
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||||
|
|
||||||
|
$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([$budget]));
|
||||||
|
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||||
|
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||||
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$this->changeDateRange($this->user(), $range);
|
||||||
|
$response = $this->get(route('budgets.index', ['2017-01-01']));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// has bread crumb
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
||||||
|
* @covers \FireflyIII\Http\Controllers\BudgetController::collectBudgetInformation
|
||||||
|
* @covers \FireflyIII\Http\Controllers\BudgetController::__construct
|
||||||
|
* @dataProvider dateRangeProvider
|
||||||
|
*
|
||||||
|
* @param string $range
|
||||||
|
*/
|
||||||
|
public function testIndexWithInvalidDate(string $range)
|
||||||
|
{
|
||||||
|
// mock stuff
|
||||||
|
$budget = factory(Budget::class)->make();
|
||||||
|
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||||
|
|
||||||
|
// set budget limit to current month:
|
||||||
|
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||||
|
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||||
|
|
||||||
|
$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([$budget]));
|
||||||
|
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||||
|
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||||
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||||
|
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$this->changeDateRange($this->user(), $range);
|
||||||
|
$response = $this->get(route('budgets.index', ['Hello-there']));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// has bread crumb
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
* @covers \FireflyIII\Http\Controllers\BudgetController::index
|
||||||
* @covers \FireflyIII\Http\Controllers\BudgetController::collectBudgetInformation
|
* @covers \FireflyIII\Http\Controllers\BudgetController::collectBudgetInformation
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types = 1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Tests\Feature\Controllers\Transaction;
|
namespace Tests\Feature\Controllers\Transaction;
|
||||||
|
|
||||||
@@ -209,6 +209,29 @@ class ConvertControllerTest extends TestCase
|
|||||||
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||||
|
*/
|
||||||
|
public function testPostIndexDepositWithdrawalEmptyName()
|
||||||
|
{
|
||||||
|
// mock stuff
|
||||||
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||||
|
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('getCashAccount')->andReturn(new Account)->once();
|
||||||
|
|
||||||
|
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
||||||
|
$data = ['destination_account_expense' => '',];
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('transactions.convert.index', ['withdrawal', $deposit->id]), $data);
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertRedirect(route('transactions.show', [$deposit->id]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||||
@@ -296,7 +319,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$accountRepos->shouldReceive('store')->andReturn(new Account);
|
$accountRepos->shouldReceive('store')->andReturn(new Account)->once();
|
||||||
|
|
||||||
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
|
$transfer = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->first();
|
||||||
$data = ['source_account_revenue' => 'New rev'];
|
$data = ['source_account_revenue' => 'New rev'];
|
||||||
@@ -319,7 +342,7 @@ class ConvertControllerTest extends TestCase
|
|||||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
$accountRepos->shouldReceive('store')->andReturn(new Account);
|
$accountRepos->shouldReceive('store')->andReturn(new Account)->once();
|
||||||
|
|
||||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
||||||
$data = ['source_account_revenue' => 'New revenue name.',];
|
$data = ['source_account_revenue' => 'New revenue name.',];
|
||||||
@@ -329,6 +352,29 @@ class ConvertControllerTest extends TestCase
|
|||||||
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getDestinationAccount
|
||||||
|
*/
|
||||||
|
public function testPostIndexWithdrawalDepositEmptyName()
|
||||||
|
{
|
||||||
|
// mock stuff
|
||||||
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('convert')->andReturn(new MessageBag);
|
||||||
|
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||||
|
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('getCashAccount')->andReturn(new Account)->once();
|
||||||
|
|
||||||
|
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->where('user_id', $this->user()->id)->first();
|
||||||
|
$data = ['source_account_revenue' => '',];
|
||||||
|
$this->be($this->user());
|
||||||
|
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
|
||||||
|
$response->assertStatus(302);
|
||||||
|
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::postIndex
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController::getSourceAccount
|
||||||
|
@@ -122,10 +122,13 @@ class MassControllerTest extends TestCase
|
|||||||
->orderBy('ct', 'DESC')
|
->orderBy('ct', 'DESC')
|
||||||
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')])
|
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')])
|
||||||
);
|
);
|
||||||
$allIds = $collection->pluck('id')->toArray();
|
|
||||||
|
|
||||||
|
// add opening balance:
|
||||||
|
$collection->push(TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first());
|
||||||
|
$allIds = $collection->pluck('id')->toArray();
|
||||||
|
$route = route('transactions.mass.edit', join(',', $allIds));
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$response = $this->get(route('transactions.mass.edit', join(',', $allIds)));
|
$response = $this->get($route);
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertSee('Edit a number of transactions');
|
$response->assertSee('Edit a number of transactions');
|
||||||
// has bread crumb
|
// has bread crumb
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
declare(strict_types = 1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Tests\Feature\Controllers\Transaction;
|
namespace Tests\Feature\Controllers\Transaction;
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
|
use Illuminate\Database\Query\JoinClause;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use Steam;
|
use Steam;
|
||||||
@@ -145,7 +146,6 @@ class SingleControllerTest extends TestCase
|
|||||||
$response->assertSee(' name="source_account_name" type="text" value="">');
|
$response->assertSee(' name="source_account_name" type="text" value="">');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||||
*/
|
*/
|
||||||
@@ -187,6 +187,63 @@ class SingleControllerTest extends TestCase
|
|||||||
$response->assertStatus(302);
|
$response->assertStatus(302);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||||
|
*/
|
||||||
|
public function testEditTransferWithForeignAmount()
|
||||||
|
{
|
||||||
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
||||||
|
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$withdrawal = TransactionJournal::where('transaction_type_id', 3)
|
||||||
|
->whereNull('transaction_journals.deleted_at')
|
||||||
|
->leftJoin(
|
||||||
|
'transactions', function (JoinClause $join) {
|
||||||
|
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('amount', '<', 0);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->where('user_id', $this->user()->id)
|
||||||
|
->whereNotNull('transactions.foreign_amount')
|
||||||
|
->first(['transaction_journals.*']);
|
||||||
|
$response = $this->get(route('transactions.edit', [$withdrawal->id]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// has bread crumb
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||||
|
*/
|
||||||
|
public function testEditWithForeignAmount()
|
||||||
|
{
|
||||||
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
||||||
|
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->once();
|
||||||
|
|
||||||
|
$this->be($this->user());
|
||||||
|
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
|
||||||
|
->whereNull('transaction_journals.deleted_at')
|
||||||
|
->leftJoin(
|
||||||
|
'transactions', function (JoinClause $join) {
|
||||||
|
$join->on('transactions.transaction_journal_id', '=', 'transaction_journals.id')->where('amount', '<', 0);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
->where('user_id', $this->user()->id)
|
||||||
|
->whereNotNull('transactions.foreign_amount')
|
||||||
|
->first(['transaction_journals.*']);
|
||||||
|
$response = $this->get(route('transactions.edit', [$withdrawal->id]));
|
||||||
|
$response->assertStatus(200);
|
||||||
|
// has bread crumb
|
||||||
|
$response->assertSee('<ol class="breadcrumb">');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
|
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user