From 83d6c7c7c1e0badf0078cef3aef2e2707342f50e Mon Sep 17 00:00:00 2001 From: Sidharth Bansal Date: Tue, 3 Jul 2018 02:40:22 +0530 Subject: [PATCH] User Session Controller tests for Facebook (#2966) --- .../user_sessions_controller_test.rb | 79 ++++++++++++++++--- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/test/functional/user_sessions_controller_test.rb b/test/functional/user_sessions_controller_test.rb index f02563c4b1a..3d2ee1cc7f1 100644 --- a/test/functional/user_sessions_controller_test.rb +++ b/test/functional/user_sessions_controller_test.rb @@ -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 @@ -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 @@ -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: { @@ -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