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:
@@ -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
|
||||
{
|
||||
|
Reference in New Issue
Block a user