From 1be4cc78f50b4c1d9f354d21d171c62a025696be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ba=C5=9F?= Date: Thu, 4 Oct 2018 16:53:16 +0300 Subject: [PATCH] Tests for Settings --- tests/Feature/Settings/CategoriesTest.php | 84 +++++++++++++++++++++++ tests/Feature/Settings/CurrenciesTest.php | 83 ++++++++++++++++++++++ tests/Feature/Settings/TaxesTest.php | 73 ++++++++++++++++++++ 3 files changed, 240 insertions(+) create mode 100644 tests/Feature/Settings/CategoriesTest.php create mode 100644 tests/Feature/Settings/CurrenciesTest.php create mode 100644 tests/Feature/Settings/TaxesTest.php diff --git a/tests/Feature/Settings/CategoriesTest.php b/tests/Feature/Settings/CategoriesTest.php new file mode 100644 index 000000000..fd6e27fc5 --- /dev/null +++ b/tests/Feature/Settings/CategoriesTest.php @@ -0,0 +1,84 @@ +loginAs() + ->get(route('categories.index')) + ->assertStatus(200) + ->assertSeeText(trans_choice('general.categories', 2)); + } + + public function testItShouldSeeCategoryCreatePage() + { + $this->loginAs() + ->get(route('categories.create')) + ->assertStatus(200) + ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.categories', 1)])); + } + + public function testItShouldCreateCategory() + { + $this->loginAs() + ->post(route('categories.store'), $this->getCategoryRequest()) + ->assertStatus(302) + ->assertRedirect(route('categories.index')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldSeeCategoryUpdatePage() + { + $category = Category::create($this->getCategoryRequest()); + + $this->loginAs() + ->get(route('categories.edit', ['category' => $category->id])) + ->assertStatus(200) + ->assertSee($category->name); + } + + public function testItShouldUpdateCategory() + { + $request = $this->getCategoryRequest(); + + $category = Category::create($request); + + $request['name'] = $this->faker->text(15); + + $this->loginAs() + ->patch(route('categories.update', $category->id), $request) + ->assertStatus(302) + ->assertRedirect(route('categories.index')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldDeleteCategory() + { + $category = Category::create($this->getCategoryRequest()); + + $this->loginAs() + ->delete(route('categories.destroy', $category->id)) + ->assertStatus(302) + ->assertRedirect(route('categories.index')); + + $this->assertFlashLevel('success'); + } + + private function getCategoryRequest() + { + return [ + 'company_id' => $this->company->id, + 'name' => $this->faker->text(15), + 'type' => 'other', + 'color' => $this->faker->text(15), + 'enabled' => $this->faker->boolean ? 1 : 0 + ]; + } +} \ No newline at end of file diff --git a/tests/Feature/Settings/CurrenciesTest.php b/tests/Feature/Settings/CurrenciesTest.php new file mode 100644 index 000000000..f2ab49132 --- /dev/null +++ b/tests/Feature/Settings/CurrenciesTest.php @@ -0,0 +1,83 @@ +loginAs() + ->get(route('currencies.index')) + ->assertStatus(200) + ->assertSeeText(trans_choice('general.currencies', 2)); + } + + public function testItShouldSeeCurrencyCreatePage() + { + $this->loginAs() + ->get(route('currencies.create')) + ->assertStatus(200) + ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.currencies', 1)])); + } + + public function testItShouldCreateCurrency() + { + $this->loginAs() + ->post(route('currencies.store'), $this->getCurrencyRequest()) + ->assertStatus(302) + ->assertRedirect(route('currencies.index')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldUpdateCurrency() + { + $request = $this->getCurrencyRequest(); + + $currency = Currency::create($request); + + $request['name'] = $this->faker->text(15); + + $this->loginAs() + ->patch(route('currencies.update', $currency->id), $request) + ->assertStatus(302) + ->assertRedirect(route('currencies.index')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldDeleteCurrency() + { + $currency = Currency::create($this->getCurrencyRequest()); + + $this->loginAs() + ->delete(route('currencies.destroy', $currency->id)) + ->assertStatus(302) + ->assertRedirect(route('currencies.index')); + + $this->assertFlashLevel('success'); + } + + + private function getCurrencyRequest() + { + return [ + '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' => $this->faker->boolean ? 1 : 0 + ]; + } +} \ No newline at end of file diff --git a/tests/Feature/Settings/TaxesTest.php b/tests/Feature/Settings/TaxesTest.php new file mode 100644 index 000000000..0e64de59d --- /dev/null +++ b/tests/Feature/Settings/TaxesTest.php @@ -0,0 +1,73 @@ +loginAs() + ->get(route('taxes.index')) + ->assertStatus(200) + ->assertSeeText(trans_choice('general.tax_rates', 2)); + } + + public function testItShouldSeeTaxCreatePage() + { + $this->loginAs() + ->get(route('taxes.create')) + ->assertStatus(200) + ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.taxes', 1)])); + } + + public function testItShouldCreateTax() + { + $this->loginAs() + ->post(route('taxes.store'), $this->getTaxRequest()) + ->assertStatus(302) + ->assertRedirect(route('taxes.index')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldUpdateTax() + { + $request = $this->getTaxRequest(); + + $tax = Tax::create($request); + + $request['name'] = $this->faker->text(15); + + $this->loginAs() + ->patch(route('taxes.update', $tax->id), $request) + ->assertStatus(302) + ->assertRedirect(route('taxes.index')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldDeleteTax() + { + $tax = Tax::create($this->getTaxRequest()); + + $this->loginAs() + ->delete(route('taxes.destroy', $tax->id)) + ->assertStatus(302) + ->assertRedirect(route('taxes.index')); + + $this->assertFlashLevel('success'); + } + + private function getTaxRequest() + { + return [ + 'company_id' => $this->company->id, + 'name' => $this->faker->text(15), + 'rate' => $this->faker->randomFloat(2, 10, 20), + 'enabled' => $this->faker->boolean ? 1 : 0 + ]; + } +} \ No newline at end of file