Improve test coverage and fix test code.

This commit is contained in:
James Cole
2018-08-23 18:33:39 +02:00
parent 3f493aceb2
commit d4096103cb
21 changed files with 1378 additions and 21 deletions

View File

@@ -129,7 +129,7 @@ class AvailableBudgetControllerTest extends TestCase
// mock calls:
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setAvailableBudget')->once()->andReturn($availableBudget);
$currencyRepository->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
// data to submit
$data = [
@@ -148,6 +148,78 @@ class AvailableBudgetControllerTest extends TestCase
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
/**
* Store new available budget without a valid currency.
*
* @covers \FireflyIII\Api\V1\Controllers\AvailableBudgetController
* @covers \FireflyIII\Api\V1\Requests\AvailableBudgetRequest
*/
public function testStoreNoCurrencyId(): void
{
/** @var AvailableBudget $availableBudget */
$availableBudget = $this->user()->availableBudgets()->first();
// mock stuff:
$repository = $this->mock(BudgetRepositoryInterface::class);
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setAvailableBudget')->once()->andReturn($availableBudget);
$currencyRepository->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
$currencyRepository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(TransactionCurrency::find(1))->once();
// data to submit
$data = [
'currency_id' => '1',
'currency_code' => 'EUR',
'amount' => '100',
'start_date' => '2018-01-01',
'end_date' => '2018-01-31',
];
// test API
$response = $this->post('/api/v1/available_budgets', $data);
$response->assertStatus(200);
$response->assertJson(['data' => ['type' => 'available_budgets', 'links' => true],]);
$response->assertSee($availableBudget->amount); // the amount
$response->assertHeader('Content-Type', 'application/vnd.api+json');
}
/**
* 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);
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('setUser')->once();
$currencyRepository->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
$currencyRepository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once();
// data to submit
$data = [
'currency_id' => '1',
'currency_code' => 'EUR',
'amount' => '100',
'start_date' => '2018-01-01',
'end_date' => '2018-01-31',
];
// test API
$response = $this->post('/api/v1/available_budgets', $data, ['Accept' => 'application/json']);
$response->assertStatus(500);
$response->assertSee('Could not find the indicated currency.'); // the amount
$response->assertHeader('Content-Type', 'application/json');
}
/**
* Update available budget.