Expand test coverage.

This commit is contained in:
James Cole
2018-09-30 11:57:51 +02:00
parent ea5ab54c3a
commit e33bbc6f16
9 changed files with 746 additions and 408 deletions

View File

@@ -29,6 +29,7 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -47,8 +48,6 @@ use Tests\TestCase;
*/
class AutoCompleteControllerTest extends TestCase
{
/**
*
*/
@@ -68,11 +67,12 @@ class AutoCompleteControllerTest extends TestCase
$collection = new Collection([$accountA]);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET]])
->withArgs([[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN,
AccountType::DEBT, AccountType::MORTGAGE]])
->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.all-accounts'));
$response = $this->get(route('json.autocomplete',['all-accounts']));
$response->assertStatus(200);
$response->assertExactJson([$accountA->name]);
@@ -88,10 +88,10 @@ class AutoCompleteControllerTest extends TestCase
$collection = new Collection([$accountA]);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')
->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn($collection);
->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.asset-accounts'));
$response = $this->get(route('json.autocomplete',['asset-accounts']));
$response->assertStatus(200);
$response->assertExactJson([$accountA->name]);
@@ -102,16 +102,39 @@ class AutoCompleteControllerTest extends TestCase
*/
public function testAllTransactionJournals(): void
{
$transaction = new Transaction();
$transaction->description = 'hi there';
$collection = new Collection([$transaction]);
$collector = $this->mock(TransactionCollectorInterface::class);
$collector->shouldReceive('setLimit')->withArgs([250])->andReturnSelf();
$collector->shouldReceive('setPage')->withArgs([1])->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
$collector->shouldReceive('getTransactions')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.all-transaction-journals'));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testAllTransactionJournalsSearch(): void
{
$transaction = new Transaction();
$transaction->description = 'hi there';
$collection = new Collection([$transaction]);
$collector = $this->mock(TransactionCollectorInterface::class);
$collector->shouldReceive('setLimit')->withArgs([250])->andReturnSelf();
$collector->shouldReceive('setPage')->withArgs([1])->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.all-transaction-journals').'?search=hi');
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
@@ -123,7 +146,22 @@ class AutoCompleteControllerTest extends TestCase
$repository->shouldReceive('getActiveBills')->andReturn($bills);
$this->be($this->user());
$response = $this->get(route('json.bills'));
$response = $this->get(route('json.autocomplete',['bills']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testBillsSearch(): void
{
$repository = $this->mock(BillRepositoryInterface::class);
$bills = factory(Bill::class, 10)->make();
$repository->shouldReceive('getActiveBills')->andReturn($bills);
$this->be($this->user());
$response = $this->get(route('json.autocomplete',['bills']).'?search=1234');
$response->assertStatus(200);
}
@@ -139,7 +177,7 @@ class AutoCompleteControllerTest extends TestCase
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));
$this->be($this->user());
$response = $this->get(route('json.budgets'));
$response = $this->get(route('json.autocomplete',['budgets']));
$response->assertStatus(200);
$response->assertExactJson([$budget->name]);
}
@@ -156,7 +194,7 @@ class AutoCompleteControllerTest extends TestCase
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
$this->be($this->user());
$response = $this->get(route('json.categories'));
$response = $this->get(route('json.autocomplete',['categories']));
$response->assertStatus(200);
$response->assertExactJson([$category->name]);
}
@@ -172,7 +210,7 @@ class AutoCompleteControllerTest extends TestCase
$repository->shouldReceive('get')->andReturn(new Collection([$currency]))->once();
$this->be($this->user());
$response = $this->get(route('json.currency-names'));
$response = $this->get(route('json.autocomplete',['currency-names']));
$response->assertStatus(200);
$response->assertExactJson(['Euro']);
}
@@ -194,7 +232,7 @@ class AutoCompleteControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.expense-accounts'));
$response = $this->get(route('json.autocomplete',['expense-accounts']));
$response->assertStatus(200);
$response->assertExactJson([$accountA->name]);
}
@@ -218,6 +256,25 @@ class AutoCompleteControllerTest extends TestCase
$response->assertExactJson([['id' => $journal->id, 'name' => $journal->id . ': ' . $journal->description]]);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testJournalsWithIdSearch(): void
{
$journal = $this->user()->transactionJournals()->where('id', '!=', 1)->first();
$journal->journal_id = $journal->id;
$collection = new Collection([$journal]);
$collector = $this->mock(TransactionCollectorInterface::class);
$collector->shouldReceive('setLimit')->withArgs([400])->andReturnSelf();
$collector->shouldReceive('setPage')->withArgs([1])->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.journals-with-id', [1]).'?search=a' );
$response->assertStatus(200);
$response->assertExactJson([['id' => $journal->id, 'name' => $journal->id . ': ' . $journal->description]]);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
@@ -235,7 +292,7 @@ class AutoCompleteControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.revenue-accounts'));
$response = $this->get(route('json.autocomplete',['revenue-accounts']));
$response->assertStatus(200);
$response->assertExactJson([$accountA->name]);
}
@@ -253,7 +310,7 @@ class AutoCompleteControllerTest extends TestCase
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]))->once();
$this->be($this->user());
$response = $this->get(route('json.tags'));
$response = $this->get(route('json.autocomplete', ['tags']));
$response->assertStatus(200);
$response->assertExactJson([$tag->tag]);
}
@@ -263,6 +320,10 @@ class AutoCompleteControllerTest extends TestCase
*/
public function testTransactionJournals(): void
{
$transaction = new Transaction();
$transaction->description = 'hi there';
$collection = new Collection([$transaction]);
// mock stuff
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
@@ -270,12 +331,36 @@ class AutoCompleteControllerTest extends TestCase
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
$collector->shouldReceive('getTransactions')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.transaction-journals', ['deposit']));
$response->assertStatus(200);
$response->assertExactJson([]);
$response->assertExactJson(['hi there']);
}
/**
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testTransactionJournalsSearch(): void
{
$transaction = new Transaction();
$transaction->description = 'hi there';
$collection = new Collection([$transaction]);
// mock stuff
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
$this->be($this->user());
$response = $this->get(route('json.transaction-journals', ['deposit']).'?search=hi');
$response->assertStatus(200);
$response->assertExactJson(['hi there']);
}
/**
@@ -289,7 +374,7 @@ class AutoCompleteControllerTest extends TestCase
$journalRepos->shouldReceive('getTransactionTypes')->once()->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('json.transaction-types', ['deposit']));
$response = $this->get(route('json.autocomplete',['transaction_types']));
$response->assertStatus(200);
$response->assertExactJson([]);
}