added currency factory
This commit is contained in:
parent
c0f1587e04
commit
35c11c12ed
39
database/factories/Currency.php
Normal file
39
database/factories/Currency.php
Normal 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]);
|
@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Feature\Settings;
|
namespace Tests\Feature\Settings;
|
||||||
|
|
||||||
use App\Jobs\Setting\CreateCurrency;
|
use App\Jobs\Setting\CreateCurrency;
|
||||||
|
use App\Models\Setting\Currency;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class CurrenciesTest extends FeatureTestCase
|
class CurrenciesTest extends FeatureTestCase
|
||||||
@ -26,7 +27,7 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
public function testItShouldCreateCurrency()
|
public function testItShouldCreateCurrency()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('currencies.store'), $this->getCurrencyRequest())
|
->post(route('currencies.store'), $this->getRequest())
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
@ -34,7 +35,7 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldUpdateCurrency()
|
public function testItShouldUpdateCurrency()
|
||||||
{
|
{
|
||||||
$request = $this->getCurrencyRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$currency = $this->dispatch(new CreateCurrency($request));
|
$currency = $this->dispatch(new CreateCurrency($request));
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldDeleteCurrency()
|
public function testItShouldDeleteCurrency()
|
||||||
{
|
{
|
||||||
$currency = $this->dispatch(new CreateCurrency($this->getCurrencyRequest()));
|
$currency = $this->dispatch(new CreateCurrency($this->getRequest()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('currencies.destroy', $currency->id))
|
->delete(route('currencies.destroy', $currency->id))
|
||||||
@ -58,21 +59,8 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCurrencyRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return [
|
return factory(Currency::class)->states('enabled')->raw();
|
||||||
'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,
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,11 @@
|
|||||||
namespace Tests\Feature\Wizard;
|
namespace Tests\Feature\Wizard;
|
||||||
|
|
||||||
use App\Jobs\Setting\CreateCurrency;
|
use App\Jobs\Setting\CreateCurrency;
|
||||||
|
use App\Models\Setting\Currency;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class CurrenciesTest extends FeatureTestCase
|
class CurrenciesTest extends FeatureTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testItShouldSeeCurrencyListPage()
|
public function testItShouldSeeCurrencyListPage()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
@ -18,7 +18,7 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
public function testItShouldCreateCurrency()
|
public function testItShouldCreateCurrency()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('wizard.currencies.store'), $this->getCurrencyRequest())
|
->post(route('wizard.currencies.store'), $this->getRequest())
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
@ -26,7 +26,7 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldUpdateCurrency()
|
public function testItShouldUpdateCurrency()
|
||||||
{
|
{
|
||||||
$request = $this->getCurrencyRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$currency = $this->dispatch(new CreateCurrency($request));
|
$currency = $this->dispatch(new CreateCurrency($request));
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldDeleteCurrency()
|
public function testItShouldDeleteCurrency()
|
||||||
{
|
{
|
||||||
$currency = $this->dispatch(new CreateCurrency($this->getCurrencyRequest()));
|
$currency = $this->dispatch(new CreateCurrency($this->getRequest()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('wizard.currencies.delete', $currency->id))
|
->delete(route('wizard.currencies.delete', $currency->id))
|
||||||
@ -50,21 +50,8 @@ class CurrenciesTest extends FeatureTestCase
|
|||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCurrencyRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return [
|
return factory(Currency::class)->states('enabled')->raw();
|
||||||
'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
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user