mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Fix unit tests.
This commit is contained in:
@@ -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/',
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -36,12 +36,14 @@ class FromAccountStartsTest extends TestCase
|
||||
*/
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$transaction = null;
|
||||
$count = 0;
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
} while (null === $transaction);
|
||||
$account = $transaction->account;
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings(substr($account->name, 0, -3), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -53,13 +55,14 @@ class FromAccountStartsTest extends TestCase
|
||||
*/
|
||||
public function testTriggeredLonger(): void
|
||||
{
|
||||
$transaction = null;
|
||||
$count = 0;
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
} while (null === $transaction);
|
||||
|
||||
$account = $transaction->account;
|
||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
|
||||
$trigger = FromAccountStarts::makeFromStrings('bla-bla-bla' . $account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
@@ -37,14 +37,13 @@ class ToAccountIsTest extends TestCase
|
||||
public function testTriggered(): void
|
||||
{
|
||||
$count = 0;
|
||||
$transactionCount = 0;
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 1);
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings($account->name, false);
|
||||
$result = $trigger->triggered($journal);
|
||||
@@ -57,14 +56,13 @@ class ToAccountIsTest extends TestCase
|
||||
public function testTriggeredNot(): void
|
||||
{
|
||||
$count = 0;
|
||||
$transactionCount = 0;
|
||||
do {
|
||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||
$transactionCount = $journal->transactions()->count();
|
||||
$account = $transaction->account;
|
||||
$count++;
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 1);
|
||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||
|
||||
$trigger = ToAccountIs::makeFromStrings('some name' . random_int(1, 234), false);
|
||||
$result = $trigger->triggered($journal);
|
||||
|
Reference in New Issue
Block a user