mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-19 16:10:00 +00:00
Improve test coverage.
This commit is contained in:
@@ -22,7 +22,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Bill;
|
||||
@@ -58,344 +58,28 @@ class AutoCompleteControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Request a list of asset accounts
|
||||
*
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testAllAccounts(): void
|
||||
public function testAccounts(): void
|
||||
{
|
||||
// mock stuff
|
||||
$accountA = factory(Account::class)->make();
|
||||
$collection = new Collection([$accountA]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs(
|
||||
[[AccountType::REVENUE, AccountType::EXPENSE, AccountType::BENEFICIARY, AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN,
|
||||
AccountType::DEBT, AccountType::MORTGAGE]]
|
||||
)
|
||||
->andReturn($collection);
|
||||
$account = $this->getRandomAsset();
|
||||
$euro = $this->getEuro();
|
||||
|
||||
|
||||
|
||||
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
|
||||
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
||||
$this->mockDefaultSession();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['all-accounts']));
|
||||
$httpQuery = http_build_query(['types' => AccountType::ASSET]);
|
||||
$response = $this->get(route('json.autocomplete.accounts') . '?' . $httpQuery);
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
|
||||
$response->assertSee($account->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testAllTransactionJournals(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$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'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testAllTransactionJournalsSearch(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$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
|
||||
*/
|
||||
public function testAssetAccounts(): void
|
||||
{
|
||||
// mock stuff
|
||||
$accountA = factory(Account::class)->make();
|
||||
$collection = new Collection([$accountA]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['asset-accounts']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testBills(): 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']));
|
||||
$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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testBudgets(): void
|
||||
{
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$categoryRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$categoryRepos->shouldReceive('getBudgets')->andReturn(new Collection([$budget]));
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['budgets']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$budget->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testCategories(): void
|
||||
{
|
||||
// mock stuff
|
||||
$category = factory(Category::class)->make();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]));
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['categories']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$category->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testCurrencyNames(): void
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$currency = TransactionCurrency::find(1);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection([$currency]))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['currency-names']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson(['Euro']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testExpenseAccounts(): void
|
||||
{
|
||||
// mock stuff
|
||||
$accountA = factory(Account::class)->make();
|
||||
$accountB = factory(Account::class)->make();
|
||||
$accountA->active = true;
|
||||
$accountB->active = false;
|
||||
$collection = new Collection([$accountA, $accountB]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->once()->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['expense-accounts']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testJournalsWithId(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$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]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([['id' => $journal->id, 'name' => $journal->id . ': ' . $journal->description]]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testJournalsWithIdSearch(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$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
|
||||
*/
|
||||
public function testRevenueAccounts(): void
|
||||
{
|
||||
// mock stuff
|
||||
$accountA = factory(Account::class)->make();
|
||||
$accountB = factory(Account::class)->make();
|
||||
$accountA->active = true;
|
||||
$accountB->active = false;
|
||||
$collection = new Collection([$accountA, $accountB]);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['revenue-accounts']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$accountA->name]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testTags(): void
|
||||
{
|
||||
// mock stuff
|
||||
$tag = factory(Tag::class)->make();
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['tags']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([$tag->tag]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testTransactionJournals(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$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']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson(['hi there']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testTransactionJournalsSearch(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$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']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
||||
*/
|
||||
public function testTransactionTypes(): void
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getTransactionTypes')->once()->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.autocomplete', ['transaction_types']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user