Skip to content

Commit

Permalink
User Session Controller tests for Facebook (publiclab#2966)
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthBansal authored and jywarren committed Jul 2, 2018
1 parent 6b6f3eb commit 83d6c7c
Showing 1 changed file with 68 additions and 11 deletions.
79 changes: 68 additions & 11 deletions test/functional/user_sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,67 @@ class UserSessionsControllerTest < ActionController::TestCase
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]

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

test 'sign up and login via provider basic flow for facebook' do
assert_not_nil OmniAuth.config.mock_auth[:facebook1]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter1]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook1]
assert_not_nil request.env['omniauth.auth']
#Sign Up for a new user
post :create
Expand All @@ -170,10 +227,10 @@ class UserSessionsControllerTest < ActionController::TestCase
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]
test 'sign up and login via provider alternative flow for facebook' do
assert_not_nil OmniAuth.config.mock_auth[:facebook2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook2]
assert_not_nil request.env['omniauth.auth']
#Sign Up for an existing user as email exists in the db
post :create
Expand All @@ -186,7 +243,7 @@ class UserSessionsControllerTest < ActionController::TestCase
assert_equal "Signed in!", flash[:notice]
end

test 'login user with an email and then contwitter provider' do
test 'login user with an email and then connect facebook provider' do
post :create,
params: {
user_session: {
Expand All @@ -195,14 +252,14 @@ class UserSessionsControllerTest < ActionController::TestCase
}
}
assert_redirected_to '/dashboard'
assert_not_nil OmniAuth.config.mock_auth[:twitter2]
assert_not_nil OmniAuth.config.mock_auth[:facebook2]
#Omniauth hash is present
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:twitter2]
request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:facebook2]
assert_not_nil request.env['omniauth.auth']
#Link a twitter account to an existing user
#Link a facebook 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
#Link same facebook account to an existing user again
post :create
assert_equal "Already linked to your account!", flash[:notice]
#Log Out
Expand Down

0 comments on commit 83d6c7c

Please sign in to comment.