diff --git a/tests/Feature/Auth/LoginTest.php b/tests/Feature/Auth/LoginTest.php new file mode 100644 index 000000000..89db499a5 --- /dev/null +++ b/tests/Feature/Auth/LoginTest.php @@ -0,0 +1,64 @@ +get(route('login')) + ->assertStatus(200) + ->assertSeeText(trans('auth.login_to')); + } + + public function testItShouldLoginUser() + { + $this->post(route('login'), ['email' => $this->user->email, 'password' => $this->user->password]) + ->assertStatus(302) + ->assertRedirect(url('/')); + + $this->isAuthenticated($this->user->user); + } + + public function testItShouldNotLoginUser() + { + $user = factory(User::class)->create([ + 'password' => bcrypt($password = 'correct-password'), + ]); + + $this->post(route('login'), ['email' => $user->email, 'password' != $user->password = $password]) + ->assertStatus(302); + + $this->dontSeeIsAuthenticated(); + } + + public function testItShouldLogoutUser() + { + $user = User::create($this->getLoginRequest()); + + $this->loginAs() + ->get(route('logout',$user->id)) + ->assertStatus(302) + ->assertRedirect(route('login')); + + $this->dontSeeIsAuthenticated(); + } + + private function getLoginRequest() + { + $password = $this->faker->password(); + return[ + 'name' => $this->faker->name, + 'email' => $this->faker->email, + 'password' => $password, + 'companies' => [session('company_id')], + 'roles' => Role::take(1)->pluck('id')->toArray(), + 'enabled' => $this->faker->boolean ? 1 : 0, + ]; + } +} \ No newline at end of file