added currency factory

This commit is contained in:
denisdulici 2020-01-13 02:56:14 +03:00
parent c0f1587e04
commit 35c11c12ed
3 changed files with 51 additions and 37 deletions

View File

@ -0,0 +1,39 @@
<?php
use App\Models\Auth\User;
use App\Models\Setting\Currency;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
$factory->define(Currency::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
$currencies = config('money');
$random = $faker->randomElement($currencies);
$filtered = array_filter($currencies, function ($value) use ($random) {
return ($value['code'] == $random['code']);
});
$code = key($filtered);
$currency = $filtered[$code];
return [
'company_id' => $company->id,
'name' => $currency['name'],
'code' => $code,
'rate' => $faker->randomFloat($currency['precision'], 1, 10),
'precision' => $currency['precision'],
'symbol' => $currency['symbol'],
'symbol_first' => $currency['symbol_first'],
'decimal_mark' => $currency['decimal_mark'],
'thousands_separator' => $currency['thousands_separator'],
'enabled' => $faker->boolean ? 1 : 0,
];
});
$factory->state(Currency::class, 'enabled', ['enabled' => 1]);
$factory->state(Currency::class, 'disabled', ['enabled' => 0]);

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Settings;
use App\Jobs\Setting\CreateCurrency;
use App\Models\Setting\Currency;
use Tests\Feature\FeatureTestCase;
class CurrenciesTest extends FeatureTestCase
@ -26,7 +27,7 @@ class CurrenciesTest extends FeatureTestCase
public function testItShouldCreateCurrency()
{
$this->loginAs()
->post(route('currencies.store'), $this->getCurrencyRequest())
->post(route('currencies.store'), $this->getRequest())
->assertStatus(200);
$this->assertFlashLevel('success');
@ -34,7 +35,7 @@ class CurrenciesTest extends FeatureTestCase
public function testItShouldUpdateCurrency()
{
$request = $this->getCurrencyRequest();
$request = $this->getRequest();
$currency = $this->dispatch(new CreateCurrency($request));
@ -49,7 +50,7 @@ class CurrenciesTest extends FeatureTestCase
public function testItShouldDeleteCurrency()
{
$currency = $this->dispatch(new CreateCurrency($this->getCurrencyRequest()));
$currency = $this->dispatch(new CreateCurrency($this->getRequest()));
$this->loginAs()
->delete(route('currencies.destroy', $currency->id))
@ -58,21 +59,8 @@ class CurrenciesTest extends FeatureTestCase
$this->assertFlashLevel('success');
}
private function getCurrencyRequest()
public function getRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'code' => $this->faker->text(strtoupper(5)),
'rate' => $this->faker->boolean(1),
'precision' => $this->faker->text(5),
'symbol' => $this->faker->text(5),
'symbol_first' => 1,
'symbol_position' => 'after_amount',
'decimal_mark' => $this->faker->text(5),
'thousands_separator' => $this->faker->text(5),
'enabled' => $this->faker->boolean ? 1 : 0,
'default_currency' => 0,
];
return factory(Currency::class)->states('enabled')->raw();
}
}

View File

@ -2,11 +2,11 @@
namespace Tests\Feature\Wizard;
use App\Jobs\Setting\CreateCurrency;
use App\Models\Setting\Currency;
use Tests\Feature\FeatureTestCase;
class CurrenciesTest extends FeatureTestCase
{
public function testItShouldSeeCurrencyListPage()
{
$this->loginAs()
@ -18,7 +18,7 @@ class CurrenciesTest extends FeatureTestCase
public function testItShouldCreateCurrency()
{
$this->loginAs()
->post(route('wizard.currencies.store'), $this->getCurrencyRequest())
->post(route('wizard.currencies.store'), $this->getRequest())
->assertStatus(200);
$this->assertFlashLevel('success');
@ -26,7 +26,7 @@ class CurrenciesTest extends FeatureTestCase
public function testItShouldUpdateCurrency()
{
$request = $this->getCurrencyRequest();
$request = $this->getRequest();
$currency = $this->dispatch(new CreateCurrency($request));
@ -41,7 +41,7 @@ class CurrenciesTest extends FeatureTestCase
public function testItShouldDeleteCurrency()
{
$currency = $this->dispatch(new CreateCurrency($this->getCurrencyRequest()));
$currency = $this->dispatch(new CreateCurrency($this->getRequest()));
$this->loginAs()
->delete(route('wizard.currencies.delete', $currency->id))
@ -50,21 +50,8 @@ class CurrenciesTest extends FeatureTestCase
$this->assertFlashLevel('success');
}
private function getCurrencyRequest()
public function getRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'code' => $this->faker->text(strtoupper(5)),
'rate' => $this->faker->boolean(1),
'precision' => $this->faker->text(5),
'symbol' => $this->faker->text(5),
'symbol_first' => 1,
'symbol_position' => 'after_amount',
'decimal_mark' => $this->faker->text(5),
'thousands_separator' => $this->faker->text(5),
'enabled' => $this->faker->boolean ? 1 : 0,
'default_currency' => 0
];
return factory(Currency::class)->states('enabled')->raw();
}
}