mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up tests, test only the important things.
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* AboutControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Transformers\UserTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AboutControllerTest.
|
||||
*/
|
||||
class AboutControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the about endpoint
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AboutController
|
||||
*/
|
||||
public function testAbout(): void
|
||||
{
|
||||
|
||||
$search = ['~', '#'];
|
||||
$replace = ['\~', '# '];
|
||||
$phpVersion = str_replace($search, $replace, PHP_VERSION);
|
||||
$phpOs = str_replace($search, $replace, PHP_OS);
|
||||
$response = $this->get(route('api.v1.about.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'version' => config('firefly.version'),
|
||||
'api_version' => config('firefly.api_version'),
|
||||
'php_version' => $phpVersion,
|
||||
'os' => $phpOs,
|
||||
'driver' => 'sqlite',
|
||||
]]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test user end point
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AboutController
|
||||
*/
|
||||
public function testUser(): void
|
||||
{
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$response = $this->get(route('api.v1.about.user'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -24,16 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Transformers\AccountTransformer;
|
||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||
use FireflyIII\Transformers\TransactionGroupTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
@@ -53,145 +46,10 @@ class AccountControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy account over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroy')->atLeast()->once()->andReturn(true);
|
||||
|
||||
// get account:
|
||||
$account = $this->getRandomAsset();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.accounts.delete', [$account->id]));
|
||||
$response->assertStatus(204);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the list of accounts.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$accounts = factory(Account::class, 10)->create();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAccountsByType')->withAnyArgs()->andReturn($accounts)->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/accounts');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 10, 'count' => 10, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertSee('type=all'); // default returns this.
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the list of piggy banks.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testPiggyBanks(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// get piggies for this user.
|
||||
$piggies = factory(PiggyBank::class, 10)->create();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn($piggies)->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.piggy_banks', [$asset->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(
|
||||
['meta' => ['pagination' => ['total' => $piggies->count(), 'count' => $piggies->count(), 'per_page' => true, 'current_page' => 1,
|
||||
'total_pages' => 1]],]
|
||||
);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertSee('page=1'); // default returns this.
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an account.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
|
||||
public function testShow(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$account = $this->getRandomAsset();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.show', [$account->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Opening balance without date.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreInvalidBalance(): void
|
||||
@@ -230,7 +88,6 @@ class AccountControllerTest extends TestCase
|
||||
* Send correct data. Should call account repository store method.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreLiability(): void
|
||||
@@ -277,7 +134,7 @@ class AccountControllerTest extends TestCase
|
||||
* CC type present when account is a credit card.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNoCreditCardData(): void
|
||||
{
|
||||
@@ -316,7 +173,6 @@ class AccountControllerTest extends TestCase
|
||||
* No currency information (is allowed).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNoCurrencyInfo(): void
|
||||
@@ -354,13 +210,11 @@ class AccountControllerTest extends TestCase
|
||||
* Name already in use.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
*/
|
||||
public function testStoreNotUnique(): void
|
||||
{
|
||||
// mock repositories
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
@@ -395,7 +249,6 @@ class AccountControllerTest extends TestCase
|
||||
* Send correct data. Should call account repository store method.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreValid(): void
|
||||
@@ -434,7 +287,6 @@ class AccountControllerTest extends TestCase
|
||||
* Send correct data. Should call account repository store method.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreWithCurrencyCode(): void
|
||||
@@ -471,138 +323,15 @@ class AccountControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show transactions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
// default mocks
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
|
||||
// objects
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
// calls to account repos.
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector:
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withAPIInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->withArgs([50])->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.transactions', [$asset->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show transactions but submit a limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testTransactionsLimit(): void
|
||||
{
|
||||
// default mocks
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
|
||||
// objects
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
// calls to account repos.
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector:
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withAPIInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->withArgs([10])->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.transactions', [$asset->id]) . '?limit=10');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
// default mocks
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$collector = $this->mock(GroupCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionGroupTransformer::class);
|
||||
|
||||
// objects
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
// calls to account repos.
|
||||
$accountRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock collector:
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('withAPIInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$asset = $this->getRandomAsset();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.accounts.transactions', [$asset->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update first asset account we find. Name can be the same as it was.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock repositories
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
@@ -639,7 +368,6 @@ class AccountControllerTest extends TestCase
|
||||
* Update first asset account we find. Name can be the same as it was.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
|
||||
*/
|
||||
public function testUpdateCurrencyCode(): void
|
||||
{
|
||||
@@ -681,7 +409,6 @@ class AccountControllerTest extends TestCase
|
||||
* Update a liability
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AccountController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest
|
||||
*/
|
||||
public function testUpdateLiability(): void
|
||||
{
|
||||
|
@@ -23,11 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||
use Exception;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Transformers\AttachmentTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
@@ -50,202 +48,11 @@ class AttachmentControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy account over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get attachment:
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.attachments.delete', [$attachment->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download attachment
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDownload(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
$content = 'Attachment content ' . random_int(100, 1000);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('exists')->andReturn(true)->once();
|
||||
$repository->shouldReceive('getContent')->andReturn($content)->once();
|
||||
|
||||
// get attachment:
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.attachments.download', [$attachment->id]));
|
||||
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($content);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Download attachment but file doesn't exist.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDownloadNotExisting(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
$content = 'Attachment content ' . random_int(100, 1000);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('exists')->andReturn(false)->once();
|
||||
|
||||
// get attachment:
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.attachments.download', [$attachment->id]));
|
||||
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Could not find the indicated attachment. The file is no longer there.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Download attachment but no file uploaded
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testDownloadNotUploaded(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// create attachment
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'attachable_id' => 1,
|
||||
'attachable_type' => TransactionJournal::class,
|
||||
'md5' => md5('Hello' . random_int(1, 10000)),
|
||||
'filename' => 'some name',
|
||||
'mime' => 'text/plain',
|
||||
'size' => 5,
|
||||
'uploaded' => false,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.attachments.download', [$attachment->id]));
|
||||
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No file has been uploaded for this attachment (yet).');
|
||||
}
|
||||
|
||||
/**
|
||||
* List all attachments.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$attachments = factory(Attachment::class, 10)->create();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('get')->once()->andReturn($attachments);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.attachments.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 10, 'count' => 10, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* List one attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var Attachment $attachment */
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.attachments.show', [$attachment->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a new attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AttachmentRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@@ -253,10 +60,9 @@ class AttachmentControllerTest extends TestCase
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -295,14 +101,13 @@ class AttachmentControllerTest extends TestCase
|
||||
* Update an attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AttachmentRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
// mock repositories
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -333,31 +138,6 @@ class AttachmentControllerTest extends TestCase
|
||||
$response->assertJson(['data' => ['type' => 'attachments', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload file for attachment.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
|
||||
*
|
||||
*/
|
||||
public function testUpload(): void
|
||||
{
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
|
||||
/** @var Attachment $attachment */
|
||||
$attachment = $this->user()->attachments()->first();
|
||||
$content = 'Hello there';
|
||||
// mock helper:
|
||||
$helper = $this->mock(AttachmentHelperInterface::class);
|
||||
$helper->shouldReceive('saveAttachmentFromApi')->once();
|
||||
|
||||
$response = $this->call('POST', route('api.v1.attachments.upload', [$attachment->id]), [], [], [], [], $content);
|
||||
//$response = $this->post('/api/v1/attachments/' . $attachment->id . '/upload',$content, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
}
|
||||
|
@@ -51,102 +51,14 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroyAvailableBudget')->once()->andReturn(true);
|
||||
|
||||
// get available budget:
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.available_budgets.delete', [$availableBudget->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all available budgets.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$availableBudgets = $this->user()->availableBudgets()->get();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAvailableBudgets')->once()->andReturn($availableBudgets);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.available_budgets.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($availableBudgets->first()->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show one available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$availableBudget = $this->user()->availableBudgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.available_budgets.show', [$availableBudget->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($availableBudget->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$availableBudget = new AvailableBudget;
|
||||
@@ -183,14 +95,12 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
* Store new available budget without a valid currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*/
|
||||
public function testStoreNoCurrencyAtAll(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$availableBudget = new AvailableBudget;
|
||||
|
||||
@@ -226,7 +136,6 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
* Store new available budget without a valid currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*/
|
||||
public function testStoreNoCurrencyId(): void
|
||||
{
|
||||
@@ -237,7 +146,6 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$factory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -273,7 +181,6 @@ class AvailableBudgetControllerTest extends TestCase
|
||||
* Update available budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
|
||||
*
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
|
@@ -24,18 +24,9 @@ declare(strict_types=1);
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
||||
use Exception;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Transformers\AttachmentTransformer;
|
||||
use FireflyIII\Transformers\BillTransformer;
|
||||
use FireflyIII\Transformers\RuleTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
@@ -56,155 +47,17 @@ class BillControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* List all attachments.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testAttachments(): void
|
||||
{
|
||||
// create stuff
|
||||
$bill = $this->user()->bills()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('getAttachments')->once()->andReturn(new Collection);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.attachments', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send delete
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get bill:
|
||||
$bill = $this->user()->bills()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.bills.delete', [$bill->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all bills
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50, 1);
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getPaginator')->withAnyArgs()->andReturn($paginator)->once();
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testRules(): void
|
||||
{
|
||||
$bill = $this->user()->bills()->first();
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('getRulesForBill')->atLeast()->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.bills.rules', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show one bill
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// create stuff
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.show', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'bills',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store with minimum amount more than maximum amount
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreMinOverMax(): void
|
||||
{
|
||||
// create stuff
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
@@ -243,7 +96,7 @@ class BillControllerTest extends TestCase
|
||||
* Store a valid bill
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreValid(): void
|
||||
{
|
||||
@@ -285,110 +138,12 @@ class BillControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBills')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.transactions', [$bill->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$bill = $this->user()->bills()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBills')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.bills.transactions', [$bill->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a valid bill.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BillController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BillRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateValid(): void
|
||||
{
|
||||
|
@@ -57,100 +57,10 @@ class BudgetControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all budgets
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testBudgetLimits(): void
|
||||
{
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once()->atLeast()->once();
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection());
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.budgets.budget_limits', [$budget->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get budget:
|
||||
$budget = $this->user()->budgets()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.budgets.delete', [$budget->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all budgets
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getBudgets')->once()->andReturn(new Collection);
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.budgets.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.budgets.show', [$budget->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@@ -188,7 +98,6 @@ class BudgetControllerTest extends TestCase
|
||||
* Store new budget limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testStoreBudgetLimit(): void
|
||||
{
|
||||
@@ -225,109 +134,10 @@ class BudgetControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.budgets.transactions', [$budget->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.budgets.transactions', [$budget->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a budget.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@@ -56,171 +56,10 @@ class BudgetLimitControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroyBudgetLimit')->once()->andReturn(true);
|
||||
|
||||
// Create a budget limit (just in case).
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$budgetLimit = BudgetLimit::create(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'start_date' => '2018-01-01',
|
||||
'end_date' => '2018-01-31',
|
||||
'amount' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.budget_limits.delete', $budgetLimit->id));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show budget limits by budget, include no dates.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$params = ['budget_id' => $budget->id,];
|
||||
$response = $this->get(route('api.v1.budget_limits.index') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show budget limits by budget, include dates.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testIndexNoBudget(): void
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->andReturn(null);
|
||||
$repository->shouldReceive('getAllBudgetLimits')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$params = [
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
];
|
||||
$uri = route('api.v1.budget_limits.index') . '?' . http_build_query($params);
|
||||
$response = $this->get($uri);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show budget limits by budget, include dates.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testIndexWithDates(): void
|
||||
{
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->andReturn($budget);
|
||||
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$params = [
|
||||
'budget_id' => $budget->id,
|
||||
'start' => '2018-01-01',
|
||||
'end' => '2018-01-31',
|
||||
];
|
||||
$response = $this->get(route('api.v1.budget_limits.index') . '?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// Create a budget limit (just in case).
|
||||
/** @var Budget $budget */
|
||||
$budget = $this->user()->budgets()->first();
|
||||
$budgetLimit = BudgetLimit::create(
|
||||
[
|
||||
'budget_id' => $budget->id,
|
||||
'start_date' => '2018-01-01',
|
||||
'end_date' => '2018-01-31',
|
||||
'amount' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.budget_limits.show', $budgetLimit->id));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new budget limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@@ -267,7 +106,6 @@ class BudgetLimitControllerTest extends TestCase
|
||||
* Store new budget limit, but give error
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testStoreBadBudget(): void
|
||||
{
|
||||
@@ -292,60 +130,10 @@ class BudgetLimitControllerTest extends TestCase
|
||||
$response->assertSee('Unknown budget.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$budgetLimit = BudgetLimit::first();
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$budgetRepos->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.budget_limits.transactions', [$budgetLimit->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update of budget limit.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\BudgetLimitController
|
||||
* @covers \FireflyIII\Api\V1\Requests\BudgetLimitRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@@ -55,83 +55,10 @@ class CategoryControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get category:
|
||||
$category = $this->user()->categories()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.categories.delete', $category->id));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all categories
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$transformer = $this->mock(CategoryTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getCategories')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.categories.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$category = $this->user()->categories()->first();
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CategoryRepositoryInterface::class);
|
||||
$transformer = $this->mock(CategoryTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.categories.show', [$category->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a new category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CategoryRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@@ -166,109 +93,10 @@ class CategoryControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$category = $this->user()->categories()->first();
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
$categoryRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.categories.transactions', [$category->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$category = $this->user()->categories()->first();
|
||||
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
$categoryRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('setUser');
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCategory')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.categories.transactions', [$category->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a category.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CategoryController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CategoryRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@@ -1,251 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ConfigurationControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Models\Configuration;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class ConfigurationControllerTest
|
||||
*/
|
||||
class ConfigurationControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$demoConfig = new Configuration;
|
||||
$demoConfig->name = 'is_demo_site';
|
||||
$demoConfig->data = false;
|
||||
|
||||
$permConfig = new Configuration;
|
||||
$permConfig->name = 'permission_update_check';
|
||||
$permConfig->data = -1;
|
||||
|
||||
$lastConfig = new Configuration;
|
||||
$lastConfig->name = 'last_update_check';
|
||||
$lastConfig->data = 123456789;
|
||||
|
||||
$singleConfig = new Configuration;
|
||||
$singleConfig->name = 'single_user_mode';
|
||||
$singleConfig->data = true;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site'])->andReturn($demoConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check'])->andReturn($permConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check'])->andReturn($lastConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode'])->andReturn($singleConfig)->once();
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'is_demo_site' => false,
|
||||
'permission_update_check' => -1,
|
||||
'last_update_check' => 123456789,
|
||||
'single_user_mode' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->get(route('api.v1.configuration.index'));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson($expected);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
*/
|
||||
public function testIndexNotOwner(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
Passport::actingAs($this->emptyUser());
|
||||
$response = $this->get(route('api.v1.configuration.index'));
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No access to method.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$data = [
|
||||
'value' => 1,
|
||||
|
||||
];
|
||||
|
||||
$demoConfig = new Configuration;
|
||||
$demoConfig->name = 'is_demo_site';
|
||||
$demoConfig->data = false;
|
||||
|
||||
$permConfig = new Configuration;
|
||||
$permConfig->name = 'permission_update_check';
|
||||
$permConfig->data = -1;
|
||||
|
||||
$lastConfig = new Configuration;
|
||||
$lastConfig->name = 'last_update_check';
|
||||
$lastConfig->data = 123456789;
|
||||
|
||||
$singleConfig = new Configuration;
|
||||
$singleConfig->name = 'single_user_mode';
|
||||
$singleConfig->data = true;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site'])->andReturn($demoConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check'])->andReturn($permConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check'])->andReturn($lastConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode'])->andReturn($singleConfig)->once();
|
||||
FireflyConfig::shouldReceive('set')->once()->withArgs(['permission_update_check', 1]);
|
||||
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'is_demo_site' => false,
|
||||
'permission_update_check' => -1,
|
||||
'last_update_check' => 123456789,
|
||||
'single_user_mode' => true,
|
||||
],
|
||||
];
|
||||
$response = $this->post(route('api.v1.configuration.update', ['permission_update_check']), $data);
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variables.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdateBoolean(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
$data = [
|
||||
'value' => 'true',
|
||||
|
||||
];
|
||||
|
||||
$demoConfig = new Configuration;
|
||||
$demoConfig->name = 'is_demo_site';
|
||||
$demoConfig->data = false;
|
||||
|
||||
$permConfig = new Configuration;
|
||||
$permConfig->name = 'permission_update_check';
|
||||
$permConfig->data = -1;
|
||||
|
||||
$lastConfig = new Configuration;
|
||||
$lastConfig->name = 'last_update_check';
|
||||
$lastConfig->data = 123456789;
|
||||
|
||||
$singleConfig = new Configuration;
|
||||
$singleConfig->name = 'single_user_mode';
|
||||
$singleConfig->data = true;
|
||||
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site'])->andReturn($demoConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check'])->andReturn($permConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['last_update_check'])->andReturn($lastConfig)->once();
|
||||
FireflyConfig::shouldReceive('get')->withArgs(['single_user_mode'])->andReturn($singleConfig)->once();
|
||||
FireflyConfig::shouldReceive('set')->once()->withArgs(['single_user_mode', true]);
|
||||
|
||||
|
||||
$expected = [
|
||||
'data' => [
|
||||
'is_demo_site' => false,
|
||||
'permission_update_check' => -1,
|
||||
'last_update_check' => 123456789,
|
||||
'single_user_mode' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->post(route('api.v1.configuration.update', ['single_user_mode']), $data);
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variable that you're not allowed to change
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdateInvalid(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$data = [
|
||||
'value' => 'true',
|
||||
];
|
||||
$response = $this->post('/api/v1/configuration/last_update_check', $data);
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set configuration variables but you're not the owner.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ConfigurationController
|
||||
* @covers \FireflyIII\Api\V1\Requests\ConfigurationRequest
|
||||
*/
|
||||
public function testUpdateNotOwner(): void
|
||||
{
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
|
||||
|
||||
Passport::actingAs($this->emptyUser());
|
||||
$response = $this->post(route('api.v1.configuration.update', ['single_user_mode']));
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No access to method.');
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -74,450 +74,16 @@ class CurrencyControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the list of accounts.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testAccounts(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$currency = TransactionCurrency::first();
|
||||
$account = $this->getRandomAsset();
|
||||
$collection = new Collection([$account]);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(AccountTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAccountsByType')->withAnyArgs()->andReturn($collection)->atLeast()->once();
|
||||
$repository->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('1');
|
||||
|
||||
// test API
|
||||
|
||||
$response = $this->get(route('api.v1.currencies.accounts', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 1, 'count' => 1, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertSee('type=all'); // default returns this.
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all available budgets.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testAvailableBudgets(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(AvailableBudgetTransformer::class);
|
||||
$collection = new Collection([AvailableBudget::first()]);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$budgetRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$budgetRepos->shouldReceive('getAvailableBudgets')->once()->andReturn($collection);
|
||||
|
||||
// call API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.available_budgets', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show all bills
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testBills(): void
|
||||
{
|
||||
// create stuff
|
||||
$paginator = new LengthAwarePaginator(new Collection([Bill::first()]), 0, 50, 1);
|
||||
// mock stuff:
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(BillTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getPaginator')->withAnyArgs()->andReturn($paginator)->once();
|
||||
|
||||
// test API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.bills', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testBudgetLimits(): void
|
||||
{
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(BudgetLimitTransformer::class);
|
||||
$currency = TransactionCurrency::first();
|
||||
$budgetLimit = BudgetLimit::first();
|
||||
$budgetLimit->transaction_currency_id = $currency->id;
|
||||
$collection = new Collection([$budgetLimit]);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('getAllBudgetLimits')->once()->andReturn($collection);
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$response = $this->get(route('api.v1.currencies.budget_limits', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testCer(): void
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls
|
||||
$repository->shouldReceive('setUser')->once()->atLeast()->once();
|
||||
$repository->shouldReceive('getExchangeRates')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.cer', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send delete
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->once()->withArgs([Mockery::any(), 'owner'])->andReturn(true);
|
||||
$repository->shouldReceive('currencyInUse')->once()->andReturn(false);
|
||||
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get a currency
|
||||
$currency = TransactionCurrency::first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/currencies/' . $currency->code);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testDisable(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('disable')->once();
|
||||
$repository->shouldReceive('currencyInUse')->once()->andReturnFalse();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.disable', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testDisableInUse(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('currencyInUse')->once()->andReturnTrue();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.disable', [$currency->code]));
|
||||
$response->assertStatus(409);
|
||||
$response->assertJson([]);
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testEnable(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('enable')->once();
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.enable', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getAll')->withNoArgs()->andReturn(new Collection)->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/currencies');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(
|
||||
[
|
||||
'meta' => [
|
||||
'pagination' => [
|
||||
'total' => 0,
|
||||
'count' => 0,
|
||||
'per_page' => true, // depends on user preference.
|
||||
'current_page' => 1,
|
||||
'total_pages' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testMakeDefault(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('enable')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->post(route('api.v1.currencies.default', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testRecurrences(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$recurrence = Recurrence::first();
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getAll')->once()->andReturn(new Collection([$recurrence]));
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.recurrences', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testRules(): void
|
||||
{
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$ruleRepos->shouldReceive('getAll')->once()->andReturn(new Collection([Rule::first()]));
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$currency = TransactionCurrency::first();
|
||||
$response = $this->get(route('api.v1.currencies.rules', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test show of a currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// create stuff
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/currencies/' . $currency->code);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currencies',
|
||||
],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
@@ -552,13 +118,11 @@ class CurrencyControllerTest extends TestCase
|
||||
* Store new currency and make it default.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testStoreWithDefault(): void
|
||||
{
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
@@ -595,110 +159,15 @@ class CurrencyControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testTransactionsBasic(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$currency = TransactionCurrency::first();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCurrency')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(route('api.v1.currencies.transactions', [$currency->code]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
*/
|
||||
public function testTransactionsRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$currency = TransactionCurrency::first();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$currencyRepository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setCurrency')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// test API
|
||||
$response = $this->get(
|
||||
route('api.v1.currencies.transactions', [$currency->code]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update currency.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
@@ -733,13 +202,11 @@ class CurrencyControllerTest extends TestCase
|
||||
* Update currency and make default.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyController
|
||||
* @covers \FireflyIII\Api\V1\Requests\CurrencyRequest
|
||||
*/
|
||||
public function testUpdateWithDefault(): void
|
||||
{
|
||||
$currency = TransactionCurrency::first();
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(CurrencyTransformer::class);
|
||||
$preference = new Preference;
|
||||
$preference->data = 'EUR';
|
||||
|
@@ -1,173 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CurrencyExchangeRateControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Services\Currency\ExchangeRateInterface;
|
||||
use FireflyIII\Transformers\CurrencyExchangeRateTransformer;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class CurrencyExchangeRateControllerTest
|
||||
*/
|
||||
class CurrencyExchangeRateControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(TransactionCurrency::whereCode('EUR')->first())->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
$repository->shouldReceive('getExchangeRate')->andReturn(null)->once();
|
||||
$service->shouldReceive('setUser')->once();
|
||||
$service->shouldReceive('getRate')->once()->andReturn($rate);
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params));
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
['data' => [
|
||||
'type' => 'currency_exchange_rates',
|
||||
],
|
||||
]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadDestination(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(null)->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown destination currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController
|
||||
*/
|
||||
public function testIndexBadSource(): void
|
||||
{
|
||||
// mock repository
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$service = $this->mock(ExchangeRateInterface::class);
|
||||
$transformer = $this->mock(CurrencyExchangeRateTransformer::class);
|
||||
|
||||
$rate = new CurrencyExchangeRate();
|
||||
$rate->date = new Carbon();
|
||||
$rate->updated_at = new Carbon();
|
||||
$rate->created_at = new Carbon();
|
||||
$rate->rate = '0.5';
|
||||
$rate->to_currency_id = 1;
|
||||
$rate->from_currency_id = 2;
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
|
||||
$repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once();
|
||||
|
||||
// test API
|
||||
$params = [
|
||||
'from' => 'EUR',
|
||||
'to' => 'USD',
|
||||
'date' => '2018-01-01',
|
||||
];
|
||||
$response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Unknown source currency.');
|
||||
$response->assertHeader('Content-Type', 'application/json');
|
||||
}
|
||||
}
|
@@ -1,138 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* ImportControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Transformers\ImportJobTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ImportControllerTest
|
||||
*/
|
||||
class ImportControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Passport::actingAs($this->user());
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ImportController
|
||||
*/
|
||||
public function testListAll(): void
|
||||
{
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$transformer = $this->mock(ImportJobTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.import.list'), ['Accept' => 'application/json']);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ImportController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->first();
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$transformer = $this->mock(ImportJobTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
|
||||
$response = $this->get(route('api.v1.import.show', [$job->key]), ['accept' => 'application/json']);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\ImportController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
/** @var ImportJob $job */
|
||||
$job = $this->user()->importJobs()->first();
|
||||
$tag = $this->user()->tags()->first();
|
||||
$job->tag_id = $tag->id;
|
||||
$job->save();
|
||||
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// paginator:
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTag')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.import.transactions', [$job->key]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']),
|
||||
['accept' => 'application/json']
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
}
|
@@ -23,19 +23,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
||||
use Exception;
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\Transformers\LinkTypeTransformer;
|
||||
use FireflyIII\Transformers\TransactionTransformer;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Class LinkTypeControllerTest
|
||||
@@ -55,114 +51,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// create editable link type:
|
||||
$linkType = LinkType::create(
|
||||
[
|
||||
'name' => 'random' . random_int(1, 100000),
|
||||
'outward' => 'outward' . random_int(1, 100000),
|
||||
'inward' => 'inward ' . random_int(1, 100000),
|
||||
'editable' => true,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/link_types/' . $linkType->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testDeleteNotEditable(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
// create editable link type:
|
||||
$linkType = LinkType::create(
|
||||
[
|
||||
'name' => 'random' . random_int(1, 100000),
|
||||
'outward' => 'outward' . random_int(1, 100000),
|
||||
'inward' => 'inward ' . random_int(1, 100000),
|
||||
'editable' => false,
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/link_types/' . $linkType->id);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('You cannot delete this link type');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/link_types');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$linkType = LinkType::first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/link_types/' . $linkType->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@@ -203,16 +92,13 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNotOwner(): void
|
||||
{
|
||||
$linkType = LinkType::first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
@@ -236,48 +122,7 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$linkType = LinkType::first();
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
// mock repositories:
|
||||
$linkTypeRepos = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$journalIds = $linkTypeRepos->shouldReceive('getJournalIds')->once()->andReturn([1, 2, 3]);
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setJournalIds')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
$linkTypeRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.link_types.transactions', [$linkType->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
@@ -327,14 +172,12 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateNotEditable(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
// create editable link type:
|
||||
$linkType = LinkType::create(
|
||||
@@ -367,14 +210,13 @@ class LinkTypeControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\LinkTypeController
|
||||
* @covers \FireflyIII\Api\V1\Requests\LinkTypeRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdateNotOwner(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(LinkTypeTransformer::class);
|
||||
|
||||
$userRepository->shouldReceive('hasRole')->once()->andReturn(false);
|
||||
|
||||
|
@@ -23,13 +23,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace Tests\Api\V1\Controllers;
|
||||
|
||||
use Exception;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Transformers\PiggyBankEventTransformer;
|
||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Laravel\Passport\Passport;
|
||||
use Log;
|
||||
use Mockery;
|
||||
@@ -52,126 +51,8 @@ class PiggyBankControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy piggy bank over API
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{ // mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get piggy bank:
|
||||
$piggyBank = $this->user()->piggyBanks()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/piggy_banks/' . $piggyBank->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// create stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
$repository->shouldReceive('getPiggyBanks')->withAnyArgs()->andReturn(new Collection())->once();
|
||||
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$currencyRepos->shouldReceive('setUser');
|
||||
//$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first());
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/piggy_banks');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => true, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(
|
||||
['links' => ['self' => true, 'first' => true, 'last' => true,],]
|
||||
);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testPiggyBankEvents(): void
|
||||
{
|
||||
$piggyBank = $this->user()->piggyBanks()->first();
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankEventTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getEvents')->once()->andReturn(new Collection);
|
||||
|
||||
$response = $this->get(route('api.v1.piggy_banks.events', [$piggyBank->id]));
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// create stuff
|
||||
$piggy = $this->user()->piggyBanks()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
//$currencyRepos->shouldReceive('setUser')->once();
|
||||
//$accountRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$repository->shouldReceive('getCurrentAmount')->andReturn('12');
|
||||
$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('12');
|
||||
|
||||
//$accountRepos->shouldReceive('setUser');
|
||||
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
|
||||
$currencyRepos->shouldReceive('setUser');
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first());
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/piggy_banks/' . $piggy->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => ['type' => 'piggy_banks', 'links' => true],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PiggyBankRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStore(): void
|
||||
{
|
||||
@@ -179,10 +60,8 @@ class PiggyBankControllerTest extends TestCase
|
||||
$piggy = $this->user()->piggyBanks()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
@@ -193,17 +72,8 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
//$accountRepos->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('store')->once()->andReturn($piggy);
|
||||
|
||||
//$repository->shouldReceive('getCurrentAmount')->andReturn('12')->once();
|
||||
//$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('12')->once();
|
||||
|
||||
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
|
||||
|
||||
//$currencyRepos->shouldReceive('setUser')->once();
|
||||
//$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
|
||||
|
||||
$data = [
|
||||
'name' => 'New piggy #' . random_int(1, 100000),
|
||||
'account_id' => 1,
|
||||
@@ -220,15 +90,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PiggyBankRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testStoreNull(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$transformer = $this->mock(PiggyBankTransformer::class);
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
@@ -251,7 +118,7 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PiggyBankController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PiggyBankRequest
|
||||
* @throws Exception
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
@@ -274,8 +141,6 @@ class PiggyBankControllerTest extends TestCase
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser');
|
||||
//$currencyRepos->shouldReceive('setUser')->once();
|
||||
//$accountRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$repository->shouldReceive('update')->once()->andReturn($piggy);
|
||||
|
||||
|
@@ -51,34 +51,6 @@ class PreferencesControllerTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$transformer = $this->mock(PreferenceTransformer::class);
|
||||
$available = ['language', 'customFiscalYear', 'fiscalYearStart', 'currencyPreference', 'transaction_journal_optional_fields', 'frontPageAccounts',
|
||||
'viewRange', 'listPageSize, twoFactorAuthEnabled',];
|
||||
|
||||
foreach ($available as $pref) {
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), $pref])->once();
|
||||
}
|
||||
// extra call for frontpage preference
|
||||
$pref = new Preference;
|
||||
$pref->data = [1];
|
||||
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'frontPageAccounts', []])->once()
|
||||
->andReturn($pref);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/preferences');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateArray(): void
|
||||
{
|
||||
$transformer = $this->mock(PreferenceTransformer::class);
|
||||
@@ -100,7 +72,6 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateBoolean(): void
|
||||
{
|
||||
@@ -123,7 +94,6 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateDefault(): void
|
||||
{
|
||||
@@ -146,7 +116,6 @@ class PreferencesControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\PreferenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\PreferenceRequest
|
||||
*/
|
||||
public function testUpdateInteger(): void
|
||||
{
|
||||
|
@@ -60,92 +60,11 @@ class RecurrenceControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get a recurrence:
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/recurrences/' . $recurrence->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
$repository->shouldReceive('getAll')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/recurrences');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var Recurrence $recurrence */
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/recurrences/' . $recurrence->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreAssetId(): void
|
||||
{
|
||||
@@ -231,7 +150,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source name field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreAssetName(): void
|
||||
{
|
||||
@@ -319,7 +238,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit a deposit. Since most validators have been tested in other methods, dont bother too much.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreDeposit(): void
|
||||
{
|
||||
@@ -408,7 +327,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Add a recurring with correct reference to a destination (expense).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreDestinationId(): void
|
||||
{
|
||||
@@ -501,7 +420,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Add a recurring with correct reference to a destination (expense).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreDestinationName(): void
|
||||
{
|
||||
@@ -592,7 +511,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Includes both repetition count and an end date.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailBothRepetitions(): void
|
||||
{
|
||||
@@ -688,7 +607,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit foreign amount but no currency information.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailForeignCurrency(): void
|
||||
{
|
||||
@@ -768,7 +687,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidDaily(): void
|
||||
{
|
||||
@@ -847,7 +766,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Add a recurring but refer to an asset as destination.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidDestinationId(): void
|
||||
{
|
||||
@@ -939,7 +858,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidMonthly(): void
|
||||
{
|
||||
@@ -1017,7 +936,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdom(): void
|
||||
{
|
||||
@@ -1095,7 +1014,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomCount(): void
|
||||
{
|
||||
@@ -1174,7 +1093,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidNdomHigh(): void
|
||||
{
|
||||
@@ -1252,7 +1171,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit the minimum amount to store a recurring transaction (using source ID field).
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailInvalidWeekly(): void
|
||||
{
|
||||
@@ -1330,7 +1249,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit without a source account.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailNoAsset(): void
|
||||
{
|
||||
@@ -1402,7 +1321,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit with an expense account.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailNotAsset(): void
|
||||
{
|
||||
@@ -1480,7 +1399,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit with an invalid asset account name.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailNotAssetName(): void
|
||||
{
|
||||
@@ -1565,7 +1484,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Dont include enough repetitions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailRepetitions(): void
|
||||
{
|
||||
@@ -1635,7 +1554,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Dont include enough repetitions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreFailTransactions(): void
|
||||
{
|
||||
@@ -1703,7 +1622,7 @@ class RecurrenceControllerTest extends TestCase
|
||||
* Submit a transfer. Since most validators have been tested in other methods, dont bother too much.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest
|
||||
*/
|
||||
public function testStoreTransfer(): void
|
||||
{
|
||||
@@ -1790,102 +1709,11 @@ class RecurrenceControllerTest extends TestCase
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$recurrence = $this->user()->recurrences()->first();
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
// mock repositories:
|
||||
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
$journalIds = $recurringRepos->shouldReceive('getJournalIds')->once()->andReturn([1, 2, 3]);
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setJournalIds')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
$recurringRepos->shouldReceive('setUser')->once();
|
||||
|
||||
$response = $this->get(
|
||||
route('api.v1.recurrences.transactions', [$recurrence->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31'])
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTriggerError(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$cronjob = $this->mock(RecurringCronjob::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
$cronjob->shouldReceive('fire')->andThrow(FireflyException::class);
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
|
||||
$response = $this->post(route('api.v1.recurrences.trigger'));
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('Could not fire recurring cron job.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTriggerFalse(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$cronjob = $this->mock(RecurringCronjob::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
$cronjob->shouldReceive('fire')->once()->andReturnFalse();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$response = $this->post(route('api.v1.recurrences.trigger'));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
*/
|
||||
public function testTriggerTrue(): void
|
||||
{
|
||||
$repository = $this->mock(RecurringRepositoryInterface::class);
|
||||
$cronjob = $this->mock(RecurringCronjob::class);
|
||||
$categoryFactory = $this->mock(CategoryFactory::class);
|
||||
$transformer = $this->mock(RecurrenceTransformer::class);
|
||||
$cronjob->shouldReceive('fire')->once()->andReturnTrue();
|
||||
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||
|
||||
$response = $this->post(route('api.v1.recurrences.trigger'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just a basic test because the store() tests cover everything.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RecurrenceController
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest
|
||||
* @covers \FireflyIII\Api\V1\Requests\RecurrenceUpdateRequest
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
|
@@ -55,76 +55,6 @@ class RuleControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
/** @var Rule $rule */
|
||||
$rule = $this->user()->rules()->first();
|
||||
|
||||
// mock stuff:
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$response = $this->delete('/api/v1/rules/' . $rule->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('getAll')->once()->andReturn(new Collection);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rules');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$rule = $this->user()->rules()->first();
|
||||
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleRepos->shouldReceive('setUser')->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rules/' . $rule->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleController
|
||||
|
@@ -56,100 +56,6 @@ class RuleGroupControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
/** @var RuleGroup $ruleGroup */
|
||||
$ruleGroup = $this->user()->ruleGroups()->first();
|
||||
|
||||
// mock stuff:
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
$response = $this->delete('/api/v1/rule_groups/' . $ruleGroup->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('get')->once()->andReturn(new Collection);
|
||||
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rule_groups');
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testRules(): void
|
||||
{
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleTransformer::class);
|
||||
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('getRules')->once()->andReturn(new Collection);
|
||||
|
||||
// call API
|
||||
$group = $this->user()->ruleGroups()->first();
|
||||
$response = $this->get(route('api.v1.rule_groups.rules', [$group->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
/** @var RuleGroup $ruleGroup */
|
||||
$ruleGroup = $this->user()->ruleGroups()->first();
|
||||
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$transformer = $this->mock(RuleGroupTransformer::class);
|
||||
|
||||
$accountRepos->shouldReceive('setUser')->once();
|
||||
$ruleGroupRepos->shouldReceive('setUser')->once();
|
||||
|
||||
// mock calls to transformer:
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/rule_groups/' . $ruleGroup->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\RuleGroupController
|
||||
|
@@ -49,136 +49,6 @@ class TagControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->id])->andReturnNull();
|
||||
$tagRepos->shouldReceive('findNull')->once()->withArgs([$tag->id])->andReturn($tag);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.tags.delete', [$tag->id]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testDeleteByTag(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('destroy')->once()->andReturn(true);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->tag])->andReturn($tag);
|
||||
|
||||
// call API
|
||||
$response = $this->delete(route('api.v1.tags.delete', [$tag->tag]));
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag index
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$transformer = $this->mock(TagTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(1);
|
||||
$tagRepos->shouldReceive('get')->once()->andReturn(new Collection());
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
$transformer = $this->mock(TagTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->id])->andReturnNull();
|
||||
$tagRepos->shouldReceive('findNull')->once()->withArgs([$tag->id])->andReturn($tag);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.show', [$tag->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show Tag over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testShowByTag(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
$transformer = $this->mock(TagTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->tag])->andReturn($tag);
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.show', [$tag->tag]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Tag over API.
|
||||
*
|
||||
@@ -208,52 +78,6 @@ class TagControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show transactions.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TagController
|
||||
*/
|
||||
public function testTransactions(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$tagRepos = $this->mock(TagRepositoryInterface::class);
|
||||
$tag = $this->user()->tags()->inRandomOrder()->first();
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$paginator = new LengthAwarePaginator([], 0, 50);
|
||||
|
||||
// mock calls:
|
||||
$tagRepos->shouldReceive('setUser')->times(2);
|
||||
$tagRepos->shouldReceive('findByTag')->once()->withArgs([(string)$tag->id])->andReturnNull();
|
||||
$tagRepos->shouldReceive('findNull')->once()->withArgs([$tag->id])->andReturn($tag);
|
||||
|
||||
$collector->shouldReceive('setUser')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTag')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->once()->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->once()->andReturn($paginator);
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.tags.transactions', [$tag->id]) . '?' . http_build_query(['start' => '2018-01-01', 'end' => '2018-01-31']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Tag over API.
|
||||
*
|
||||
|
@@ -56,63 +56,6 @@ class TransactionControllerTest extends TestCase
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testAttachments(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$attachmentRepos = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$transformer = $this->mock(AttachmentTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getAttachmentsByTr')->once()->andReturn(new Collection);
|
||||
|
||||
// get account:
|
||||
$transaction = $this->user()->transactions()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.transactions.attachments', [$transaction->id]));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy journal over API.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroy')->once()->andReturn(true);
|
||||
|
||||
// get account:
|
||||
$transaction = $this->user()->transactions()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/transactions/' . $transaction->id);
|
||||
$response->assertStatus(204);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit with bad currency code
|
||||
*
|
||||
@@ -1323,234 +1266,6 @@ class TransactionControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show index with range.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testIndexWithRange(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
|
||||
$paginator = new LengthAwarePaginator(new Collection, 0, 50);
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('removeFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock some calls:
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions?start=2018-01-01&end=2018-01-31');
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(
|
||||
['meta' =>
|
||||
['pagination' =>
|
||||
[
|
||||
'total' => 0,
|
||||
'count' => 0,
|
||||
'per_page' => 50,
|
||||
'current_page' => 1,
|
||||
'total_pages' => 1,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testPiggyBankEvents(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(PiggyBankEventTransformer::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getPiggyBankEventsbyTr')->once()->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
|
||||
// get account:
|
||||
$transaction = $this->user()->transactions()->first();
|
||||
|
||||
// call API
|
||||
$response = $this->get(route('api.v1.transactions.piggy_bank_events', [$transaction->id]));
|
||||
$response->assertStatus(200);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a withdrawal.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testShowDeposit(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$deposit = $this->getRandomDeposit();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setJournals')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('addFilter')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions/' . $deposit->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
[
|
||||
'data' => [
|
||||
],
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a withdrawal.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
|
||||
*/
|
||||
public function testShowWithdrawal(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transformer = $this->mock(TransactionTransformer::class);
|
||||
$withdrawal = $this->getRandomWithdrawal();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$accountRepos->shouldReceive('setUser');
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->andReturn($this->user()->accounts()->where('account_type_id', 3)->get());
|
||||
|
||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$repository->shouldReceive('setUser');
|
||||
$collector->shouldReceive('setUser')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setJournals')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('addFilter')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/transactions/' . $withdrawal->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(
|
||||
[
|
||||
'data' => [
|
||||
],
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a transaction (withdrawal) with attached bill ID
|
||||
|
@@ -53,102 +53,6 @@ class TransactionLinkControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('destroyLink')->once()->andReturn(true);
|
||||
|
||||
// get a link
|
||||
/** @var TransactionJournalLink $journalLink */
|
||||
$journalLink = TransactionJournalLink::first();
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/transaction_links/' . $journalLink->id);
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$transaction = Transaction::first();
|
||||
$transaction->date = new Carbon;
|
||||
$transaction->transaction_type_type = 'Withdrawal';
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionLinkTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findByName')->once()->andReturn(null);
|
||||
$repository->shouldReceive('getJournalLinks')->once()->andReturn(new Collection);
|
||||
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/transaction_links');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$journalLink = TransactionJournalLink::first();
|
||||
$transaction = Transaction::first();
|
||||
$transaction->date = new Carbon;
|
||||
$transaction->transaction_type_type = 'Withdrawal';
|
||||
|
||||
|
||||
// mock stuff:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$collector = $this->mock(TransactionCollectorInterface::class);
|
||||
$transformer = $this->mock(TransactionLinkTransformer::class);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// mock calls:
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$journalRepos->shouldReceive('setUser')->once();
|
||||
|
||||
|
||||
// call API
|
||||
$response = $this->get('/api/v1/transaction_links/' . $journalLink->id);
|
||||
$response->assertStatus(200);
|
||||
$response->assertSee($journalLink->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Api\V1\Controllers\TransactionLinkController
|
||||
* @covers \FireflyIII\Api\V1\Requests\TransactionLinkRequest
|
||||
|
@@ -50,110 +50,6 @@ class UserControllerTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserRequest
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
$userRepository->shouldReceive('destroy')->once();
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/users/2');
|
||||
$response->assertStatus(204);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user as non admin
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserRequest
|
||||
*/
|
||||
public function testDeleteNoAdmin(): void
|
||||
{
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(false);
|
||||
Passport::actingAs($this->emptyUser());
|
||||
|
||||
// create a user first:
|
||||
$user = User::create(['email' => 'some@newu' . random_int(1, 10000) . 'ser.nl', 'password' => 'hello', 'blocked' => 0]);
|
||||
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/users/' . $user->id, [], ['Accept' => 'application/json']);
|
||||
$response->assertStatus(302);
|
||||
$this->assertDatabaseHas('users', ['id' => $user->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cannot delete yourself.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
* @covers \FireflyIII\Api\V1\Requests\UserRequest
|
||||
*/
|
||||
public function testDeleteYourself(): void
|
||||
{
|
||||
$userRepository = $this->mock(UserRepositoryInterface::class);
|
||||
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
|
||||
|
||||
// create a user first:
|
||||
// call API
|
||||
$response = $this->delete('/api/v1/users/' . $this->user()->id, [], ['Accept' => 'application/json']);
|
||||
$response->assertStatus(500);
|
||||
$response->assertSee('No access to method.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show list of users.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
// mock stuff:
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
|
||||
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
$repository->shouldReceive('all')->withAnyArgs()->andReturn(new Collection)->once();
|
||||
$transformer->shouldReceive('setParameters')->atLeast()->once();
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/users', ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['data' => [],]);
|
||||
$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'current_page' => 1, 'total_pages' => 1]],]);
|
||||
$response->assertJson(['links' => ['self' => true, 'first' => true, 'last' => true,],]);
|
||||
$response->assertHeader('Content-Type', 'application/vnd.api+json');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show single user.
|
||||
*
|
||||
* @covers \FireflyIII\Api\V1\Controllers\UserController
|
||||
*/
|
||||
public function testShow(): void
|
||||
{
|
||||
$user = User::first();
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$transformer = $this->mock(UserTransformer::class);
|
||||
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->once()->andReturn(true);
|
||||
|
||||
// mock transformer
|
||||
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
|
||||
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
|
||||
$transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
|
||||
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
|
||||
|
||||
// test API
|
||||
$response = $this->get('/api/v1/users/' . $user->id, ['Accept' => 'application/json']);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store new user.
|
||||
*
|
||||
|
Reference in New Issue
Block a user