mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Fix some tests, disable actions for the time being.
This commit is contained in:
@@ -24,7 +24,13 @@ declare(strict_types=1);
|
||||
namespace Tests\Traits;
|
||||
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
@@ -48,6 +54,46 @@ trait CollectsValues
|
||||
return User::where('email', 'no_admin@firefly')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function getRandomWithdrawal(): TransactionJournal
|
||||
{
|
||||
return $this->getRandomJournal(TransactionType::WITHDRAWAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return TransactionJournal
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getRandomJournal(string $type): TransactionJournal
|
||||
{
|
||||
$query = DB::table('transactions')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('transaction_journals.user_id', $this->user()->id)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->where('transaction_types.type', $type)
|
||||
->groupBy('transactions.transaction_journal_id')
|
||||
->having('ct', '=', 2)
|
||||
->inRandomOrder()->take(1);
|
||||
$result = $query->get(
|
||||
[
|
||||
'transactions.transaction_journal_id',
|
||||
'transaction_journals.transaction_type_id',
|
||||
DB::raw('COUNT(transaction_journal_id) as ct'),
|
||||
]
|
||||
)->first();
|
||||
if (null === $result) {
|
||||
throw new FireflyException(sprintf('Cannot find suitable %s to use.', $type));
|
||||
}
|
||||
|
||||
return TransactionJournal::find((int)$result->transaction_journal_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
@@ -55,4 +101,45 @@ trait CollectsValues
|
||||
{
|
||||
return TransactionCurrency::whereCode('EUR')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function getDollar(): TransactionCurrency
|
||||
{
|
||||
return TransactionCurrency::whereCode('USD')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $except
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function getRandomAsset(?int $except = null): Account
|
||||
{
|
||||
return $this->getRandomAccount(AccountType::ASSET, $except);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @param int|null $except
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
private function getRandomAccount(string $type, ?int $except): Account
|
||||
{
|
||||
$query = Account::
|
||||
leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('accounts.user_id', $this->user()->id)
|
||||
->where('account_types.type', $type)
|
||||
->inRandomOrder()->take(1);
|
||||
if (null !== $except) {
|
||||
$query->where('accounts.id', '!=', $except);
|
||||
}
|
||||
return $query->first(['accounts.*']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user