Skip to content

Commit

Permalink
User Session Controller tests for twitter (#2962)
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthBansal authored and jywarren committed Jul 2, 2018
1 parent 331a73a commit 73b614f
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/functional/user_sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 73b614f

Please sign in to comment.