added tax factory

This commit is contained in:
denisdulici
2020-01-12 21:52:21 +03:00
parent f8d8f35925
commit ee755c9c61
2 changed files with 40 additions and 11 deletions

View File

@ -0,0 +1,34 @@
<?php
use App\Models\Auth\User;
use App\Models\Setting\Tax;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
$factory->define(Tax::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
$types = ['normal', 'inclusive', 'compound', 'fixed'];
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'rate' => $faker->randomFloat(2, 10, 20),
'type' => $faker->randomElement($types),
'enabled' => $faker->boolean ? 1 : 0,
];
});
$factory->state(Tax::class, 'enabled', ['enabled' => 1]);
$factory->state(Tax::class, 'disabled', ['enabled' => 0]);
$factory->state(Tax::class, 'normal', ['type' => 'normal']);
$factory->state(Tax::class, 'inclusive', ['type' => 'inclusive']);
$factory->state(Tax::class, 'compound', ['type' => 'compound']);
$factory->state(Tax::class, 'fixed', ['type' => 'fixed']);

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Settings; namespace Tests\Feature\Settings;
use App\Jobs\Setting\CreateTax; use App\Jobs\Setting\CreateTax;
use App\Models\Setting\Tax;
use Tests\Feature\FeatureTestCase; use Tests\Feature\FeatureTestCase;
class TaxesTest extends FeatureTestCase class TaxesTest extends FeatureTestCase
@ -26,7 +27,7 @@ class TaxesTest extends FeatureTestCase
public function testItShouldCreateTax() public function testItShouldCreateTax()
{ {
$this->loginAs() $this->loginAs()
->post(route('taxes.store'), $this->getTaxRequest()) ->post(route('taxes.store'), $this->getRequest())
->assertStatus(200); ->assertStatus(200);
$this->assertFlashLevel('success'); $this->assertFlashLevel('success');
@ -34,7 +35,7 @@ class TaxesTest extends FeatureTestCase
public function testItShouldUpdateTax() public function testItShouldUpdateTax()
{ {
$request = $this->getTaxRequest(); $request = $this->getRequest();
$tax = $this->dispatch(new CreateTax($request)); $tax = $this->dispatch(new CreateTax($request));
@ -49,7 +50,7 @@ class TaxesTest extends FeatureTestCase
public function testItShouldDeleteTax() public function testItShouldDeleteTax()
{ {
$tax = $this->dispatch(new CreateTax($this->getTaxRequest())); $tax = $this->dispatch(new CreateTax($this->getRequest()));
$this->loginAs() $this->loginAs()
->delete(route('taxes.destroy', $tax->id)) ->delete(route('taxes.destroy', $tax->id))
@ -58,14 +59,8 @@ class TaxesTest extends FeatureTestCase
$this->assertFlashLevel('success'); $this->assertFlashLevel('success');
} }
private function getTaxRequest() public function getRequest()
{ {
return [ return factory(Tax::class)->states('enabled')->raw();
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'rate' => $this->faker->randomFloat(2, 10, 20),
'type' => $this->faker->randomElement(['normal', 'inclusive', 'compound']),
'enabled' => $this->faker->boolean ? 1 : 0
];
} }
} }