As mentioned in commits likea586ba806,a7664ad81,006128da5,b41fbfa52andc480cdd91, accessing the database after starting the browser with the `visit` method sometimes results in database corruption and failing tests on our CI due to the process running the test accessing the database after the process running the browser has started. IMHO this is also a bad practice for system tests, since these tests should be checking what users experience. So, just like we did a few commits ago with tests that reloaded records, we're modifying the tests to check the results of user interactions from the point of view of the users. Also note we aren't changing tests with the `:no_js` tag, since these tests don't run a real browser in a separate process. In the future, we should also change most of these tests so they don't access the database and they use a real browser. Finally, note that one of the tests we're changing in the shared `notifiable_in_app` file did not check the database content, but we're also changing it for consistency.
115 lines
3.7 KiB
Ruby
115 lines
3.7 KiB
Ruby
require "rails_helper"
|
|
|
|
describe "Users" do
|
|
scenario "Create a level 3 user with email from scratch" do
|
|
login_as_manager
|
|
visit management_document_verifications_path
|
|
fill_in "Document number", with: "12345678Z"
|
|
click_button "Check document"
|
|
|
|
expect(page).to have_content "Please introduce the email used on the account"
|
|
|
|
click_link "Create a new account"
|
|
|
|
fill_in "user_username", with: "pepe"
|
|
fill_in "user_email", with: "pepe@gmail.com"
|
|
fill_in "Date of birth", with: Date.new(1980, 12, 31)
|
|
|
|
click_button "Create user"
|
|
|
|
expect(page).to have_content "We have sent an email"
|
|
expect(page).not_to have_content "Autogenerated password is"
|
|
|
|
visit management_document_verifications_path
|
|
fill_in "Document number", with: "12345678Z"
|
|
click_button "Check document"
|
|
|
|
expect(page).to have_content "This user account is already verified"
|
|
|
|
sent_token = /.*confirmation_token=(.*)".*/.match(ActionMailer::Base.deliveries.last.body.to_s)[1]
|
|
visit user_confirmation_path(confirmation_token: sent_token)
|
|
|
|
expect(page).to have_content "Confirming the account with email"
|
|
|
|
fill_in "user_password", with: "12345678"
|
|
fill_in "user_password_confirmation", with: "12345678"
|
|
|
|
click_button "Confirm"
|
|
|
|
expect(page).to have_content "Your account has been confirmed."
|
|
|
|
visit account_path
|
|
|
|
expect(page).to have_field "Username", with: "pepe"
|
|
expect(page).to have_content "Account verified"
|
|
end
|
|
|
|
scenario "Create a level 3 user without email from scratch" do
|
|
login_as_manager
|
|
visit management_document_verifications_path
|
|
fill_in "document_verification_document_number", with: "12345678Z"
|
|
click_button "Check document"
|
|
|
|
expect(page).to have_content "Please introduce the email used on the account"
|
|
|
|
click_link "Create a new account"
|
|
|
|
fill_in "user_username", with: "Kelly Sue"
|
|
fill_in "user_email", with: ""
|
|
fill_in "Date of birth", with: Date.new(1980, 12, 31)
|
|
|
|
click_button "Create user"
|
|
|
|
expect(page).not_to have_content "We have sent an email"
|
|
generated_password = find("p", text: "Autogenerated password is").find("b").text
|
|
|
|
visit management_document_verifications_path
|
|
fill_in "Document number", with: "12345678Z"
|
|
click_button "Check document"
|
|
|
|
expect(page).to have_content "This user account is already verified"
|
|
|
|
logout
|
|
login_through_form_with("Kelly Sue", password: generated_password)
|
|
|
|
expect(page).to have_content "You have been signed in successfully."
|
|
|
|
visit account_path
|
|
|
|
expect(page).to have_content "Account verified"
|
|
end
|
|
|
|
scenario "Delete a level 2 user account from document verification page" do
|
|
level_2_user = create(:user, :level_two, document_number: "12345678Z")
|
|
manager = create(:manager)
|
|
administrator = create(:administrator)
|
|
|
|
login_as_manager(manager)
|
|
visit management_document_verifications_path
|
|
fill_in "document_verification_document_number", with: "12345678Z"
|
|
click_button "Check document"
|
|
|
|
expect(page).to have_content "This user can participate in the website with the following permissions"
|
|
expect(page).not_to have_content "This user account is already verified."
|
|
|
|
click_link "Delete user"
|
|
accept_confirm { click_button "Delete account" }
|
|
|
|
expect(page).to have_content "User account deleted."
|
|
|
|
fill_in "document_verification_document_number", with: "12345678Z"
|
|
click_button "Check document"
|
|
|
|
expect(page).to have_content "no user account associated to it"
|
|
|
|
logout
|
|
login_as(administrator.user)
|
|
|
|
visit admin_users_path(filter: "erased")
|
|
|
|
within "tr", text: level_2_user.id do
|
|
expect(page).to have_content "Deleted by manager: manager_user_#{manager.user_id}"
|
|
end
|
|
end
|
|
end
|