Transfer test refactored
This commit is contained in:
@ -4,15 +4,10 @@ namespace Database\Factories;
|
||||
|
||||
use App\Abstracts\Factory;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Banking\Transfer as Model;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Traits\Categories;
|
||||
|
||||
class Transfer extends Factory
|
||||
{
|
||||
use Categories;
|
||||
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
@ -27,42 +22,20 @@ class Transfer extends Factory
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
$accounts = Account::enabled()->get();
|
||||
$from_account = Account::factory()->enabled()->default_currency()->create();
|
||||
|
||||
if ($accounts->count() >= 2) {
|
||||
$random = $accounts->random(2);
|
||||
|
||||
$expense_account = $random->first();
|
||||
$income_account = $random->last();
|
||||
} else {
|
||||
$expense_account = $accounts->first();
|
||||
|
||||
$income_account = Account::factory()->enabled()->default_currency()->create();
|
||||
}
|
||||
|
||||
$request = [
|
||||
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
||||
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'),
|
||||
'category_id' => $this->getTransferCategoryId(),
|
||||
'description' => $this->faker->text(20),
|
||||
'reference' => $this->faker->text(20),
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
|
||||
$expense_transaction = Transaction::factory()->create(array_merge($request, [
|
||||
'type' => Transaction::EXPENSE_TRANSFER_TYPE,
|
||||
'account_id' => $expense_account->id,
|
||||
]));
|
||||
|
||||
$income_transaction = Transaction::factory()->create(array_merge($request, [
|
||||
'type' => Transaction::INCOME_TRANSFER_TYPE,
|
||||
'account_id' => $income_account->id,
|
||||
]));
|
||||
$to_account = Account::factory()->enabled()->default_currency()->create();
|
||||
|
||||
return [
|
||||
'company_id' => $this->company->id,
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
'from_account_id' => $from_account->id,
|
||||
'to_account_id' => $to_account->id,
|
||||
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
||||
'transferred_at' => $this->faker->date(),
|
||||
'description'=> $this->faker->text(20),
|
||||
'payment_method' => setting('default.payment_method'),
|
||||
'reference' => $this->faker->text(20),
|
||||
'created_from' => 'core::factory',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user