Expand tests, do code cleanup.

This commit is contained in:
James Cole
2017-12-17 14:30:53 +01:00
parent b08af77c98
commit 78335e5814
141 changed files with 773 additions and 54 deletions

View File

@@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
@@ -41,10 +42,12 @@ use Tests\TestCase;
*/
class TransactionControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
* @covers \FireflyIII\Http\Controllers\TransactionController::sumPerCurrency
*/
public function testIndex()
{
@@ -104,9 +107,19 @@ class TransactionControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
* @covers \FireflyIII\Http\Controllers\TransactionController::sumPerCurrency
*/
public function testIndexByDate()
{
$transaction = new Transaction;
$transaction->transaction_currency_id = 1;
$transaction->transaction_currency_symbol = 'x';
$transaction->transaction_currency_code = 'ABC';
$transaction->transaction_currency_dp = 2;
$transaction->transaction_amount = '5';
$collection = new Collection([$transaction]);
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
@@ -122,7 +135,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$collector->shouldReceive('getJournals')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('transactions.index', ['transfer', '2016-01-01']));
@@ -135,9 +148,18 @@ class TransactionControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
* @covers \FireflyIII\Http\Controllers\TransactionController::sumPerCurrency
*/
public function testIndexDeposit()
{
$transaction = new Transaction;
$transaction->transaction_currency_id = 1;
$transaction->transaction_currency_symbol = 'x';
$transaction->transaction_currency_code = 'ABC';
$transaction->transaction_currency_dp = 2;
$transaction->transaction_amount = '5';
$collection = new Collection([$transaction]);
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
@@ -153,7 +175,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$collector->shouldReceive('getJournals')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('transactions.index', ['deposit']));
@@ -166,9 +188,18 @@ class TransactionControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\TransactionController::index
* @covers \FireflyIII\Http\Controllers\TransactionController::__construct
* @covers \FireflyIII\Http\Controllers\TransactionController::getPeriodOverview
* @covers \FireflyIII\Http\Controllers\TransactionController::sumPerCurrency
*/
public function testIndexWithdrawal()
{
$transaction = new Transaction;
$transaction->transaction_currency_id = 1;
$transaction->transaction_currency_symbol = 'x';
$transaction->transaction_currency_code = 'ABC';
$transaction->transaction_currency_dp = 2;
$transaction->transaction_amount = '5';
$collection = new Collection([$transaction]);
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
@@ -184,7 +215,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('removeFilter')->withArgs([InternalTransferFilter::class])->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$collector->shouldReceive('getJournals')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('transactions.index', ['withdrawal']));
@@ -193,6 +224,23 @@ class TransactionControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::reconcile
*/
public function testReconcile()
{
$data = ['transactions' => [1, 2]];
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->times(1)->andReturn(new TransactionJournal);
$repository->shouldReceive('findTransaction')->andReturn(new Transaction)->twice();
$repository->shouldReceive('reconcile')->twice();
$this->be($this->user());
$response = $this->post(route('transactions.reconcile'), $data);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\TransactionController::reorder
*/