2017-08-18 08:32:11 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* AutoCompleteControllerTest.php
|
2020-02-16 06:59:55 -06:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2017-08-18 08:32:11 -05:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2017-10-21 01:40:00 -05:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:45:03 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2017-10-21 01:40:00 -05:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-08-18 08:32:11 -05:00
|
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Tests\Feature\Controllers\Json;
|
|
|
|
|
2019-06-29 12:47:31 -05:00
|
|
|
|
2017-08-18 08:32:11 -05:00
|
|
|
use FireflyIII\Models\AccountType;
|
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2019-08-29 10:53:25 -05:00
|
|
|
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
|
2017-08-18 08:32:11 -05:00
|
|
|
use Illuminate\Support\Collection;
|
2018-03-24 00:08:50 -05:00
|
|
|
use Log;
|
2017-08-18 08:32:11 -05:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AutoCompleteControllerTest
|
2019-08-17 03:48:28 -05:00
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2017-08-18 08:32:11 -05:00
|
|
|
*/
|
|
|
|
class AutoCompleteControllerTest extends TestCase
|
|
|
|
{
|
2018-03-24 00:08:50 -05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2018-09-02 13:27:26 -05:00
|
|
|
public function setUp(): void
|
2018-03-24 00:08:50 -05:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 13:05:20 -05:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-03-24 00:08:50 -05:00
|
|
|
}
|
|
|
|
|
2017-08-18 08:32:11 -05:00
|
|
|
/**
|
2019-06-29 12:47:31 -05:00
|
|
|
* Request a list of asset accounts
|
|
|
|
*
|
2018-08-09 13:17:15 -05:00
|
|
|
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
2017-08-18 08:32:11 -05:00
|
|
|
*/
|
2019-06-29 12:47:31 -05:00
|
|
|
public function testAccounts(): void
|
2019-04-09 08:32:48 -05:00
|
|
|
{
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
2019-06-29 12:47:31 -05:00
|
|
|
$account = $this->getRandomAsset();
|
|
|
|
$euro = $this->getEuro();
|
2018-06-01 15:04:52 -05:00
|
|
|
|
2019-06-29 12:47:31 -05:00
|
|
|
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
|
|
|
|
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
|
|
|
|
$this->mockDefaultSession();
|
2018-09-30 04:57:51 -05:00
|
|
|
|
|
|
|
$this->be($this->user());
|
2019-06-29 12:47:31 -05:00
|
|
|
$httpQuery = http_build_query(['types' => AccountType::ASSET]);
|
|
|
|
$response = $this->get(route('json.autocomplete.accounts') . '?' . $httpQuery);
|
2018-06-01 15:04:52 -05:00
|
|
|
$response->assertStatus(200);
|
2019-06-29 12:47:31 -05:00
|
|
|
$response->assertSee($account->name);
|
2018-06-01 15:04:52 -05:00
|
|
|
}
|
|
|
|
|
2018-08-06 12:14:30 -05:00
|
|
|
|
2019-07-24 12:02:41 -05:00
|
|
|
/**
|
|
|
|
* Request a list of revenue accounts
|
|
|
|
*
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
|
|
|
*/
|
|
|
|
public function testRevenueAccounts(): void
|
|
|
|
{
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$account = $this->getRandomAsset();
|
|
|
|
|
|
|
|
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('json.autocomplete.revenue-accounts'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee($account->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a list of expense accounts
|
|
|
|
*
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
|
|
|
*/
|
|
|
|
public function testExpenseAccounts(): void
|
|
|
|
{
|
|
|
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$account = $this->getRandomAsset();
|
|
|
|
|
|
|
|
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
|
|
|
|
$this->mockDefaultSession();
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('json.autocomplete.expense-accounts'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee($account->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a list of expense accounts
|
|
|
|
*
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
|
|
|
*/
|
|
|
|
public function testAllJournals(): void
|
|
|
|
{
|
2019-08-29 10:53:25 -05:00
|
|
|
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$journalRepos = $this->mockDefaultSession();
|
|
|
|
$journal = $this->getRandomWithdrawalAsArray();
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
|
|
|
|
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('json.autocomplete.all-journals'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee($journal['description']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a list of expense accounts
|
|
|
|
*
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
|
|
|
*/
|
|
|
|
public function testAllJournalsWithId(): void
|
|
|
|
{
|
2019-08-29 10:53:25 -05:00
|
|
|
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$journalRepos = $this->mockDefaultSession();
|
|
|
|
$journal = $this->getRandomWithdrawalAsArray();
|
|
|
|
|
|
|
|
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
|
|
|
|
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('json.autocomplete.all-journals-with-id'));
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee($journal['description']);
|
|
|
|
$response->assertSee($journal['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request a list of expense accounts
|
|
|
|
*
|
|
|
|
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
|
|
|
|
*/
|
|
|
|
public function testAllJournalsWithIdNumeric(): void
|
|
|
|
{
|
2019-08-29 10:53:25 -05:00
|
|
|
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
|
2019-07-24 12:02:41 -05:00
|
|
|
$journalRepos = $this->mockDefaultSession();
|
|
|
|
$journal = $this->getRandomWithdrawalAsArray();
|
2019-08-29 10:53:25 -05:00
|
|
|
$journalObject = $this->getRandomWithdrawalGroup();
|
2019-07-24 12:02:41 -05:00
|
|
|
|
|
|
|
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
|
2019-08-29 10:53:25 -05:00
|
|
|
$groupRepos->shouldReceive('find')->atLeast()->once()->andReturn($journalObject);
|
2019-07-24 12:02:41 -05:00
|
|
|
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$response = $this->get(route('json.autocomplete.all-journals-with-id') . '?search=' . $journal['id']);
|
|
|
|
$response->assertStatus(200);
|
|
|
|
$response->assertSee($journal['description']);
|
|
|
|
$response->assertSee($journal['id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-30 23:47:18 -05:00
|
|
|
}
|