added category factory

This commit is contained in:
denisdulici 2020-01-12 21:43:54 +03:00
parent 420ee127db
commit f8d8f35925
2 changed files with 41 additions and 12 deletions

View File

@ -0,0 +1,34 @@
<?php
use App\Models\Auth\User;
use App\Models\Setting\Category;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
$factory->define(Category::class, function (Faker $faker) use ($company) {
setting()->setExtraColumns(['company_id' => $company->id]);
$types = ['income', 'expense', 'item', 'other'];
return [
'company_id' => $company->id,
'name' => $faker->text(15),
'type' => $faker->randomElement($types),
'color' => $faker->hexColor,
'enabled' => $faker->boolean ? 1 : 0,
];
});
$factory->state(Category::class, 'enabled', ['enabled' => 1]);
$factory->state(Category::class, 'disabled', ['enabled' => 0]);
$factory->state(Category::class, 'income', ['type' => 'income']);
$factory->state(Category::class, 'expense', ['type' => 'expense']);
$factory->state(Category::class, 'item', ['type' => 'item']);
$factory->state(Category::class, 'other', ['type' => 'other']);

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Settings;
use App\Jobs\Setting\CreateCategory;
use App\Models\Setting\Category;
use Tests\Feature\FeatureTestCase;
class CategoriesTest extends FeatureTestCase
@ -26,7 +27,7 @@ class CategoriesTest extends FeatureTestCase
public function testItShouldCreateCategory()
{
$this->loginAs()
->post(route('categories.store'), $this->getCategoryRequest())
->post(route('categories.store'), $this->getRequest())
->assertStatus(200);
$this->assertFlashLevel('success');
@ -34,7 +35,7 @@ class CategoriesTest extends FeatureTestCase
public function testItShouldSeeCategoryUpdatePage()
{
$category = $this->dispatch(new CreateCategory($this->getCategoryRequest()));
$category = $this->dispatch(new CreateCategory($this->getRequest()));
$this->loginAs()
->get(route('categories.edit', ['category' => $category->id]))
@ -44,7 +45,7 @@ class CategoriesTest extends FeatureTestCase
public function testItShouldUpdateCategory()
{
$request = $this->getCategoryRequest();
$request = $this->getRequest();
$category = $this->dispatch(new CreateCategory($request));
@ -59,7 +60,7 @@ class CategoriesTest extends FeatureTestCase
public function testItShouldDeleteCategory()
{
$category = $this->dispatch(new CreateCategory($this->getCategoryRequest()));
$category = $this->dispatch(new CreateCategory($this->getRequest()));
$this->loginAs()
->delete(route('categories.destroy', $category->id))
@ -68,14 +69,8 @@ class CategoriesTest extends FeatureTestCase
$this->assertFlashLevel('success');
}
private function getCategoryRequest()
public function getRequest()
{
return [
'company_id' => $this->company->id,
'name' => $this->faker->text(15),
'type' => 'item',
'color' => $this->faker->text(15),
'enabled' => $this->faker->boolean ? 1 : 0
];
return factory(Category::class)->states('enabled')->raw();
}
}