mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update tests.
This commit is contained in:
parent
8fb6c1a0c8
commit
8101f910f0
@ -166,7 +166,7 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::showAll
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
@ -182,7 +182,7 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::showByDate
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
|
@ -12,8 +12,20 @@ declare(strict_types = 1);
|
||||
namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Events\StoredTransactionJournal;
|
||||
use FireflyIII\Events\UpdatedTransactionJournal;
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -24,12 +36,31 @@ use Tests\TestCase;
|
||||
class SingleControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::cloneTransaction
|
||||
*/
|
||||
public function testCloneTransaction()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
|
||||
$response = $this->get(route('transactions.clone', [$withdrawal->id]));
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::create
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::__construct
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('getActiveAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$piggyRepos->shouldReceive('getPiggyBanksWithAmount')->andReturn(new Collection)->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.create', ['withdrawal']));
|
||||
$response->assertStatus(200);
|
||||
@ -43,7 +74,8 @@ class SingleControllerTest extends TestCase
|
||||
public function testDelete()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.delete', [12]));
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
|
||||
$response = $this->get(route('transactions.delete', [$withdrawal->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
@ -60,8 +92,8 @@ class SingleControllerTest extends TestCase
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('delete')->once();
|
||||
|
||||
$response = $this->post(route('transactions.destroy', [13]));
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
|
||||
$response = $this->post(route('transactions.destroy', [$withdrawal->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
@ -71,22 +103,121 @@ class SingleControllerTest extends TestCase
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
$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());
|
||||
$response = $this->get(route('transactions.edit', [13]));
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)->whereNull('deleted_at')->where('user_id', $this->user()->id)->first();
|
||||
$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 testEditCashDeposit()
|
||||
{
|
||||
$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 = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('accounts.account_type_id', 2)
|
||||
->where('transaction_journals.transaction_type_id', 2)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.user_id', $this->user()->id)->first(['transactions.transaction_journal_id']);
|
||||
$response = $this->get(route('transactions.edit', [$withdrawal->transaction_journal_id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee(' name="source_account_name" type="text" value="">');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||
*/
|
||||
public function testEditCashWithdrawal()
|
||||
{
|
||||
$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 = Transaction::leftJoin('accounts', 'transactions.account_id', '=', 'accounts.id')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('accounts.account_type_id', 2)
|
||||
->where('transaction_journals.transaction_type_id', 1)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->where('transaction_journals.user_id', $this->user()->id)->first(['transactions.transaction_journal_id']);
|
||||
$response = $this->get(route('transactions.edit', [$withdrawal->transaction_journal_id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee(' name="destination_account_name" type="text" value="">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
|
||||
*/
|
||||
public function testEditRedirect()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$withdrawal = TransactionJournal::where('transaction_type_id', 1)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->groupBy('transaction_journals.id')
|
||||
->orderBy('ct', 'DESC')
|
||||
->where('user_id', $this->user()->id)->first(['transaction_journals.id', DB::raw('count(transactions.`id`) as ct')]);
|
||||
$response = $this->get(route('transactions.edit', [$withdrawal->id]));
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
|
||||
*/
|
||||
public function testStore()
|
||||
public function testStoreSuccess()
|
||||
{
|
||||
// mock results:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = new TransactionJournal();
|
||||
$journal->id = 1000;
|
||||
$journal->description = 'New journal';
|
||||
$repository->shouldReceive('store')->andReturn($journal);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$this->expectsEvents(StoredTransactionJournal::class);
|
||||
|
||||
$errors = new MessageBag;
|
||||
$errors->add('attachments','Fake error');
|
||||
|
||||
$messages = new MessageBag;
|
||||
$messages->add('attachments','Fake error');
|
||||
|
||||
// mock attachment helper, trigger an error AND and info thing.
|
||||
$attachmentRepo = $this->mock(AttachmentHelperInterface::class);
|
||||
$attachmentRepo->shouldReceive('saveAttachmentsForModel');
|
||||
$attachmentRepo->shouldReceive('getErrors')->andReturn($errors);
|
||||
$attachmentRepo->shouldReceive('getMessages')->andReturn($messages);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->session(['transactions.create.url' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
|
||||
$data = [
|
||||
$data = [
|
||||
'what' => 'withdrawal',
|
||||
'amount' => '10',
|
||||
'amount_currency_id_amount' => 1,
|
||||
@ -98,6 +229,36 @@ class SingleControllerTest extends TestCase
|
||||
$response = $this->post(route('transactions.store', ['withdrawal']), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
$response->assertSessionHas('error');
|
||||
$response->assertSessionHas('info');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
|
||||
*/
|
||||
public function testStoreError()
|
||||
{
|
||||
// mock results:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = new TransactionJournal();
|
||||
$journal->description = 'New journal';
|
||||
$repository->shouldReceive('store')->andReturn($journal);
|
||||
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$this->session(['transactions.create.url' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
|
||||
$data = [
|
||||
'what' => 'withdrawal',
|
||||
'amount' => '10',
|
||||
'amount_currency_id_amount' => 1,
|
||||
'source_account_id' => 1,
|
||||
'destination_account_name' => 'Some destination',
|
||||
'date' => '2016-01-01',
|
||||
'description' => 'Test descr',
|
||||
];
|
||||
$response = $this->post(route('transactions.store', ['withdrawal']), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,6 +266,21 @@ class SingleControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// mock
|
||||
$this->expectsEvents(UpdatedTransactionJournal::class);
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$journal = new TransactionJournal();
|
||||
|
||||
$type = TransactionType::find(1);
|
||||
$journal->id = 1000;
|
||||
$journal->description = 'New journal';
|
||||
$journal->transactionType()->associate($type);
|
||||
|
||||
|
||||
$repository->shouldReceive('update')->andReturn($journal);
|
||||
$repository->shouldReceive('first')->times(2)->andReturn(new TransactionJournal);
|
||||
|
||||
$this->session(['transactions.edit.url' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
|
@ -12,7 +12,12 @@ declare(strict_types = 1);
|
||||
namespace Tests\Feature\Controllers\Transaction;
|
||||
|
||||
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@ -25,10 +30,22 @@ class SplitControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::__construct
|
||||
* Implement testEdit().
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromJournal
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromJournal
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
$accountRepository->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])
|
||||
->andReturn(new Collection)->once();
|
||||
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
|
||||
|
||||
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.split.edit', [$deposit->id]));
|
||||
@ -37,9 +54,21 @@ class SplitControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::edit
|
||||
*/
|
||||
public function testEditOpeningBalance()
|
||||
{
|
||||
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('transactions.split.edit', [$opening->id]));
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
|
||||
* Implement testUpdate().
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::arrayFromInput
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::getTransactionDataFromRequest
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
@ -76,4 +105,20 @@ class SplitControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController::update
|
||||
*/
|
||||
public function testUpdateOpeningBalance()
|
||||
{
|
||||
$this->session(['transactions.edit-split.url' => 'http://localhost']);
|
||||
$opening = TransactionJournal::where('transaction_type_id', 4)->where('user_id', $this->user()->id)->first();
|
||||
$data = [
|
||||
'id' => $opening->id,
|
||||
];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('transactions.split.update', [$opening->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionMissing('success');
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user