From 395ae5dee1f7153cf08246151ae0810b79dfee7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Sun, 21 Jun 2020 01:27:20 +0300 Subject: [PATCH] added db asserts --- tests/Feature/Auth/PermissionsTest.php | 18 ++++++-- tests/Feature/Auth/RolesTest.php | 25 +++++++++-- tests/Feature/Auth/UsersTest.php | 41 ++++++++++++++++--- tests/Feature/Banking/AccountsTest.php | 18 ++++++-- tests/Feature/Banking/ReconciliationsTest.php | 16 +++++--- tests/Feature/Common/DashboardsTest.php | 29 ++++++++++--- tests/Feature/Common/ItemsTest.php | 18 ++++++-- 7 files changed, 137 insertions(+), 28 deletions(-) diff --git a/tests/Feature/Auth/PermissionsTest.php b/tests/Feature/Auth/PermissionsTest.php index c55779b46..58f5ed146 100644 --- a/tests/Feature/Auth/PermissionsTest.php +++ b/tests/Feature/Auth/PermissionsTest.php @@ -26,16 +26,22 @@ class PermissionsTest extends FeatureTestCase public function testItShouldCreatePermission() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('permissions.store'), $this->getRequest()) + ->post(route('permissions.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('permissions', $request); } public function testItShouldSeePermissionUpdatePage() { - $permission = $this->dispatch(new CreatePermission($this->getRequest())); + $request = $this->getRequest(); + + $permission = $this->dispatch(new CreatePermission($request)); $this->loginAs() ->get(route('permissions.edit', $permission->id)) @@ -57,11 +63,15 @@ class PermissionsTest extends FeatureTestCase ->assertSee($request['display_name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('permissions', $request); } public function testItShouldDeletePermission() { - $permission = $this->dispatch(new CreatePermission($this->getRequest())); + $request = $this->getRequest(); + + $permission = $this->dispatch(new CreatePermission($request)); $this->loginAs() ->delete(route('permissions.destroy', $permission->id)) @@ -69,6 +79,8 @@ class PermissionsTest extends FeatureTestCase $this->assertFlashLevel('success'); + $this->assertDatabaseMissing('permissions', $request); + } public function getRequest() diff --git a/tests/Feature/Auth/RolesTest.php b/tests/Feature/Auth/RolesTest.php index a8888b3ec..f585d78bc 100644 --- a/tests/Feature/Auth/RolesTest.php +++ b/tests/Feature/Auth/RolesTest.php @@ -26,16 +26,22 @@ class RolesTest extends FeatureTestCase public function testItShouldCreateRole() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('roles.store'), $this->getRequest()) + ->post(route('roles.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('roles', $this->getAssertRequest($request)); } public function testItShouldSeeRoleUpdatePage() { - $role = $this->dispatch(new CreateRole($this->getRequest())); + $request = $this->getRequest(); + + $role = $this->dispatch(new CreateRole($request)); $this->loginAs() ->get(route('roles.edit', $role->id)) @@ -57,21 +63,34 @@ class RolesTest extends FeatureTestCase ->assertSee($request['display_name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('roles', $this->getAssertRequest($request)); } public function testItShouldDeleteRole() { - $role = $this->dispatch(new CreateRole($this->getRequest())); + $request = $this->getRequest(); + + $role = $this->dispatch(new CreateRole($request)); $this->loginAs() ->delete(route('roles.destroy', $role->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseMissing('roles', $this->getAssertRequest($request)); } public function getRequest() { return factory(Role::class)->states('permissions')->raw(); } + + public function getAssertRequest($request) + { + unset($request['permissions']); + + return $request; + } } diff --git a/tests/Feature/Auth/UsersTest.php b/tests/Feature/Auth/UsersTest.php index d251d2c66..f383844e3 100644 --- a/tests/Feature/Auth/UsersTest.php +++ b/tests/Feature/Auth/UsersTest.php @@ -26,16 +26,22 @@ class UsersTest extends FeatureTestCase public function testItShouldCreateUser() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('users.store'), $this->getRequest()) + ->post(route('users.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('users', $this->getAssertRequest($request)); } public function testItShouldSeeUserUpdatePage() { - $user = $this->dispatch(new CreateUser($this->getRequest())); + $request = $this->getRequest(); + + $user = $this->dispatch(new CreateUser($request)); $this->loginAs() ->get(route('users.edit', $user->id)) @@ -57,17 +63,23 @@ class UsersTest extends FeatureTestCase ->assertSee($request['email']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('users', $this->getAssertRequest($request)); } public function testItShouldDeleteUser() { - $user = $this->dispatch(new CreateUser($this->getRequest())); + $request = $this->getRequest(); + + $user = $this->dispatch(new CreateUser($request)); $this->loginAs() ->delete(route('users.destroy', $user->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('users', $this->getAssertRequest($request)); } public function testItShouldSeeLoginPage() @@ -79,7 +91,9 @@ class UsersTest extends FeatureTestCase public function testItShouldLoginUser() { - $user = $this->dispatch(new CreateUser($this->getRequest())); + $request = $this->getRequest(); + + $user = $this->dispatch(new CreateUser($request)); $this->post(route('login'), ['email' => $user->email, 'password' => $user->password]) ->assertStatus(200); @@ -89,7 +103,9 @@ class UsersTest extends FeatureTestCase public function testItShouldNotLoginUser() { - $user = $this->dispatch(new CreateUser($this->getRequest())); + $request = $this->getRequest(); + + $user = $this->dispatch(new CreateUser($request)); $this->post(route('login'), ['email' => $user->email, 'password' => $this->faker->password()]) ->assertStatus(200); @@ -99,7 +115,9 @@ class UsersTest extends FeatureTestCase public function testItShouldLogoutUser() { - $user = $this->dispatch(new CreateUser($this->getRequest())); + $request = $this->getRequest(); + + $user = $this->dispatch(new CreateUser($request)); $this->loginAs() ->get(route('logout', $user->id)) @@ -113,4 +131,15 @@ class UsersTest extends FeatureTestCase { return factory(User::class)->states('enabled')->raw(); } + + public function getAssertRequest($request) + { + unset($request['password']); + unset($request['password_confirmation']); + unset($request['remember_token']); + unset($request['roles']); + unset($request['companies']); + + return $request; + } } diff --git a/tests/Feature/Banking/AccountsTest.php b/tests/Feature/Banking/AccountsTest.php index 34ae53172..19264786d 100644 --- a/tests/Feature/Banking/AccountsTest.php +++ b/tests/Feature/Banking/AccountsTest.php @@ -26,16 +26,22 @@ class AccountsTest extends FeatureTestCase public function testItShouldCreateAccount() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('accounts.store'), $this->getRequest()) + ->post(route('accounts.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('accounts', $request); } public function testItShouldSeeAccountUpdatePage() { - $account = $this->dispatch(new CreateAccount($this->getRequest())); + $request = $this->getRequest(); + + $account = $this->dispatch(new CreateAccount($request)); $this->loginAs() ->get(route('accounts.edit', $account->id)) @@ -57,17 +63,23 @@ class AccountsTest extends FeatureTestCase ->assertSee($request['name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('accounts', $request); } public function testItShouldDeleteAccount() { - $account = $this->dispatch(new CreateAccount($this->getRequest())); + $request = $this->getRequest(); + + $account = $this->dispatch(new CreateAccount($request)); $this->loginAs() ->delete(route('accounts.destroy', $account->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('accounts', $request); } public function getRequest() diff --git a/tests/Feature/Banking/ReconciliationsTest.php b/tests/Feature/Banking/ReconciliationsTest.php index ae94d55bd..254d020ea 100644 --- a/tests/Feature/Banking/ReconciliationsTest.php +++ b/tests/Feature/Banking/ReconciliationsTest.php @@ -25,8 +25,10 @@ class ReconciliationsTest extends FeatureTestCase public function testItShouldCreateReconciliation() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('reconciliations.store'), $this->getReconciliationRequest()) + ->post(route('reconciliations.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); @@ -34,7 +36,9 @@ class ReconciliationsTest extends FeatureTestCase public function testItShouldSeeReconciliationUpdatePage() { - $reconciliation = $this->dispatch(new CreateReconciliation($this->getReconciliationRequest())); + $request = $this->getRequest(); + + $reconciliation = $this->dispatch(new CreateReconciliation($request)); $this->loginAs() ->get(route('reconciliations.edit', $reconciliation->id)) @@ -44,7 +48,7 @@ class ReconciliationsTest extends FeatureTestCase public function testItShouldUpdateReconciliation() { - $request = $this->getReconciliationRequest(); + $request = $this->getRequest(); $reconciliation= $this->dispatch(new CreateReconciliation($request)); @@ -59,7 +63,9 @@ class ReconciliationsTest extends FeatureTestCase public function testItShouldDeleteReconciliation() { - $reconciliation = $this->dispatch(new CreateReconciliation($this->getReconciliationRequest())); + $request = $this->getRequest(); + + $reconciliation = $this->dispatch(new CreateReconciliation($request)); $this->loginAs() ->delete(route('reconciliations.destroy', $reconciliation->id)) @@ -68,7 +74,7 @@ class ReconciliationsTest extends FeatureTestCase $this->assertFlashLevel('success'); } - private function getReconciliationRequest() + private function getRequest() { return [ 'company_id' => $this->company->id, diff --git a/tests/Feature/Common/DashboardsTest.php b/tests/Feature/Common/DashboardsTest.php index b8d1166af..142682358 100644 --- a/tests/Feature/Common/DashboardsTest.php +++ b/tests/Feature/Common/DashboardsTest.php @@ -34,16 +34,22 @@ class DashboardsTest extends FeatureTestCase public function testItShouldCreateDashboard() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('dashboards.store'), $this->getRequest()) + ->post(route('dashboards.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); } public function testItShouldSeeDashboardUpdatePage() { - $dashboard = $this->dispatch(new CreateDashboard($this->getRequest())); + $request = $this->getRequest(); + + $dashboard = $this->dispatch(new CreateDashboard($request)); $this->loginAs() ->get(route('dashboards.edit', $dashboard->id)) @@ -65,22 +71,35 @@ class DashboardsTest extends FeatureTestCase ->assertSee($request['name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('dashboards', $this->getAssertRequest($request)); } public function testItShouldDeleteDashboard() { - $dashboard_1 = $this->dispatch(new CreateDashboard($this->getRequest())); - $dashboard_2 = $this->dispatch(new CreateDashboard($this->getRequest())); + $request = $this->getRequest(); + + $tmp = $this->dispatch(new CreateDashboard($this->getRequest())); + $dashboard = $this->dispatch(new CreateDashboard($request)); $this->loginAs() - ->delete(route('dashboards.destroy', $dashboard_2->id)) + ->delete(route('dashboards.destroy', $dashboard->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('dashboards', $this->getAssertRequest($request)); } public function getRequest() { return factory(Dashboard::class)->states('enabled', 'users')->raw(); } + + public function getAssertRequest($request) + { + unset($request['users']); + + return $request; + } } diff --git a/tests/Feature/Common/ItemsTest.php b/tests/Feature/Common/ItemsTest.php index 7d12566ff..221278962 100644 --- a/tests/Feature/Common/ItemsTest.php +++ b/tests/Feature/Common/ItemsTest.php @@ -26,16 +26,22 @@ class ItemsTest extends FeatureTestCase public function testItShouldCreateItem() { + $request = $this->getRequest(); + $this->loginAs() - ->post(route('items.store'), $this->getRequest()) + ->post(route('items.store'), $request) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('items', $request); } public function testItShouldSeeItemUpdatePage() { - $item = $this->dispatch(new CreateItem($this->getRequest())); + $request = $this->getRequest(); + + $item = $this->dispatch(new CreateItem($request)); $this->loginAs() ->get(route('items.edit', $item->id)) @@ -57,17 +63,23 @@ class ItemsTest extends FeatureTestCase ->assertSee($request['name']); $this->assertFlashLevel('success'); + + $this->assertDatabaseHas('items', $request); } public function testItShouldDeleteItem() { - $item = $this->dispatch(new CreateItem($this->getRequest())); + $request = $this->getRequest(); + + $item = $this->dispatch(new CreateItem($request)); $this->loginAs() ->delete(route('items.destroy', $item->id)) ->assertStatus(200); $this->assertFlashLevel('success'); + + $this->assertSoftDeleted('items', $request); } public function getRequest()