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