added random to tests

This commit is contained in:
denisdulici
2020-01-07 09:29:45 +03:00
parent 44fd928fa1
commit 40a5327f07
6 changed files with 26 additions and 22 deletions

View File

@ -2,7 +2,6 @@
use App\Models\Auth\User;
use App\Models\Banking\Account;
use App\Models\Setting\Currency;
use Faker\Generator as Faker;
$user = User::first();
@ -15,12 +14,11 @@ $factory->define(Account::class, function (Faker $faker) use ($company) {
'company_id' => $company->id,
'name' => $faker->text(5),
'number' => (string) $faker->randomNumber(2),
'currency_code' => setting('default.currency'),
//'currency_code' => Currency::enabled()->get()->random(1)->pluck('code')->first(),
'currency_code' => $company->currencies()->enabled()->get()->random(1)->pluck('code')->first(),
'opening_balance' => '0',
'bank_name' => $faker->text(5),
'bank_phone' => null,
'bank_address' => null,
'bank_phone' => $faker->phoneNumber,
'bank_address' => $faker->address,
'enabled' => $faker->boolean ? 1 : 0,
];
});
@ -36,3 +34,9 @@ $factory->state(Account::class, 'disabled', function (Faker $faker) {
'enabled' => 0,
];
});
$factory->state(Account::class, 'default_currency', function (Faker $faker) {
return [
'currency_code' => setting('default.currency'),
];
});

View File

@ -16,7 +16,7 @@ $factory->define(Item::class, function (Faker $faker) use ($company) {
'description' => $faker->text(100),
'purchase_price' => $faker->randomFloat(2, 10, 20),
'sale_price' => $faker->randomFloat(2, 10, 20),
'category_id' => $company->categories()->type('item')->pluck('id')->first(),
'category_id' => $company->categories()->type('item')->get()->random(1)->pluck('id')->first(),
'tax_id' => null,
'enabled' => $faker->boolean ? 1 : 0,
];

View File

@ -21,7 +21,7 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) {
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'description' => $faker->text(5),
'category_id' => $company->categories()->type($type)->pluck('id')->first(),
'category_id' => $company->categories()->type($type)->get()->random(1)->pluck('id')->first(),
'reference' => $faker->text(5),
'payment_method' => setting('default.payment_method'),
];
@ -30,13 +30,13 @@ $factory->define(Transaction::class, function (Faker $faker) use ($company) {
$factory->state(Transaction::class, 'income', function (Faker $faker) use ($company) {
return [
'type' => 'income',
'category_id' => $company->categories()->type('income')->pluck('id')->first(),
'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(),
];
});
$factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) {
return [
'type' => 'expense',
'category_id' => $company->categories()->type('expense')->pluck('id')->first(),
'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(),
];
});