Fix unit tests.

This commit is contained in:
James Cole
2018-07-05 20:15:20 +02:00
parent c0d2cd8962
commit 1675a0d442
5 changed files with 37 additions and 26 deletions

View File

@@ -85,8 +85,13 @@ class CurrencyExchangeRateControllerTest extends TestCase
$response->assertStatus(200);
$response->assertJson(
['data' => [
'rate' => 0.5,
'links' => [
'type' => 'currency_exchange_rates',
'id' => '0',
'attributes' => [
'rate' => 0.5,
],
'links' => [
[
'rel' => 'self',
'uri' => '/currency_exchange_rates/',

View File

@@ -1257,7 +1257,7 @@ class TransactionControllerTest extends TestCase
/**
* Show index with range.
*
*
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*/
public function testIndexWithRange(): void
@@ -1274,7 +1274,7 @@ class TransactionControllerTest extends TestCase
$collector->setAllAssetAccounts();
$collector->setLimit(5)->setPage(1);
try {
$paginator = $collector->getPaginatedJournals();
$paginator = $collector->getPaginatedJournals();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
@@ -1324,17 +1324,18 @@ class TransactionControllerTest extends TestCase
/**
* Show a deposit.
*
*
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*/
public function testShowDeposit(): void
{
$loop = 0;
do {
// this is kind of cheating but OK.
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 2)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$loop++;
} while ($count !== 2 && $loop < 30);
$transaction = $journal->transactions()->first();
@@ -1387,19 +1388,21 @@ class TransactionControllerTest extends TestCase
/**
* Show a withdrawal.
*
*
* @covers \FireflyIII\Api\V1\Controllers\TransactionController
*/
public function testShowWithdrawal(): void
{
$loop = 0;
do {
// this is kind of cheating but OK.
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 1)->whereNull('deleted_at')->first();
$count = $journal->transactions()->count();
} while ($count !== 2);
$loop++;
} while ($count !== 2 && $loop < 30);
/** @var Transaction $transaction */
$transaction = $journal->transactions()->first();
$transaction = $journal->transactions()->first();
$transaction->description = null;
$transaction->save();

View File

@@ -139,6 +139,7 @@ class UserControllerTest extends TestCase
// mock
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
$userRepos->shouldReceive('store')->once()->andReturn($this->user());
// test API
@@ -162,7 +163,7 @@ class UserControllerTest extends TestCase
// mock
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
// test API
$response = $this->post('/api/v1/users', $data, ['Accept' => 'application/json']);
$response->assertStatus(422);
@@ -198,6 +199,7 @@ class UserControllerTest extends TestCase
// mock
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('update')->once()->andReturn($user);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
// call API
$response = $this->put('/api/v1/users/' . $user->id, $data);