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