From f8d8f3592585eb45bb2c2c64e09b626f7dbd30f7 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Sun, 12 Jan 2020 21:43:54 +0300 Subject: [PATCH] added category factory --- database/factories/Category.php | 34 +++++++++++++++++++++++ tests/Feature/Settings/CategoriesTest.php | 19 +++++-------- 2 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 database/factories/Category.php diff --git a/database/factories/Category.php b/database/factories/Category.php new file mode 100644 index 000000000..c8ed5c9a5 --- /dev/null +++ b/database/factories/Category.php @@ -0,0 +1,34 @@ +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']); diff --git a/tests/Feature/Settings/CategoriesTest.php b/tests/Feature/Settings/CategoriesTest.php index 98360c1f1..08f0110cd 100644 --- a/tests/Feature/Settings/CategoriesTest.php +++ b/tests/Feature/Settings/CategoriesTest.php @@ -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(); } }