From d84895b800dbe24792c40f4e4d5517a9a6507905 Mon Sep 17 00:00:00 2001 From: iagirre Date: Thu, 15 Mar 2018 09:41:42 +0100 Subject: [PATCH] Add test suite for the feature The tests that will check the featute is working well added. There are four test: 1. Checks that the emails are been send to the user. The test looks for the link in there and takes the token. Visits the page and changes the password. 2 and 3. Both change the password by hand. One uses a password written by the manager, whilst the other uses the 'Generate random password' option. Both tests check that the user can sign in with the new passwords. 4. Checks that the password can be printed when it is saved. --- spec/features/management/account_spec.rb | 84 +++++++++++++++++++++++- spec/support/common_actions.rb | 10 +++ 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/spec/features/management/account_spec.rb b/spec/features/management/account_spec.rb index 0be7e473bca..df1ca6efd7a 100644 --- a/spec/features/management/account_spec.rb +++ b/spec/features/management/account_spec.rb @@ -6,11 +6,14 @@ login_as_manager end - scenario "Should not allow unverified users to create spending proposals" do + scenario "Should not allow unverified users to edit their account" do user = create(:user) login_managed_user(user) - click_link "Edit user account" + visit management_root_path + + click_link 'Edit user account' + click_link 'Reset password via email' expect(page).to have_content "No verified user logged in yet" end @@ -29,4 +32,81 @@ expect(user.reload.erase_reason).to eq "Deleted by manager: manager_user_#{Manager.last.user_id}" end + scenario "Send reset password email to currently managed user session" do + user = create(:user, :level_three) + login_managed_user(user) + visit management_root_path + + click_link 'Edit user account' + click_link 'Reset password via email' + + click_link 'Send reset password email' + + expect(page).to have_content 'Email correctly sent.' + + email = ActionMailer::Base.deliveries.last + + expect(email).to have_text 'Change your password' + end + + scenario "Manager changes the password by hand (writen by them)" do + user = create(:user, :level_three) + login_managed_user(user) + visit management_root_path + + click_link 'Edit user account' + click_link 'Reset password manually' + + find(:css, "input[id$='user_password']").set("new_password") + + click_button 'Save' + + expect(page).to have_content 'Password reseted successfully' + + logout + + login_through_form_with_email_and_password(user.email, 'new_password') + + expect(page).to have_content 'You have been signed in successfully.' + end + + scenario "Manager generates random password", :js do + user = create(:user, :level_three) + login_managed_user(user) + visit management_root_path + + click_link 'Edit user account' + click_link 'Reset password manually' + click_link 'Generate random password' + + new_password = find_field('user_password').value + + click_button 'Save' + + expect(page).to have_content 'Password reseted successfully' + + logout + + login_through_form_with_email_and_password(user.username, new_password) + + expect(page).to have_content 'You have been signed in successfully.' + end + + scenario "The password is printed", :js do + user = create(:user, :level_three) + login_managed_user(user) + visit management_root_path + + click_link 'Edit user account' + click_link 'Reset password manually' + + find(:css, "input[id$='user_password']").set("another_new_password") + + click_button 'Save' + + expect(page).to have_content 'Password reseted successfully' + expect(page).to have_css("a[href='javascript:window.print();']", text: 'Print password') + expect(page).to have_css("div.for-print-only", text: 'another_new_password', visible: false) + end + end diff --git a/spec/support/common_actions.rb b/spec/support/common_actions.rb index 1704faed174..fb077c26476 100644 --- a/spec/support/common_actions.rb +++ b/spec/support/common_actions.rb @@ -14,6 +14,16 @@ def sign_up(email = 'manuela@consul.dev', password = 'judgementday') click_button 'Register' end + def login_through_form_with_email_and_password(email='manuela@consul.dev', password='judgementday') + visit root_path + click_link 'Sign in' + + fill_in 'user_login', with: email + fill_in 'user_password', with: password + + click_button 'Enter' + end + def login_through_form_as(user) visit root_path click_link 'Sign in'