From 5f50e8176ef42299c6c36a95a7f55cd03bab4ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Ba=C5=9F?= Date: Tue, 6 Nov 2018 15:21:27 +0300 Subject: [PATCH] Banking Account Test --- tests/Feature/Banking/AccountsTest.php | 90 ++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/Feature/Banking/AccountsTest.php diff --git a/tests/Feature/Banking/AccountsTest.php b/tests/Feature/Banking/AccountsTest.php new file mode 100644 index 000000000..443e18bff --- /dev/null +++ b/tests/Feature/Banking/AccountsTest.php @@ -0,0 +1,90 @@ +loginAs() + ->get(route('accounts.index')) + ->assertStatus(200) + ->assertSeeText(trans_choice('general.accounts', 2)); + } + + public function testItShouldSeeAccountCreatePage() + { + $this->loginAs() + ->get(route('accounts.create')) + ->assertStatus(200) + ->assertSeeText(trans('general.title.new', ['type' => trans_choice('general.accounts', 1)])); + } + + public function testItShouldCreateAccount() + { + $this->loginAs() + ->post(url('banking/accounts'), $this->getAccountRequest()) + ->assertStatus(302) + ->assertRedirect(url('banking/accounts')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldSeeAccountUpdatePage() + { + $account = Account::create($this->getAccountRequest()); + + $this->loginAs() + ->get(route('accounts.edit', ['account' => $account->id])) + ->assertStatus(200) + ->assertSee($account->name); + } + + public function testItShouldUpdateAccount() + { + $request = $this->getAccountRequest(); + + $account= Account::create($request); + + $request['name'] = $this->faker->text(5); + + $this->loginAs() + ->patch(url('banking/accounts', $account->id), $request) + ->assertStatus(302) + ->assertRedirect(url('banking/accounts')); + + $this->assertFlashLevel('success'); + } + + public function testItShouldDeleteAccount() + { + $account = Account::create($this->getAccountRequest()); + + $this->loginAs() + ->delete(route('accounts.destroy', ['account' => $account])) + ->assertStatus(302) + ->assertRedirect(route('accounts.index')); + + $this->assertFlashLevel('success'); + } + + private function getAccountRequest() + { + return[ + 'company_id' => $this->company->id, + 'name' => $this->faker->text(5), + 'number' => '1', + 'currency_code' => setting('general.default_currency'), + 'opening_balance' => 0, + 'bank_name' => $this->faker->text(5), + 'bank_phone' => null, + 'bank_address' => null, + 'default_account' => $this->faker->randomElement(['yes', 'no']), + 'enabled' => $this->faker->boolean ? 1 : 0, + ]; + } +} +