added category factory
This commit is contained in:
parent
420ee127db
commit
f8d8f35925
34
database/factories/Category.php
Normal file
34
database/factories/Category.php
Normal 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']);
|
@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Feature\Settings;
|
namespace Tests\Feature\Settings;
|
||||||
|
|
||||||
use App\Jobs\Setting\CreateCategory;
|
use App\Jobs\Setting\CreateCategory;
|
||||||
|
use App\Models\Setting\Category;
|
||||||
use Tests\Feature\FeatureTestCase;
|
use Tests\Feature\FeatureTestCase;
|
||||||
|
|
||||||
class CategoriesTest extends FeatureTestCase
|
class CategoriesTest extends FeatureTestCase
|
||||||
@ -26,7 +27,7 @@ class CategoriesTest extends FeatureTestCase
|
|||||||
public function testItShouldCreateCategory()
|
public function testItShouldCreateCategory()
|
||||||
{
|
{
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->post(route('categories.store'), $this->getCategoryRequest())
|
->post(route('categories.store'), $this->getRequest())
|
||||||
->assertStatus(200);
|
->assertStatus(200);
|
||||||
|
|
||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
@ -34,7 +35,7 @@ class CategoriesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldSeeCategoryUpdatePage()
|
public function testItShouldSeeCategoryUpdatePage()
|
||||||
{
|
{
|
||||||
$category = $this->dispatch(new CreateCategory($this->getCategoryRequest()));
|
$category = $this->dispatch(new CreateCategory($this->getRequest()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->get(route('categories.edit', ['category' => $category->id]))
|
->get(route('categories.edit', ['category' => $category->id]))
|
||||||
@ -44,7 +45,7 @@ class CategoriesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldUpdateCategory()
|
public function testItShouldUpdateCategory()
|
||||||
{
|
{
|
||||||
$request = $this->getCategoryRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
$category = $this->dispatch(new CreateCategory($request));
|
$category = $this->dispatch(new CreateCategory($request));
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ class CategoriesTest extends FeatureTestCase
|
|||||||
|
|
||||||
public function testItShouldDeleteCategory()
|
public function testItShouldDeleteCategory()
|
||||||
{
|
{
|
||||||
$category = $this->dispatch(new CreateCategory($this->getCategoryRequest()));
|
$category = $this->dispatch(new CreateCategory($this->getRequest()));
|
||||||
|
|
||||||
$this->loginAs()
|
$this->loginAs()
|
||||||
->delete(route('categories.destroy', $category->id))
|
->delete(route('categories.destroy', $category->id))
|
||||||
@ -68,14 +69,8 @@ class CategoriesTest extends FeatureTestCase
|
|||||||
$this->assertFlashLevel('success');
|
$this->assertFlashLevel('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCategoryRequest()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return [
|
return factory(Category::class)->states('enabled')->raw();
|
||||||
'company_id' => $this->company->id,
|
|
||||||
'name' => $this->faker->text(15),
|
|
||||||
'type' => 'item',
|
|
||||||
'color' => $this->faker->text(15),
|
|
||||||
'enabled' => $this->faker->boolean ? 1 : 0
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user