transfer factory
This commit is contained in:
parent
f8453ad2d7
commit
3d72265cfd
@ -8,15 +8,16 @@ $user = User::first();
|
||||
$company = $user->companies()->first();
|
||||
|
||||
$factory->define(Account::class, function (Faker $faker) use ($company) {
|
||||
session(['company_id' => $company->id]);
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
|
||||
return [
|
||||
'company_id' => $company->id,
|
||||
'name' => $faker->text(5),
|
||||
'number' => (string) $faker->randomNumber(2),
|
||||
'name' => $faker->text(15),
|
||||
'number' => (string) $faker->iban(),
|
||||
'currency_code' => $company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
|
||||
'opening_balance' => '0',
|
||||
'bank_name' => $faker->text(5),
|
||||
'bank_name' => $faker->text(15),
|
||||
'bank_phone' => $faker->phoneNumber,
|
||||
'bank_address' => $faker->address,
|
||||
'enabled' => $faker->boolean ? 1 : 0,
|
||||
@ -27,4 +28,11 @@ $factory->state(Account::class, 'enabled', ['enabled' => 1]);
|
||||
|
||||
$factory->state(Account::class, 'disabled', ['enabled' => 0]);
|
||||
|
||||
$factory->state(Account::class, 'default_currency', ['currency_code' => setting('default.currency')]);
|
||||
$factory->state(Account::class, 'default_currency', function (Faker $faker) use ($company) {
|
||||
session(['company_id' => $company->id]);
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
|
||||
return [
|
||||
'currency_code' => setting('default.currency'),
|
||||
];
|
||||
});
|
||||
|
53
database/factories/Transfer.php
Normal file
53
database/factories/Transfer.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Auth\User;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Banking\Transfer;
|
||||
use App\Models\Setting\Category;
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$user = User::first();
|
||||
$company = $user->companies()->first();
|
||||
|
||||
$factory->define(Transfer::class, function (Faker $faker) use ($company) {
|
||||
session(['company_id' => $company->id]);
|
||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||
|
||||
$accounts = Account::enabled()->get();
|
||||
|
||||
if ($accounts->count() >= 2) {
|
||||
$random = $accounts->random(2);
|
||||
|
||||
$expense_account = $random->first();
|
||||
$income_account = $random->last();
|
||||
} else {
|
||||
$expense_account = $accounts->first();
|
||||
|
||||
$income_account = factory(Account::class)->states('enabled', 'default_currency')->create();
|
||||
}
|
||||
|
||||
$request = [
|
||||
'amount' => $faker->randomFloat(2, 1, 1000),
|
||||
'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'),
|
||||
'category_id' => Category::transfer(),
|
||||
'description' => $faker->text(20),
|
||||
'reference' => $faker->text(20),
|
||||
];
|
||||
|
||||
$expense_transaction = factory(Transaction::class)->create(array_merge($request, [
|
||||
'type' => 'expense',
|
||||
'account_id' => $expense_account->id,
|
||||
]));
|
||||
|
||||
$income_transaction = factory(Transaction::class)->create(array_merge($request, [
|
||||
'type' => 'income',
|
||||
'account_id' => $income_account->id,
|
||||
]));
|
||||
|
||||
return [
|
||||
'company_id' => $company->id,
|
||||
'expense_transaction_id' => $expense_transaction->id,
|
||||
'income_transaction_id' => $income_transaction->id,
|
||||
];
|
||||
});
|
@ -49,7 +49,7 @@ class AccountsTest extends FeatureTestCase
|
||||
|
||||
$account = $this->dispatch(new CreateAccount($request));
|
||||
|
||||
$request['name'] = $this->faker->text(5);
|
||||
$request['name'] = $this->faker->text(10);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('accounts.update', $account->id), $request)
|
||||
|
@ -49,7 +49,7 @@ class TransfersTest extends FeatureTestCase
|
||||
|
||||
$transfer = $this->dispatch(new CreateTransfer($request));
|
||||
|
||||
$request['description'] = $this->faker->text(10);
|
||||
$request['description'] = $this->faker->text(15);
|
||||
|
||||
$this->loginAs()
|
||||
->patch(route('transfers.update', $transfer->id), $request)
|
||||
@ -79,11 +79,11 @@ class TransfersTest extends FeatureTestCase
|
||||
'company_id' => $this->company->id,
|
||||
'from_account_id' => $from_account->id,
|
||||
'to_account_id' => $to_account->id,
|
||||
'amount' => $this->faker->randomFloat(2, 2, 1000),
|
||||
'amount' => $this->faker->randomFloat(2, 1, 1000),
|
||||
'transferred_at' => $this->faker->date(),
|
||||
'description'=> $this->faker->text(5),
|
||||
'description'=> $this->faker->text(20),
|
||||
'payment_method' => setting('default.payment_method'),
|
||||
'reference' => $this->faker->text(5),
|
||||
'reference' => $this->faker->text(20),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user