diff --git a/test/functional/user_sessions_controller_test.rb b/test/functional/user_sessions_controller_test.rb index 5b3103e934..f02563c4b1 100644 --- a/test/functional/user_sessions_controller_test.rb +++ b/test/functional/user_sessions_controller_test.rb @@ -153,4 +153,60 @@ class UserSessionsControllerTest < ActionController::TestCase post :destroy assert_equal "Successfully logged out.", flash[:notice] end + + test 'sign up and login via provider basic flow for twitter' do + assert_not_nil OmniAuth.config.mock_auth[:twitter1] + #Omniauth hash is present + request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter1] + assert_not_nil request.env['omniauth.auth'] + #Sign Up for a new user + post :create + assert_equal "You have successfully signed in. Please change your password via a link sent to you via a mail", flash[:notice] + #Log Out + post :destroy + assert_equal "Successfully logged out.", flash[:notice] + #auth hash is present so login via a provider + post :create + assert_equal "Signed in!", flash[:notice] + end + + test 'sign up and login via provider alternative flow for twitter' do + assert_not_nil OmniAuth.config.mock_auth[:twitter2] + #Omniauth hash is present + request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2] + assert_not_nil request.env['omniauth.auth'] + #Sign Up for an existing user as email exists in the db + post :create + assert_equal "Successfully linked to your account!", flash[:notice] + #Log Out + post :destroy + assert_equal "Successfully logged out.", flash[:notice] + #auth hash is present so login via a provider + post :create + assert_equal "Signed in!", flash[:notice] + end + + test 'login user with an email and then contwitter provider' do + post :create, + params: { + user_session: { + username: users(:jeff).email, + password: 'secretive' + } + } + assert_redirected_to '/dashboard' + assert_not_nil OmniAuth.config.mock_auth[:twitter2] + #Omniauth hash is present + request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2] + assert_not_nil request.env['omniauth.auth'] + #Link a twitter account to an existing user + post :create + assert_equal "Successfully linked to your account!", flash[:notice] + #Link same twitter account to an existing user again + post :create + assert_equal "Already linked to your account!", flash[:notice] + #Log Out + post :destroy + assert_equal "Successfully logged out.", flash[:notice] + end end