Clean up tests, test only the important things.

This commit is contained in:
James Cole
2019-04-12 04:53:18 +02:00
parent 6f063a134f
commit 5ac39dbdef
65 changed files with 464 additions and 4016 deletions

View File

@@ -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
{