Simplify login through form as officer in tests

We were always passing `officer.user` to this method, so we might as
well pass the officer (since the "officer" is in the name of the method)
and call `officer.user` inside the method.

We're also calling `login_through_form_as` in order to remove the
duplication between these two methods.
This commit is contained in:
Javi Martín
2025-03-13 01:41:55 +01:00
parent f15991dd3e
commit 55a5cef783
6 changed files with 24 additions and 29 deletions

View File

@@ -34,13 +34,8 @@ module Users
click_button "Enter"
end
def login_through_form_as_officer(user)
visit root_path
click_link "Sign in"
fill_in "user_login", with: user.email
fill_in "user_password", with: user.password
click_button "Enter"
def login_through_form_as_officer(officer)
login_through_form_as(officer.user)
expect(page).to have_content "You have been signed in successfully"
end

View File

@@ -16,7 +16,7 @@ describe "BudgetPolls", :with_frozen_time do
context "Offline" do
scenario "A citizen can cast a paper vote" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -46,7 +46,7 @@ describe "BudgetPolls", :with_frozen_time do
end
scenario "A citizen cannot vote offline again" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -66,7 +66,7 @@ describe "BudgetPolls", :with_frozen_time do
end
scenario "A citizen cannot vote online after voting offline" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -127,7 +127,7 @@ describe "BudgetPolls", :with_frozen_time do
end
logout
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence

View File

@@ -4,7 +4,7 @@ describe "Booth", :with_frozen_time do
scenario "Officer with no booth assignments today" do
officer = create(:poll_officer)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
expect(page).to have_content "You don't have officing shifts today"
@@ -14,7 +14,7 @@ describe "Booth", :with_frozen_time do
officer = create(:poll_officer)
create(:poll_officer_assignment, officer: officer, date: Date.current + 1.day)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
expect(page).to have_content "You don't have officing shifts today"
@@ -28,7 +28,7 @@ describe "Booth", :with_frozen_time do
create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth, date: Date.current)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
within("#officing-booth") do
@@ -46,7 +46,7 @@ describe "Booth", :with_frozen_time do
create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth1, date: Date.current)
create(:poll_officer_assignment, officer: officer, poll: poll, booth: booth2, date: Date.current)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
expect(page).to have_content "Choose your booth"
@@ -72,7 +72,7 @@ describe "Booth", :with_frozen_time do
create(:poll_officer_assignment, officer: officer, poll: poll2, booth: booth2, date: Date.current)
create(:poll_officer_assignment, officer: officer, poll: poll2, booth: booth2, date: Date.current)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
expect(page).to have_content "Choose your booth"

View File

@@ -22,7 +22,7 @@ describe "Residence", :with_frozen_time do
describe "Assigned officers" do
before do
create(:poll_officer_assignment, officer: officer)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit officing_root_path
end
@@ -112,7 +112,7 @@ describe "Residence", :with_frozen_time do
scenario "by default (without custom census) not display date_of_birth and postal_code" do
Setting["feature.remote_census"] = false
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit officing_root_path
within("#side_menu") do
@@ -127,7 +127,7 @@ describe "Residence", :with_frozen_time do
end
scenario "with all custom census not display year_of_birth" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit officing_root_path
within("#side_menu") do
@@ -145,7 +145,7 @@ describe "Residence", :with_frozen_time do
scenario "can verify voter with date_of_birth and postal_code fields" do
mock_valid_remote_census_response
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit officing_root_path
within("#side_menu") do

View File

@@ -73,7 +73,7 @@ describe "Voters" do
expect(user).not_to be_level_two_verified
logout
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence

View File

@@ -74,7 +74,7 @@ describe "Voter" do
end
scenario "Voting in booth" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -107,7 +107,7 @@ describe "Voter" do
before { create(:user, :in_census) }
scenario "Show not to vote at this time button" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -119,7 +119,7 @@ describe "Voter" do
end
scenario "Hides not to vote at this time button if already voted" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -148,7 +148,7 @@ describe "Voter" do
expect(Poll::Voter.count).to eq(1)
logout
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -159,7 +159,7 @@ describe "Voter" do
end
scenario "Trying to vote in booth and then in web" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
vote_for_poll_via_booth
@@ -192,7 +192,7 @@ describe "Voter" do
allow_any_instance_of(Verification::Sms).to receive(:generate_confirmation_code).and_return("1357")
user = create(:user)
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
vote_for_poll_via_booth
logout
@@ -228,7 +228,7 @@ describe "Voter" do
context "Side menu" do
scenario "'Validate document' menu item with votable polls" do
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence
@@ -252,7 +252,7 @@ describe "Voter" do
scenario "'Validate document' menu item without votable polls" do
create(:poll_voter, poll: poll, user: create(:user, :in_census))
login_through_form_as_officer(officer.user)
login_through_form_as_officer(officer)
visit new_officing_residence_path
officing_verify_residence