diff --git a/spec/support/dfe_sign_in_user_helper.rb b/spec/support/dfe_sign_in_user_helper.rb index a91e4a413..440dfbda4 100644 --- a/spec/support/dfe_sign_in_user_helper.rb +++ b/spec/support/dfe_sign_in_user_helper.rb @@ -1,4 +1,21 @@ module DfESignInUserHelper + def sign_in_placements_user(organisations: [], with_dfe_sign_id: true, sign_in: true) + @current_user = create(:placements_user) + @current_user.update!(dfe_sign_in_uid: nil) unless with_dfe_sign_id + organisations.each do |organisation| + create(:user_membership, user: @current_user, organisation:) + end + sign_in ? sign_in_as(@current_user) : user_exists_in_dfe_sign_in(user: @current_user) + end + alias_method :given_i_am_signed_in_as_a_placements_user, :sign_in_placements_user + + def sign_in_placements_support_user(with_dfe_sign_id: true, sign_in: true) + @current_user = create(:placements_support_user) + @current_user.update!(dfe_sign_in_uid: nil) unless with_dfe_sign_id + sign_in ? sign_in_as(@current_user) : user_exists_in_dfe_sign_in(user: @current_user) + end + alias_method :given_i_am_signed_in_as_a_placements_support_user, :sign_in_placements_support_user + def sign_in_as(user) user_exists_in_dfe_sign_in(user:) diff --git a/spec/support/shared_examples/system/placements/edit_a_placement_wizard.rb b/spec/support/shared_examples/system/placements/edit_a_placement_wizard.rb index e5d4a47b4..09b2f1134 100644 --- a/spec/support/shared_examples/system/placements/edit_a_placement_wizard.rb +++ b/spec/support/shared_examples/system/placements/edit_a_placement_wizard.rb @@ -387,14 +387,6 @@ private - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def then_i_should_see_the_mentor_name_in_the_placement_details( mentor_name:, change_link: "Change" ) diff --git a/spec/system/good_job_dashboard_spec.rb b/spec/system/good_job_dashboard_spec.rb index 450dd0706..47819b7f1 100644 --- a/spec/system/good_job_dashboard_spec.rb +++ b/spec/system/good_job_dashboard_spec.rb @@ -2,13 +2,13 @@ RSpec.describe "GoodJob admin dashboard", service: :placements, type: :system do scenario "Access the dashboard as a support user" do - given_i_am_a_support_user + given_i_am_signed_in_as_a_placements_support_user when_i_go_to_the_dashboard_path then_i_can_see_the_dashboard end scenario "Cannot access the dashboard as a regular user" do - given_i_am_a_regular_user + given_i_am_signed_in_as_a_placements_user when_i_go_to_the_dashboard_path then_i_cannot_see_the_dashboard end @@ -20,14 +20,6 @@ private - def given_i_am_a_support_user - sign_in_as create(:placements_support_user) - end - - def given_i_am_a_regular_user - sign_in_as create(:placements_user) - end - def when_i_go_to_the_dashboard_path visit "/good_job" end diff --git a/spec/system/infinite_redirect_spec.rb b/spec/system/infinite_redirect_spec.rb index 98b713dd6..8d0a7f377 100644 --- a/spec/system/infinite_redirect_spec.rb +++ b/spec/system/infinite_redirect_spec.rb @@ -1,10 +1,8 @@ require "rails_helper" RSpec.describe "Infinite redirect", service: :placements, type: :system do - let!(:user) { create(:placements_support_user) } - scenario "When the support users permissions are removed they aren't stuck in an infinite loop" do - given_i_am_a_support_user + given_i_am_signed_in_as_a_placements_support_user when_i_view_all_organisations and_the_support_user_is_removed_as_a_support_user and_i_click_link("Organisations") @@ -14,16 +12,12 @@ private - def given_i_am_a_support_user - sign_in_as user - end - def when_i_view_all_organisations visit placements_support_organisations_path end def and_the_support_user_is_removed_as_a_support_user - user.update!(type: "Placements::User") + @current_user.update!(type: "Placements::User") end def and_i_click_link(text) diff --git a/spec/system/placements/authenticate_user_spec.rb b/spec/system/placements/authenticate_user_spec.rb index afaf2ab3c..8c7aa0357 100644 --- a/spec/system/placements/authenticate_user_spec.rb +++ b/spec/system/placements/authenticate_user_spec.rb @@ -10,21 +10,13 @@ end scenario "As a user who has signed in" do - given_there_is_an_existing_placements_user_with_a_school_for(anne) - when_i_visit_the_sign_in_path - and_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [school]) and_i_visit_placements_schools_details_path then_i_am_able_to_access_the_page end private - def given_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - create(:user_membership, user:, organisation: school, email: user.email) - user - end - def when_i_visit_placements_schools_details_path visit placements_school_path(school.id) end @@ -37,23 +29,5 @@ def then_i_am_able_to_access_the_page expect(page).to have_content("NameSchool") end - def when_i_visit_the_sign_in_path - visit sign_in_path - end - - def when_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_there_is_an_existing_placements_user_with_a_school_for(user) - user_exists_in_dfe_sign_in(user:) - create( - :user_membership, - user:, - organisation: school, - ) - end - - alias_method :and_i_click_sign_in, :when_i_click_sign_in alias_method :and_i_visit_placements_schools_details_path, :when_i_visit_placements_schools_details_path end diff --git a/spec/system/placements/organisations/users/add_users_spec.rb b/spec/system/placements/organisations/users/add_users_spec.rb index b737d4fd8..d3fac3c21 100644 --- a/spec/system/placements/organisations/users/add_users_spec.rb +++ b/spec/system/placements/organisations/users/add_users_spec.rb @@ -7,19 +7,17 @@ perform_enqueued_jobs { example.run } end - let(:anne) { create(:placements_user, :anne) } let(:one_school) { create(:placements_school, name: "One School") } let(:one_provider) { create(:placements_provider, name: "One Provider") } - let(:mary) { create(:placements_user, :mary) } let(:another_school) { create(:placements_school, name: "Another School") } let(:new_user) { create(:placements_user) } describe "Ann invites a member successfully" do context "with provider" do scenario "user invites a member to a provider" do - given_i_am_logged_in_as_a_user_with_one_organisation(one_provider) + given_i_am_signed_in_as_a_placements_user(organisations: [one_provider]) when_i_click_users - then_i_see_the_users_page + then_i_see_the_users_page_for_provider(one_provider) when_i_click_add_user and_i_enter_valid_user_details and_user_is_selected_in_provider_primary_navigation @@ -38,9 +36,9 @@ context "with school" do scenario "user invites a member to a school" do - given_i_am_logged_in_as_a_user_with_one_organisation(one_school) + given_i_am_signed_in_as_a_placements_user(organisations: [one_school]) when_i_click_users - then_i_see_the_users_page + then_i_see_the_users_page_for_school(one_school) and_user_is_selected_in_school_primary_navigation when_i_click_add_user and_user_is_selected_in_school_primary_navigation @@ -60,14 +58,10 @@ end describe "Mary invites a members to second organisation" do - before "user is sent an invitation" do - create(:user_membership, user: mary, organisation: one_school) - create(:user_membership, user: mary, organisation: another_school) - create(:user_membership, user: mary, organisation: one_provider) - end - scenario "user adds a user to multiple organisations" do - given_i_am_logged_in_as_a_user_with_multiple_organisations + given_i_am_signed_in_as_a_placements_user( + organisations: [one_provider, one_school, another_school], + ) and_user_is_already_assigned_to_a_school when_i_navigate_to_that_schools_users then_i_see_the_user_on_that_schools_user_list @@ -83,16 +77,16 @@ end scenario "user tries to submit invalid form" do - given_i_am_logged_in_as_a_user_with_one_organisation(one_school) + given_i_am_signed_in_as_a_placements_user(organisations: [one_school]) when_i_click_users - then_i_see_the_users_page + then_i_see_the_users_page_for_school(one_school) when_i_click_add_user and_try_to_submit_invalid_form_data then_i_see_form_errors end scenario "user tries to add an existing user to the organisation" do - given_i_am_logged_in_as_a_user_with_one_organisation(one_school) + given_i_am_signed_in_as_a_placements_user(organisations: [one_school]) and_user_is_already_assigned_to_a_school when_i_try_to_add_the_user_to_the_same_school then_i_see_the_email_taken_error @@ -106,14 +100,14 @@ } end - before { given_i_am_logged_in_as_a_user_with_one_organisation(one_school) } + before { given_i_am_signed_in_as_a_placements_user(organisations: [one_school]) } it "persists the user details for each tab upon refresh" do windows.each do |window, details| within_window window do visit placements_school_placements_path(one_school) when_i_click_users - then_i_see_the_users_page + then_i_see_the_users_page_for_school(one_school) and_user_is_selected_in_school_primary_navigation when_i_click_add_user and_user_is_selected_in_school_primary_navigation @@ -159,19 +153,6 @@ def then_i_see_the_email_taken_error expect(page).to have_content("Email address already in use") end - def given_i_am_logged_in_as_a_user_with_one_organisation(organisation) - user_exists_in_dfe_sign_in(user: anne) - create(:user_membership, user: anne, organisation:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - - def given_i_am_logged_in_as_a_user_with_multiple_organisations - user_exists_in_dfe_sign_in(user: mary) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def and_user_is_already_assigned_to_a_school create(:user_membership, user: new_user, organisation: one_school) end @@ -220,9 +201,12 @@ def when_i_click_users click_on "Users" end - def then_i_see_the_users_page - expect(page).to have_content "Anne Wilson" - expect(page).to have_content "anne_wilson@example.org" + def then_i_see_the_users_page_for_school(school) + expect(page).to have_current_path placements_school_users_path(school), ignore_query: true + end + + def then_i_see_the_users_page_for_provider(provider) + expect(page).to have_current_path placements_provider_users_path(provider), ignore_query: true end def when_i_click_add_user diff --git a/spec/system/placements/organisations/users/user_removes_other_users_from_organisation_spec.rb b/spec/system/placements/organisations/users/user_removes_other_users_from_organisation_spec.rb index 031ba9edd..16e0c9ecf 100644 --- a/spec/system/placements/organisations/users/user_removes_other_users_from_organisation_spec.rb +++ b/spec/system/placements/organisations/users/user_removes_other_users_from_organisation_spec.rb @@ -13,13 +13,11 @@ let(:mary) { create(:placements_user, :mary) } before do - [anne, mary].each do |user| - create(:user_membership, user:, organisation: school) - end + create(:user_membership, user: anne, organisation: school) + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end scenario "user is removed from a school" do - given_i_am_signed_in_as_mary and_i_visit_the_user_page(anne) when_i_click_on("Delete user") then_i_am_asked_to_confirm(anne, school) @@ -33,8 +31,7 @@ end scenario "I try to remove myself from a school" do - given_i_am_signed_in_as_mary - when_i_try_to_visit_the_remove_path_for(mary, school) + when_i_try_to_visit_the_remove_path_for(@current_user, school) then_i_am_redirected_back end end @@ -45,13 +42,11 @@ let(:mary) { create(:placements_user, :mary) } before "message is sent to user" do - [anne, mary].each do |user| - create(:user_membership, user:, organisation: provider) - end + create(:user_membership, user: anne, organisation: provider) + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end scenario "user is removed from a provider" do - given_i_am_signed_in_as_mary and_i_visit_the_user_page(anne) when_i_click_on("Delete user") then_i_am_asked_to_confirm(anne, provider) @@ -65,20 +60,13 @@ end scenario "I try to remove myself from a school" do - given_i_am_signed_in_as_mary - when_i_try_to_visit_the_remove_path_for(mary, provider) + when_i_try_to_visit_the_remove_path_for(@current_user, provider) then_i_am_redirected_back end end private - def given_i_am_signed_in_as_mary - user_exists_in_dfe_sign_in(user: mary) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def email_removal_notification(email, _organisation) ActionMailer::Base.deliveries.find do |delivery| delivery.to.include?(email) && delivery.subject == "You have been removed from Manage school placements" diff --git a/spec/system/placements/organisations/users/user_views_other_users_spec.rb b/spec/system/placements/organisations/users/user_views_other_users_spec.rb index 904aaa0c1..143884aa7 100644 --- a/spec/system/placements/organisations/users/user_views_other_users_spec.rb +++ b/spec/system/placements/organisations/users/user_views_other_users_spec.rb @@ -4,17 +4,19 @@ let(:school) { create(:placements_school, name: "Placements School 1") } let(:provider) { create(:placements_provider, name: "Placements Provider 1") } let(:anne) { create(:placements_user, :anne) } - let(:mary) { create(:placements_user, :mary) } describe "schools" do + before do + create(:user_membership, user: anne, organisation: school) + end + scenario "user can view other school users" do - user_exists_in_dfe_sign_in(user: mary) - given_users_have_been_assigned_to_the(organisation: school) + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_visit_the_users_page then_i_see_the_organisation_users and_users_is_selected_in_schools_primary_nav - when_i_click_on_a_users_name(mary.full_name) - then_i_see_user_details(:school, user: mary) + when_i_click_on_a_users_name(@current_user.full_name) + then_i_see_user_details(:school, user: @current_user) and_users_is_selected_in_schools_primary_nav and_i_do_not_see_the_remove_user_link when_i_click_back @@ -26,35 +28,30 @@ end describe "providers" do + before do + create(:user_membership, user: anne, organisation: provider) + end + scenario "users can view other provider users" do - user_exists_in_dfe_sign_in(user: anne) - given_users_have_been_assigned_to_the(organisation: provider) + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_visit_the_users_page then_i_see_the_organisation_users and_users_is_selected_in_providers_primary_nav - when_i_click_on_a_users_name(mary.full_name) - then_i_see_user_details(:provider, user: mary) + when_i_click_on_a_users_name(@current_user.full_name) + then_i_see_user_details(:provider, user: @current_user) and_users_is_selected_in_providers_primary_nav - and_i_see_the_remove_user_link + and_i_do_not_see_the_remove_user_link when_i_click_back when_i_click_on_a_users_name(anne.full_name) then_i_see_user_details(:provider, user: anne) and_users_is_selected_in_providers_primary_nav - and_i_do_not_see_the_remove_user_link + and_i_see_the_remove_user_link end end private - def given_users_have_been_assigned_to_the(organisation:) - [mary, anne].each do |user| - create(:user_membership, user:, organisation:) - end - end - def when_i_visit_the_users_page - visit sign_in_path - click_on "Sign in using DfE Sign In" within(".app-primary-navigation__nav") do click_on "Users" end @@ -64,8 +61,8 @@ def then_i_see_the_organisation_users expect(page).to have_content anne.full_name expect(page).to have_content anne.email - expect(page).to have_content mary.full_name - expect(page).to have_content mary.email + expect(page).to have_content @current_user.full_name + expect(page).to have_content @current_user.email end def when_i_click_on_a_users_name(user_name) diff --git a/spec/system/placements/organisations/view_organisations_spec.rb b/spec/system/placements/organisations/view_organisations_spec.rb index 0d07d24c9..79a20e40a 100644 --- a/spec/system/placements/organisations/view_organisations_spec.rb +++ b/spec/system/placements/organisations/view_organisations_spec.rb @@ -10,11 +10,9 @@ let(:school_without_placement) { create(:school) } scenario "I sign in as user Mary with multiple organistions" do - user = given_the_placements_user("Mary") - user_exists_in_dfe_sign_in(user:) - and_user_has_multiple_organisations(user:) - when_i_visit_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [ + multi_org_school, multi_org_provider, claims_school, no_service_school + ]) i_am_redirected_to_organisation_index and_i_only_see_placement_schools when_i_click_on_school_name @@ -28,47 +26,22 @@ end scenario "I sign in as user Anne with one school" do - user = given_the_placements_user("Anne") - user_exists_in_dfe_sign_in(user:) - and_user_has_one_school(user:) - when_i_visit_sign_in_path - when_i_click_sign_in - then_i_see_the_one_school(one_school) + given_i_am_signed_in_as_a_placements_user(organisations: [one_school]) + then_i_see_the_one_school end scenario "I sign in as user Anne with one provider" do - user = given_the_placements_user("Anne") - user_exists_in_dfe_sign_in(user:) - and_user_has_one_provider(user:) - when_i_visit_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [one_provider]) then_i_see_the_one_provider end scenario "I cannot view a school unless it is a placements school" do - user = given_the_placements_user("Anne") - user_exists_in_dfe_sign_in(user:) - and_user_has_a_school_without_a_service(user:) - when_i_visit_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [one_school, school_without_placement]) then_i_am_redirected_to_404_when_i_visit_the_school end private - def user(user_name) - create(:placements_user, user_name.downcase.to_sym) - end - - def given_the_placements_user(user_name) - user(user_name) - end - - def and_user_has_a_school_without_a_service(user:) - create(:user_membership, user:, organisation: create(:school, :placements)) - create(:user_membership, user:, organisation: school_without_placement) - end - def then_i_am_redirected_to_404_when_i_visit_the_school expect { visit placements_school_path(school_without_placement) }.to raise_error(ActiveRecord::RecordNotFound) end @@ -77,13 +50,6 @@ def then_i_am_redirected_to_404 expect(page).to have_content("ERROR") end - def and_user_has_multiple_organisations(user:) - create(:user_membership, user:, organisation: multi_org_school) - create(:user_membership, user:, organisation: multi_org_provider) - create(:user_membership, user:, organisation: claims_school) - create(:user_membership, user:, organisation: no_service_school) - end - def when_i_click_on_school_name click_on "Placements School" end @@ -122,17 +88,9 @@ def then_i_see_the_placements_search_page(provider) end end - def and_user_has_one_school(user:) - create(:user_membership, user:, organisation: one_school) - end - - def and_user_has_one_provider(user:) - create(:user_membership, user:, organisation: one_provider) - end - - def then_i_see_the_one_school(school) + def then_i_see_the_one_school expect(page).not_to have_content "Change organisation" - then_i_see_the_school_page(school) + then_i_see_the_school_page(one_school) end def then_i_see_the_one_provider diff --git a/spec/system/placements/providers/partner_schools/add_a_partner_school_spec.rb b/spec/system/placements/providers/partner_schools/add_a_partner_school_spec.rb index bc6aa760c..d46b6cca0 100644 --- a/spec/system/placements/providers/partner_schools/add_a_partner_school_spec.rb +++ b/spec/system/placements/providers/partner_schools/add_a_partner_school_spec.rb @@ -13,7 +13,7 @@ let!(:school_user) { create(:placements_user, schools: [school]) } before do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end scenario "User adds a partner school", :js, retry: 3 do @@ -135,14 +135,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/providers/partner_schools/add_a_partner_school_without_javascript_spec.rb b/spec/system/placements/providers/partner_schools/add_a_partner_school_without_javascript_spec.rb index cf0ad2851..299743f7c 100644 --- a/spec/system/placements/providers/partner_schools/add_a_partner_school_without_javascript_spec.rb +++ b/spec/system/placements/providers/partner_schools/add_a_partner_school_without_javascript_spec.rb @@ -17,7 +17,7 @@ create(:school, :placements, name: "London") create(:school, :claims, name: "Claims") - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end scenario "User adds a partner school" do @@ -99,14 +99,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/providers/partner_schools/placements/view_a_placement_for_partner_school_spec.rb b/spec/system/placements/providers/partner_schools/placements/view_a_placement_for_partner_school_spec.rb index d7fafac01..c7cafd315 100644 --- a/spec/system/placements/providers/partner_schools/placements/view_a_placement_for_partner_school_spec.rb +++ b/spec/system/placements/providers/partner_schools/placements/view_a_placement_for_partner_school_spec.rb @@ -9,7 +9,7 @@ before do placements_partnership - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end scenario "User views a placement for a partner school" do @@ -20,14 +20,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_school_placements_page visit placements_provider_partner_school_placements_path(provider, school) end diff --git a/spec/system/placements/providers/partner_schools/placements/view_placements_for_partner_school_spec.rb b/spec/system/placements/providers/partner_schools/placements/view_placements_for_partner_school_spec.rb index 1458aa0cf..ec146586a 100644 --- a/spec/system/placements/providers/partner_schools/placements/view_placements_for_partner_school_spec.rb +++ b/spec/system/placements/providers/partner_schools/placements/view_placements_for_partner_school_spec.rb @@ -10,7 +10,7 @@ before do placements_partnership - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end scenario "User views placements for a partner school" do @@ -22,16 +22,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - - alias_method :and_i_sign_in_as_patricia, :given_i_sign_in_as_patricia - def when_i_view_the_partner_school_show_page visit placements_provider_partner_school_path(provider, school) end diff --git a/spec/system/placements/providers/partner_schools/remove_a_partner_school_spec.rb b/spec/system/placements/providers/partner_schools/remove_a_partner_school_spec.rb index 520c52b9c..10fabcfb9 100644 --- a/spec/system/placements/providers/partner_schools/remove_a_partner_school_spec.rb +++ b/spec/system/placements/providers/partner_schools/remove_a_partner_school_spec.rb @@ -23,7 +23,7 @@ end scenario "User removes a partner school" do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_the_partner_school_show_page and_i_click_on("Delete school") then_i_am_asked_to_confirm_partner_school(school) @@ -54,7 +54,7 @@ end scenario "User removes a partner school, and see the placements listed" do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_the_partner_school_show_page and_i_click_on("Delete school") then_i_am_asked_to_confirm_partner_school(school) @@ -72,7 +72,7 @@ scenario "User removes a partner school, which is not onboarded on the placements service" do given_the_school_is_not_onboarded_on_placements_service(school) - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_the_partner_school_show_page and_i_click_on("Delete school") then_i_am_asked_to_confirm_partner_school(school) @@ -88,14 +88,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_school_show_page visit placements_provider_partner_school_path(provider, school) diff --git a/spec/system/placements/providers/partner_schools/view_a_partner_school_spec.rb b/spec/system/placements/providers/partner_schools/view_a_partner_school_spec.rb index a8b166220..cc3956c75 100644 --- a/spec/system/placements/providers/partner_schools/view_a_partner_school_spec.rb +++ b/spec/system/placements/providers/partner_schools/view_a_partner_school_spec.rb @@ -9,21 +9,13 @@ before { partnership } scenario "User views a provider partner school" do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_the_partner_school_show_page then_i_see_the_details_of(school) end private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_school_show_page visit placements_provider_partner_school_path(provider, school) diff --git a/spec/system/placements/providers/partner_schools/view_partner_schools_list_spec.rb b/spec/system/placements/providers/partner_schools/view_partner_schools_list_spec.rb index eea46faf2..ebab6d24f 100644 --- a/spec/system/placements/providers/partner_schools/view_partner_schools_list_spec.rb +++ b/spec/system/placements/providers/partner_schools/view_partner_schools_list_spec.rb @@ -8,7 +8,7 @@ let!(:another_school) { create(:placements_school, name: "Shelbyville Elementary School", urn: "5678") } scenario "User views provider partner schools page where provider has no partner schools" do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_the_partner_schools_page then_i_see_the_empty_state end @@ -16,7 +16,7 @@ scenario "User views provider partner schools page where provider has partner schools" do given_a_partnership_exists_between(school, provider) and_a_partnership_exists_between(another_school, another_provider) - and_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_the_partner_schools_page then_i_see_partner_school(school) and_i_cannot_see_partner_school(another_school) @@ -24,15 +24,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - alias_method :and_i_sign_in_as_patricia, :given_i_sign_in_as_patricia - def when_i_view_the_partner_schools_page visit placements_provider_partner_schools_path(provider) diff --git a/spec/system/placements/providers/placements/searches_filter_options_for_placements_spec.rb b/spec/system/placements/providers/placements/searches_filter_options_for_placements_spec.rb index fd5d4c01e..ab07dc217 100644 --- a/spec/system/placements/providers/placements/searches_filter_options_for_placements_spec.rb +++ b/spec/system/placements/providers/placements/searches_filter_options_for_placements_spec.rb @@ -38,7 +38,7 @@ guildford_placement bath_placement - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_visit_the_placements_index_page end @@ -94,14 +94,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/providers/placements/searching_for_a_placement_spec.rb b/spec/system/placements/providers/placements/searching_for_a_placement_spec.rb index 8709f371d..1fb596b89 100644 --- a/spec/system/placements/providers/placements/searching_for_a_placement_spec.rb +++ b/spec/system/placements/providers/placements/searching_for_a_placement_spec.rb @@ -36,7 +36,7 @@ guildford_placement bath_placement - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end context "when searching for placements near a location (London)" do @@ -133,14 +133,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/providers/placements/view_a_placement_spec.rb b/spec/system/placements/providers/placements/view_a_placement_spec.rb index 5fbbfb786..c9c746756 100644 --- a/spec/system/placements/providers/placements/view_a_placement_spec.rb +++ b/spec/system/placements/providers/placements/view_a_placement_spec.rb @@ -33,7 +33,7 @@ create(:placement, subject: placement_subject, school:, additional_subjects:, academic_year:, terms:) end - before { given_i_sign_in_as_patricia } + before { given_i_am_signed_in_as_a_placements_user(organisations: [provider]) } context "when the placement has a subject without child subjects" do let(:placement_subject) { subject_1 } @@ -69,14 +69,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_placement_show_page visit placements_provider_placement_path(provider, placement) diff --git a/spec/system/placements/providers/placements/view_placements_list_spec.rb b/spec/system/placements/providers/placements/view_placements_list_spec.rb index 4032be74e..e00b06ecc 100644 --- a/spec/system/placements/providers/placements/view_placements_list_spec.rb +++ b/spec/system/placements/providers/placements/view_placements_list_spec.rb @@ -33,7 +33,7 @@ let(:placement_3) { create(:placement, subject: subject_3, school: secondary_school, provider: build(:placements_provider)) } before do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) end scenario "User views all placements page, when no placements exist" do @@ -318,14 +318,6 @@ private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/providers/remembering_the_current_provider_spec.rb b/spec/system/placements/providers/remembering_the_current_provider_spec.rb index ac03f2be1..7e4824e0e 100644 --- a/spec/system/placements/providers/remembering_the_current_provider_spec.rb +++ b/spec/system/placements/providers/remembering_the_current_provider_spec.rb @@ -5,7 +5,7 @@ let(:provider_two) { build(:placements_provider, name: "Ctrl + Alt + Teach") } scenario "A multi-org user switches between different providers" do - given_i_sign_in_with_access_to_multiple_providers + given_i_am_signed_in_as_a_placements_user(organisations: [provider_one, provider_two]) when_i_click_on "The Chalkboard Champions" then_my_current_provider_is "The Chalkboard Champions" @@ -21,13 +21,6 @@ private - def given_i_sign_in_with_access_to_multiple_providers - user = create(:placements_user, providers: [provider_one, provider_two]) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/providers/view_provider_details_spec.rb b/spec/system/placements/providers/view_provider_details_spec.rb index c29cabb03..898a78aea 100644 --- a/spec/system/placements/providers/view_provider_details_spec.rb +++ b/spec/system/placements/providers/view_provider_details_spec.rb @@ -16,21 +16,13 @@ end scenario "User views their provider's details" do - given_i_sign_in_as_patricia + given_i_am_signed_in_as_a_placements_user(organisations: [provider]) when_i_view_my_organisation_details_page then_i_see_the_details_for_my_provider end private - def given_i_sign_in_as_patricia - user = create(:placements_user, :patricia) - create(:user_membership, user:, organisation: provider) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_my_organisation_details_page visit placements_provider_path(provider) diff --git a/spec/system/placements/schools/mentors/delete_a_mentor_spec.rb b/spec/system/placements/schools/mentors/delete_a_mentor_spec.rb index dcdc09caa..ba4c90113 100644 --- a/spec/system/placements/schools/mentors/delete_a_mentor_spec.rb +++ b/spec/system/placements/schools/mentors/delete_a_mentor_spec.rb @@ -15,7 +15,7 @@ before do given_the_school_has_mentors(school:, mentors: [mentor_1, mentor_2]) - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end context "when the mentor has no placements" do @@ -46,30 +46,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - and_user_has_one_school(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - - def and_user_has_one_school(user:) - create(:user_membership, user:, organisation: school) - end - def given_the_school_has_mentors(school:, mentors:) mentors.each do |mentor| create(:placements_mentor_membership, school:, mentor:) diff --git a/spec/system/placements/schools/mentors/user_adds_mentor_spec.rb b/spec/system/placements/schools/mentors/user_adds_mentor_spec.rb index 500863c5c..4e2d01610 100644 --- a/spec/system/placements/schools/mentors/user_adds_mentor_spec.rb +++ b/spec/system/placements/schools/mentors/user_adds_mentor_spec.rb @@ -7,7 +7,7 @@ let(:placements_mentor) { create(:placements_mentor) } let(:new_mentor) { build(:placements_mentor) } - before { given_i_sign_in_as_anne } + before { given_i_am_signed_in_as_a_placements_user(organisations: [school]) } scenario "I can navigate back to the index page" do given_i_navigate_to_schools_mentors_list @@ -213,14 +213,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def given_a_claims_mentor_exists create(:claims_mentor_membership, school: another_school, mentor: claims_mentor) end diff --git a/spec/system/placements/schools/mentors/view_a_mentor_spec.rb b/spec/system/placements/schools/mentors/view_a_mentor_spec.rb index b631428ee..18e7e593d 100644 --- a/spec/system/placements/schools/mentors/view_a_mentor_spec.rb +++ b/spec/system/placements/schools/mentors/view_a_mentor_spec.rb @@ -10,8 +10,7 @@ end before do - school - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end scenario "User views a school mentor's details" do @@ -26,26 +25,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - and_user_has_one_school(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def given_a_mentor_exists_in(school:) create(:placements_mentor_membership, school:, mentor:) end @@ -66,8 +45,4 @@ def then_i_see_the_mentor_details(first_name:, last_name:, trn:) expect(page).to have_content(trn) end end - - def and_user_has_one_school(user:) - create(:user_membership, user:, organisation: school) - end end diff --git a/spec/system/placements/schools/mentors/view_mentors_spec.rb b/spec/system/placements/schools/mentors/view_mentors_spec.rb index 5828ae419..5468e8685 100644 --- a/spec/system/placements/schools/mentors/view_mentors_spec.rb +++ b/spec/system/placements/schools/mentors/view_mentors_spec.rb @@ -6,43 +6,22 @@ let!(:mentor3) { create(:mentor, trn: "1231233") } let!(:school) { create(:placements_school, mentors: [mentor1, mentor2]) } let!(:another_school) { create(:placements_school) } - let!(:anne) do - create( - :placements_user, - :anne, - user_memberships: [create(:user_membership, organisation: school)], - ) - end - let!(:mary) do - create( - :placements_user, - :mary, - user_memberships: [create(:user_membership, organisation: another_school)], - ) - end scenario "View a school's mentors as a user" do - user_exists_in_dfe_sign_in(user: anne) - given_i_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_visit_the_school_mentors_page(school) then_i_see_a_list_of_the_schools_mentors and_i_dont_see_mentors_from_another_school end scenario "View a school's empty mentors list" do - user_exists_in_dfe_sign_in(user: mary) - given_i_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [another_school]) when_i_visit_the_school_mentors_page(another_school) then_i_see_no_results end private - def given_i_sign_in - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_school_mentors_page(school) visit placements_school_mentors_path(school) end diff --git a/spec/system/placements/schools/partner_providers/add_a_partner_provider_spec.rb b/spec/system/placements/schools/partner_providers/add_a_partner_provider_spec.rb index 50dbe56e7..efa024cd7 100644 --- a/spec/system/placements/schools/partner_providers/add_a_partner_provider_spec.rb +++ b/spec/system/placements/schools/partner_providers/add_a_partner_provider_spec.rb @@ -13,7 +13,7 @@ let!(:provider_user) { create(:placements_user, providers: [provider]) } before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end scenario "User adds a partner provider", :js, retry: 3 do @@ -135,14 +135,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_providers_page visit placements_school_partner_providers_path(school) diff --git a/spec/system/placements/schools/partner_providers/add_a_partner_provider_without_javascript_spec.rb b/spec/system/placements/schools/partner_providers/add_a_partner_provider_without_javascript_spec.rb index 0e9a64796..65059d41a 100644 --- a/spec/system/placements/schools/partner_providers/add_a_partner_provider_without_javascript_spec.rb +++ b/spec/system/placements/schools/partner_providers/add_a_partner_provider_without_javascript_spec.rb @@ -17,7 +17,7 @@ create(:provider, :placements, name: "London") create(:claims_provider, name: "Claims") - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end scenario "User adds a partner provider" do @@ -99,14 +99,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_add_partner_provider_page visit new_add_partner_provider_placements_school_partner_providers_path(school) end diff --git a/spec/system/placements/schools/partner_providers/remove_a_partner_provider_spec.rb b/spec/system/placements/schools/partner_providers/remove_a_partner_provider_spec.rb index 419e8fc34..9c7b4d63d 100644 --- a/spec/system/placements/schools/partner_providers/remove_a_partner_provider_spec.rb +++ b/spec/system/placements/schools/partner_providers/remove_a_partner_provider_spec.rb @@ -23,7 +23,7 @@ end scenario "User removes a partner provider" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_view_the_partner_provider_show_page and_i_click_on("Delete provider") then_i_am_asked_to_confirm_partner_provider(provider) @@ -39,7 +39,7 @@ scenario "User removes a partner provider, which is not onboarded on the placements service" do given_the_provider_is_not_onboarded_on_placements_service(provider) - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_view_the_partner_provider_show_page and_i_click_on("Delete provider") then_i_am_asked_to_confirm_partner_provider(provider) @@ -55,14 +55,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_provider_show_page visit placements_school_partner_provider_path(school, provider) diff --git a/spec/system/placements/schools/partner_providers/view_a_partner_provider_spec.rb b/spec/system/placements/schools/partner_providers/view_a_partner_provider_spec.rb index ada5cfe82..293c0f179 100644 --- a/spec/system/placements/schools/partner_providers/view_a_partner_provider_spec.rb +++ b/spec/system/placements/schools/partner_providers/view_a_partner_provider_spec.rb @@ -9,21 +9,13 @@ before { partnership } scenario "User views a school partner provider" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_view_the_partner_provider_show_page then_i_see_the_details_of(provider) end private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_provider_show_page visit placements_school_partner_provider_path(school, provider) diff --git a/spec/system/placements/schools/partner_providers/view_partner_providers_list_spec.rb b/spec/system/placements/schools/partner_providers/view_partner_providers_list_spec.rb index afc0700ff..b0af34c3e 100644 --- a/spec/system/placements/schools/partner_providers/view_partner_providers_list_spec.rb +++ b/spec/system/placements/schools/partner_providers/view_partner_providers_list_spec.rb @@ -8,7 +8,7 @@ let!(:another_provider) { create(:placements_provider, name: "Burns University", ukprn: "5678") } scenario "User views school partner providers page where school has no partner providers" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_view_the_partner_providers_page then_i_see_the_empty_state end @@ -16,7 +16,7 @@ scenario "User views school partner providers page where school has partner providers" do given_a_partnership_exists_between(school, provider) and_a_partnership_exists_between(another_school, another_provider) - and_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_view_the_partner_providers_page then_i_see_partner_provider(provider) and_i_cannot_see_partner_provider(another_provider) @@ -24,15 +24,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - alias_method :and_i_sign_in_as_anne, :given_i_sign_in_as_anne - def when_i_view_the_partner_providers_page visit placements_school_partner_providers_path(school) diff --git a/spec/system/placements/schools/placements/add_a_placement_spec.rb b/spec/system/placements/schools/placements/add_a_placement_spec.rb index 976168671..471143e8a 100644 --- a/spec/system/placements/schools/placements/add_a_placement_spec.rb +++ b/spec/system/placements/schools/placements/add_a_placement_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "Placements / Schools / Placements / Add a placement", service: :placements, type: :system do before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end context "when the school has no school contact assigned" do @@ -22,26 +22,6 @@ private - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - create(:user_membership, user:, organisation: school) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_placements_page visit placements_school_placements_path(school) end diff --git a/spec/system/placements/schools/placements/delete_a_placement_spec.rb b/spec/system/placements/schools/placements/delete_a_placement_spec.rb index 4870809eb..5573d5b81 100644 --- a/spec/system/placements/schools/placements/delete_a_placement_spec.rb +++ b/spec/system/placements/schools/placements/delete_a_placement_spec.rb @@ -9,7 +9,7 @@ let(:subject_2) { build(:subject, name: "Subject 2", subject_area: :primary) } before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) placement_2 when_i_visit_the_placement_show_page(placement_1) end @@ -34,30 +34,10 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - create(:user_membership, user:, organisation: school) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_placement_show_page(placement) visit placements_school_placement_path(school, placement) end - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def when_i_click_on(text) click_on text end diff --git a/spec/system/placements/schools/placements/edit_a_placement_spec.rb b/spec/system/placements/schools/placements/edit_a_placement_spec.rb index 75a54d049..67334d718 100644 --- a/spec/system/placements/schools/placements/edit_a_placement_spec.rb +++ b/spec/system/placements/schools/placements/edit_a_placement_spec.rb @@ -2,24 +2,12 @@ RSpec.describe "Placements / Schools / Placements / Edit a placement", service: :placements, type: :system do - before { given_i_sign_in_as_anne } + before { given_i_am_signed_in_as_a_placements_user(organisations: [school]) } it_behaves_like "an edit placement wizard" private - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - create(:user_membership, user:, organisation: school) - end - def then_i_am_redirected_to_add_a_partner_provider expect(page).to have_current_path( placements_school_partner_providers_path(school), ignore_query: true diff --git a/spec/system/placements/schools/placements/navigate_placements_spec.rb b/spec/system/placements/schools/placements/navigate_placements_spec.rb index a2bbd9316..25ec7ae7f 100644 --- a/spec/system/placements/schools/placements/navigate_placements_spec.rb +++ b/spec/system/placements/schools/placements/navigate_placements_spec.rb @@ -8,7 +8,7 @@ let!(:placement_for_next_academic_year) { create(:placement, school:, academic_year: academic_year.next).decorate } before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end context "when viewing placements from the current academic year" do @@ -35,26 +35,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - create(:user_membership, user:, organisation: school) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def when_i_visit_the_placements_page visit placements_school_placements_path(school) end diff --git a/spec/system/placements/schools/placements/view_a_placement_spec.rb b/spec/system/placements/schools/placements/view_a_placement_spec.rb index 1a7d7ac73..6cdb169f9 100644 --- a/spec/system/placements/schools/placements/view_a_placement_spec.rb +++ b/spec/system/placements/schools/placements/view_a_placement_spec.rb @@ -10,7 +10,7 @@ let(:partnership) { create(:placements_partnership, provider:, school:) } before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end context "with subjects" do @@ -181,32 +181,12 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - create(:user_membership, user:, organisation: school) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_placement_show_page visit placements_school_placement_path(school, placement) end alias_method :given_i_visit_the_placement_show_page, :when_i_visit_the_placement_show_page - def given_i_sign_in_as_anne - and_there_is_an_existing_user_for("Anne") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def given_a_placement_has_one_subject(placements_subject) placement.update(subject: placements_subject) end diff --git a/spec/system/placements/schools/placements/view_placements_list_spec.rb b/spec/system/placements/schools/placements/view_placements_list_spec.rb index ef3fd2465..cfe4447cf 100644 --- a/spec/system/placements/schools/placements/view_placements_list_spec.rb +++ b/spec/system/placements/schools/placements/view_placements_list_spec.rb @@ -5,52 +5,52 @@ let!(:another_school) { create(:placements_school) } scenario "View school placements page where school has no placements" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_the_placements_page then_i_see_the_empty_state end scenario "where placements for another school exists" do given_placement_exists_for_another_school - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_the_empty_state end context "with placements" do scenario "where placement has multiple mentors" do given_a_placement_exists_with_multiple_mentors - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_mentor_names("Bart Simpson and Lisa Simpson") and_i_see_subject_names("Biology") end scenario "where placement has no mentors attached" do given_a_placement_exists - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_mentor_names("Not yet known") end scenario "when the placement has a provider" do given_a_placement_exists_with_a_provider - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_the_provider_name("Springfield University") end scenario "when the placement does not have a provider" do given_a_placement_exists - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_the_provider_name("Not yet known") end scenario "when the placement has no terms" do given_a_placement_exists - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_term_name("Any time in the academic year") end scenario "when the placement has terms" do given_a_placement_exists(with_term: true) - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_term_name("Autumn term") end @@ -64,20 +64,20 @@ let!(:next_academic_year_placement) { create(:placement, school:, academic_year: next_academic_year, subject: next_subject) } scenario "when I view placements for the current academic year" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_placement(current_academic_year_placement) and_i_do_not_see_placement(next_academic_year_placement) end scenario "when I view placements for the next academic year" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) when_i_click_on("Next year (#{next_academic_year.name})") then_i_see_placement(next_academic_year_placement) and_i_do_not_see_placement(current_academic_year_placement) end scenario "I can switch between academic years" do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) then_i_see_placement(current_academic_year_placement) and_i_do_not_see_placement(next_academic_year_placement) @@ -94,14 +94,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def given_a_placement_exists(with_term: false) with_term ? create(:placement, school:, terms: [create(:placements_term, :autumn)]) : create(:placement, school:) end diff --git a/spec/system/placements/schools/school_contacts/add_a_school_contact_spec.rb b/spec/system/placements/schools/school_contacts/add_a_school_contact_spec.rb index d85778f45..f6a4b3968 100644 --- a/spec/system/placements/schools/school_contacts/add_a_school_contact_spec.rb +++ b/spec/system/placements/schools/school_contacts/add_a_school_contact_spec.rb @@ -5,7 +5,7 @@ let(:school) { build(:placements_school, with_school_contact: false) } before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) end scenario "User adds a school contact to their organisation" do @@ -121,14 +121,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_my_organisation_details_page visit placements_school_path(school) diff --git a/spec/system/placements/schools/school_contacts/edit_a_school_contact_spec.rb b/spec/system/placements/schools/school_contacts/edit_a_school_contact_spec.rb index 256f6bd93..c16306ef1 100644 --- a/spec/system/placements/schools/school_contacts/edit_a_school_contact_spec.rb +++ b/spec/system/placements/schools/school_contacts/edit_a_school_contact_spec.rb @@ -6,7 +6,7 @@ let(:school_contact) { school.school_contact } before do - given_i_sign_in_as_anne + given_i_am_signed_in_as_a_placements_user(organisations: [school]) school_contact end @@ -85,14 +85,6 @@ private - def given_i_sign_in_as_anne - user = create(:placements_user, :anne) - create(:user_membership, user:, organisation: school) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_my_organisation_details_page visit placements_school_path(school) diff --git a/spec/system/placements/sign_in_as_a_placements_user_spec.rb b/spec/system/placements/sign_in_as_a_placements_user_spec.rb index d4d26017d..a6d139b49 100644 --- a/spec/system/placements/sign_in_as_a_placements_user_spec.rb +++ b/spec/system/placements/sign_in_as_a_placements_user_spec.rb @@ -2,9 +2,7 @@ RSpec.describe "Sign In as a Placements User", service: :placements, type: :system do scenario "I sign in as a non-support user, with no organisation" do - given_there_is_an_existing_user_for("Anne") - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user then_i_dont_get_redirected_to_support_organisations and_i_see_an_empty_organsations_page end @@ -13,10 +11,7 @@ let!(:organisation) { create(:school, :placements, name: "Placement School") } scenario "I sign in as a school user and see my schools placements" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [organisation]) then_i_dont_get_redirected_to_support_organisations then_i_can_see_the_placements_school_placements_page end @@ -26,10 +21,7 @@ let!(:organisation) { create(:provider, :placements, name: "Provider") } scenario "I sign in as a provider user and see the placements list page" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [organisation]) then_i_dont_get_redirected_to_support_organisations then_i_can_see_the_placements_page end @@ -40,38 +32,30 @@ let(:provider_organisation) { create(:provider, :placements, name: "Provider") } scenario "I sign in as a multi organisation user and see a list of my organisations" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) - and_the_user_is_part_of_an_organisation(provider_organisation) - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(organisations: [organisation, provider_organisation]) then_i_dont_get_redirected_to_support_organisations then_i_am_redirected_to_the_organisations_page end end scenario "I sign in as a support user" do - given_there_is_an_existing_support_user_for("Colin") - and_there_are_placement_organisations - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_there_are_placement_organisations + given_i_am_signed_in_as_a_placements_support_user then_i_see_a_list_of_organisations end context "when response from dfe sign in is invalid" do scenario "I sign in as user colin" do invalid_dfe_sign_in_response - when_i_visit_the_sign_in_path - when_i_click_sign_in + when_i_visit_the(sign_in_path) + when_i_click_on("Sign in using DfE Sign In") i_do_not_have_access_to_the_service end end context "when normal user tries to access support user page" do scenario "I sign in as user mary trying to access support user page" do - given_there_is_an_existing_user_for("Mary") - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user visit_support_page i_do_not_have_access_to_support_page end @@ -80,20 +64,19 @@ context "when dsi fails" do scenario "I try to sign in as support user" do when_dsi_fails - when_i_visit_the_sign_in_path - when_i_click_sign_in + when_i_visit_the(sign_in_path) + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirect_to_internal_server_error end end context "when the user has both a support and non-support account" do scenario "I sign in as user colin and accesses the support user page" do - given_there_is_an_existing_user_for("Colin") - given_there_is_an_existing_support_user_for("Colin") - and_there_are_placement_organisations + given_there_are_placement_organisations + given_i_am_signed_in_as_a_placements_user + and_the_placements_user_is_also_a_support_user + when_i_visit_the(sign_in_path) - when_i_visit_the_sign_in_path - when_i_click_sign_in then_i_see_a_list_of_organisations end end @@ -101,19 +84,15 @@ context "when the user does not have a DfE ID" do context "when the user is not a support user" do scenario "I sign in as user Anne, using my email address" do - given_there_is_an_existing_user_for("Anne", with_dfe_sign_id: false) - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_user(with_dfe_sign_id: false) then_i_dont_get_redirected_to_support_organisations end end context "when the user is a support user" do scenario "I sign in as support user Colin, using my email address" do - given_there_is_an_existing_support_user_for("Colin", with_dfe_sign_id: false) - and_there_are_placement_organisations - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_there_are_placement_organisations + given_i_am_signed_in_as_a_placements_support_user(with_dfe_sign_id: false) then_i_see_a_list_of_organisations end end @@ -122,10 +101,10 @@ context "when I use a deep link without being logged in" do context "when I am a support user" do scenario "when I sign in as Colin I am redirected to my requested page" do - given_there_is_an_existing_support_user_for("Colin") + given_i_am_signed_in_as_a_placements_support_user(sign_in: false) when_i_visit_the_support_users_path then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirected_to_the_support_users_page end end @@ -135,21 +114,21 @@ let(:provider_organisation) { create(:provider, :placements, name: "Provider") } scenario "when I sign in as a school user I am redirected to my requested page" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) + given_i_am_signed_in_as_a_placements_user(organisations: [organisation], sign_in: false) when_i_visit_the_school_users_path(organisation) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirected_to_the_school_users_page(organisation) end scenario "when I sign in as a multi-organisation user I am redirected to my organisations page" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) - and_the_user_is_part_of_an_organisation(provider_organisation) + given_i_am_signed_in_as_a_placements_user( + organisations: [organisation, provider_organisation], + sign_in: false, + ) when_i_visit_the_school_users_path(organisation) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirected_to_the_school_users_page(organisation) end end @@ -158,11 +137,10 @@ let!(:organisation) { create(:school, :placements, name: "Deep Link Placement School") } scenario "when I sign in as a school user I am redirect to the placements page" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) + given_i_am_signed_in_as_a_placements_user(organisations: [organisation], sign_in: false) when_i_visit_the(sign_in_path) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_can_see_the_placements_school_placements_page end end @@ -171,11 +149,10 @@ let!(:organisation) { create(:school, :placements, name: "Deep Link Placement School") } scenario "when I sign in as a school user I am redirect to the placements page" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) + given_i_am_signed_in_as_a_placements_user(organisations: [organisation], sign_in: false) when_i_visit_the(sign_out_path) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_can_see_the_placements_school_placements_page end end @@ -185,11 +162,10 @@ context "when I sign in as a school user" do scenario "I am redirected to the placements page for my school" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) + given_i_am_signed_in_as_a_placements_user(organisations: [organisation], sign_in: false) when_i_visit_the_school_users_path(organisation) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirected_to_the_school_users_page(organisation) when_i_visit_the placements_root_path and_i_click_on "Start now" @@ -201,11 +177,10 @@ let!(:organisation) { create(:provider, :placements, name: "Provider") } scenario "I am redirected to the placements page for my school" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) + given_i_am_signed_in_as_a_placements_user(organisations: [organisation], sign_in: false) when_i_visit_the_provider_users_path(organisation) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirected_to_the_provider_users_page(organisation) when_i_visit_the placements_root_path and_i_click_on "Start now" @@ -218,12 +193,13 @@ let!(:provider_organisation) { create(:provider, :placements, name: "Provider") } scenario "I am redirected to the list of my organisations" do - given_there_is_an_existing_user_for("Anne") - and_the_user_is_part_of_an_organisation(organisation) - and_the_user_is_part_of_an_organisation(provider_organisation) + given_i_am_signed_in_as_a_placements_user( + organisations: [organisation, provider_organisation], + sign_in: false, + ) when_i_visit_the_school_users_path(organisation) then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_am_redirected_to_the_school_users_page(organisation) when_i_visit_the placements_root_path and_i_click_on "Start now" @@ -233,11 +209,11 @@ context "when I sign in as support user Colin" do scenario "I am redirected to the support organisation list page" do - given_there_is_an_existing_support_user_for("Colin") - and_there_are_placement_organisations + given_there_are_placement_organisations + given_i_am_signed_in_as_a_placements_support_user(sign_in: false) and_i_visit_a_school_show_page then_i_am_redirected_to_the_sign_in_page - when_i_click_sign_in + when_i_click_on("Sign in using DfE Sign In") then_i_see_school_show_page when_i_visit_the placements_root_path and_i_click_on "Start now" @@ -249,22 +225,6 @@ private - def given_there_is_an_existing_user_for(user_name, with_dfe_sign_id: true) - user = create(:placements_user, user_name.downcase.to_sym) - user.update!(dfe_sign_in_uid: nil) unless with_dfe_sign_id - user_exists_in_dfe_sign_in(user:) - end - - def given_there_is_an_existing_support_user_for(user_name, with_dfe_sign_id: true) - user = create(:placements_support_user, user_name.downcase.to_sym) - user.update!(dfe_sign_in_uid: nil) unless with_dfe_sign_id - user_exists_in_dfe_sign_in(user:) - end - - def when_i_visit_the_sign_in_path - visit sign_in_path - end - def and_i_visit_a_school_show_page visit placements_school_path(organisation) end @@ -274,18 +234,15 @@ def then_i_see_school_show_page expect(page).to have_content(organisation.name) end - def and_there_are_placement_organisations + def given_there_are_placement_organisations create(:school, :placements, name: "Placement School") create(:placements_provider, name: "Provider 1") end - def when_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def and_i_click_on(text) click_on text end + alias_method :when_i_click_on, :and_i_click_on def when_i_visit_the(path) visit path @@ -375,4 +332,8 @@ def when_i_visit_the_provider_users_path(organisation) def then_i_am_redirected_to_the_provider_users_page(organisation) expect(page).to have_current_path(placements_provider_users_path(organisation)) end + + def and_the_placements_user_is_also_a_support_user + @current_user.update!(type: Placements::SupportUser) + end end diff --git a/spec/system/placements/sign_out_as_a_placements_user_spec.rb b/spec/system/placements/sign_out_as_a_placements_user_spec.rb index f3f1bdfa3..2a930c68c 100644 --- a/spec/system/placements/sign_out_as_a_placements_user_spec.rb +++ b/spec/system/placements/sign_out_as_a_placements_user_spec.rb @@ -10,9 +10,7 @@ end scenario "I sign out" do - given_there_is_an_existing_placements_user_with_a_school_for(colin) - when_i_visit_the_sign_in_path - when_i_click_sign_in + given_i_am_signed_in_as_a_placements_support_user i_should_see_a_sign_out_button when_i_click_sign_out i_expect_to_be_on_sign_in_page @@ -22,23 +20,6 @@ private - def given_there_is_an_existing_placements_user_with_a_school_for(user) - user_exists_in_dfe_sign_in(user:) - create( - :user_membership, - user:, - organisation: create(:school, :placements), - ) - end - - def when_i_visit_the_sign_in_path - visit sign_in_path - end - - def when_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def i_should_see_a_sign_out_button expect(page).to have_content("Sign out") end diff --git a/spec/system/placements/support/organisations/support_filtering_and_searching_for_organisation_spec.rb b/spec/system/placements/support/organisations/support_filtering_and_searching_for_organisation_spec.rb index 852992d7d..1abc1582f 100644 --- a/spec/system/placements/support/organisations/support_filtering_and_searching_for_organisation_spec.rb +++ b/spec/system/placements/support/organisations/support_filtering_and_searching_for_organisation_spec.rb @@ -2,7 +2,7 @@ RSpec.describe "Support user filters and searches for organisations", service: :placements, type: :system do before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user and_placement_schools_and_providers_exist then_i_see_support_navigation_with_organisation_selected end @@ -183,13 +183,6 @@ def then_i_see_all_schools expect(page).not_to have_content("Lead Partner London") end - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def then_i_see_support_navigation_with_organisation_selected within(".govuk-header__navigation-list") do expect(page).to have_link "Organisations" diff --git a/spec/system/placements/support/organisations/support_user_selects_an_organisation_type_to_add_spec.rb b/spec/system/placements/support/organisations/support_user_selects_an_organisation_type_to_add_spec.rb index ec7742c40..4245aa639 100644 --- a/spec/system/placements/support/organisations/support_user_selects_an_organisation_type_to_add_spec.rb +++ b/spec/system/placements/support/organisations/support_user_selects_an_organisation_type_to_add_spec.rb @@ -3,7 +3,7 @@ RSpec.describe "Placements / Support / Organisations / Support User Selects An Organisation Type To Add", service: :placements, type: :system do before do - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end scenario "Colin selects to add an ITT provider" do @@ -78,25 +78,6 @@ def given_i_navigate_to_the_organisations_list visit placements_support_organisations_path end - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_page - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_page - and_i_click_sign_in - end - def and_i_click_on(text) click_on text end diff --git a/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_spec.rb b/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_spec.rb index bc2d4ee00..b2741264c 100644 --- a/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_spec.rb +++ b/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_spec.rb @@ -13,7 +13,7 @@ end before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user adds a partner school", :js, retry: 3 do @@ -121,13 +121,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_schools_page_for(provider) visit placements_provider_partner_schools_path(provider) diff --git a/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_without_javascript_spec.rb b/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_without_javascript_spec.rb index d263ddf42..2233192a3 100644 --- a/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_without_javascript_spec.rb +++ b/spec/system/placements/support/providers/partner_schools/support_user_adds_a_partner_school_without_javascript_spec.rb @@ -17,7 +17,7 @@ create(:school, :placements, name: "London") create(:school, :claims, name: "Claims") - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user adds a partner school" do @@ -99,13 +99,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_add_partner_school_page_for(provider) visit new_add_partner_school_placements_provider_partner_schools_path(provider) diff --git a/spec/system/placements/support/providers/partner_schools/support_user_deletes_a_partner_school_spec.rb b/spec/system/placements/support/providers/partner_schools/support_user_deletes_a_partner_school_spec.rb index 8a05db684..68c313e2d 100644 --- a/spec/system/placements/support/providers/partner_schools/support_user_deletes_a_partner_school_spec.rb +++ b/spec/system/placements/support/providers/partner_schools/support_user_deletes_a_partner_school_spec.rb @@ -20,7 +20,7 @@ before do partnership another_partnership - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user deletes a partner school" do @@ -86,13 +86,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_schools_page_for(provider:, school:) visit placements_provider_partner_school_path(provider, school) diff --git a/spec/system/placements/support/providers/partner_schools/view_a_partner_school_as_support_user_spec.rb b/spec/system/placements/support/providers/partner_schools/view_a_partner_school_as_support_user_spec.rb index f4f1d924a..219ddd6cb 100644 --- a/spec/system/placements/support/providers/partner_schools/view_a_partner_school_as_support_user_spec.rb +++ b/spec/system/placements/support/providers/partner_schools/view_a_partner_school_as_support_user_spec.rb @@ -8,7 +8,7 @@ before do partnership - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support User views a provider partner school" do @@ -19,13 +19,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_schools_page_for(provider) visit placements_provider_partner_schools_path(provider) diff --git a/spec/system/placements/support/providers/partner_schools/view_partner_school_list_as_support_user_spec.rb b/spec/system/placements/support/providers/partner_schools/view_partner_school_list_as_support_user_spec.rb index 605af94a7..51f951dcb 100644 --- a/spec/system/placements/support/providers/partner_schools/view_partner_school_list_as_support_user_spec.rb +++ b/spec/system/placements/support/providers/partner_schools/view_partner_school_list_as_support_user_spec.rb @@ -8,7 +8,7 @@ let!(:another_school) { create(:placements_school, name: "Shelbyville Elementary School", urn: "5678") } before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user views provider partner schools page for a provider with no partner schools" do @@ -26,13 +26,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_schools_page_for(provider) visit placements_provider_partner_schools_path(provider) diff --git a/spec/system/placements/support/providers/support_user_adds_a_provider_spec.rb b/spec/system/placements/support/providers/support_user_adds_a_provider_spec.rb index b2a766313..d00e60573 100644 --- a/spec/system/placements/support/providers/support_user_adds_a_provider_spec.rb +++ b/spec/system/placements/support/providers/support_user_adds_a_provider_spec.rb @@ -4,7 +4,7 @@ let(:provider) { create(:provider, name: "Provider 1") } before do - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user provider end @@ -65,19 +65,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_page - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_add_organisation_page visit new_add_organisation_placements_support_organisations_path diff --git a/spec/system/placements/support/providers/support_user_adds_a_provider_without_javascript_spec.rb b/spec/system/placements/support/providers/support_user_adds_a_provider_without_javascript_spec.rb index 8f52079aa..d8b7938ad 100644 --- a/spec/system/placements/support/providers/support_user_adds_a_provider_without_javascript_spec.rb +++ b/spec/system/placements/support/providers/support_user_adds_a_provider_without_javascript_spec.rb @@ -6,7 +6,7 @@ create(:provider, name: "Manchester 2") create(:provider, name: "London") - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end scenario "Colin adds a new Provider" do @@ -79,25 +79,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_page - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_page - and_i_click_sign_in - end - def when_i_visit_the_add_organisation_page visit new_add_organisation_placements_support_organisations_path diff --git a/spec/system/placements/support/schools/mentors/support_user_adds_a_mentor_spec.rb b/spec/system/placements/support/schools/mentors/support_user_adds_a_mentor_spec.rb index ae5c3dfca..05eb64296 100644 --- a/spec/system/placements/support/schools/mentors/support_user_adds_a_mentor_spec.rb +++ b/spec/system/placements/support/schools/mentors/support_user_adds_a_mentor_spec.rb @@ -7,7 +7,7 @@ let(:placements_mentor) { create(:placements_mentor) } let(:new_mentor) { build(:placements_mentor) } - before { given_i_sign_in_as_colin } + before { given_i_am_signed_in_as_a_placements_support_user } scenario "I can navigate back to the index page" do given_i_navigate_to_schools_mentors_list(school) @@ -169,13 +169,6 @@ private - def given_i_sign_in_as_colin - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def given_a_claims_mentor_exists create(:claims_mentor_membership, school: another_school, mentor: claims_mentor) end diff --git a/spec/system/placements/support/schools/mentors/support_user_deletes_a_mentor_spec.rb b/spec/system/placements/support/schools/mentors/support_user_deletes_a_mentor_spec.rb index 7aa1ae167..19767c7e8 100644 --- a/spec/system/placements/support/schools/mentors/support_user_deletes_a_mentor_spec.rb +++ b/spec/system/placements/support/schools/mentors/support_user_deletes_a_mentor_spec.rb @@ -16,7 +16,7 @@ before do given_the_school_has_mentors(school:, mentors: [mentor_1, mentor_2]) - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end context "when the mentor has no placements" do @@ -46,25 +46,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def given_the_school_has_mentors(school:, mentors:) mentors.each do |mentor| create(:placements_mentor_membership, school:, mentor:) diff --git a/spec/system/placements/support/schools/mentors/support_user_views_a_mentor_spec.rb b/spec/system/placements/support/schools/mentors/support_user_views_a_mentor_spec.rb index 8ac6b65e1..0f6f2669a 100644 --- a/spec/system/placements/support/schools/mentors/support_user_views_a_mentor_spec.rb +++ b/spec/system/placements/support/schools/mentors/support_user_views_a_mentor_spec.rb @@ -12,7 +12,7 @@ before do school - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end scenario "Support User views a school mentor's details" do @@ -28,25 +28,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def given_a_mentor_exists_in(school:) create(:placements_mentor_membership, school:, mentor:) end diff --git a/spec/system/placements/support/schools/mentors/support_user_views_mentors_spec.rb b/spec/system/placements/support/schools/mentors/support_user_views_mentors_spec.rb index 04ed904a1..5645b3ede 100644 --- a/spec/system/placements/support/schools/mentors/support_user_views_mentors_spec.rb +++ b/spec/system/placements/support/schools/mentors/support_user_views_mentors_spec.rb @@ -7,30 +7,22 @@ let!(:mentor3) { create(:mentor, trn: "1231233") } let!(:school) { create(:placements_school, mentors: [mentor1, mentor2]) } let!(:another_school) { create(:placements_school) } - let!(:colin) { create(:placements_support_user, :colin) } + + before { given_i_am_signed_in_as_a_placements_support_user } scenario "View a school's mentors as a support user" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_mentors_page(school) then_i_see_a_list_of_the_schools_mentors and_i_dont_see_mentors_from_another_school end scenario "View a school's empty mentors list" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_mentors_page(another_school) then_i_see_no_results end private - def given_i_sign_in - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_school_mentors_page(school) visit placements_school_mentors_path(school) end diff --git a/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_spec.rb b/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_spec.rb index eecdd40a3..3e0967249 100644 --- a/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_spec.rb +++ b/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_spec.rb @@ -13,7 +13,7 @@ end before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user adds a partner provider", :js, retry: 3 do @@ -121,13 +121,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_providers_page_for(school) visit placements_school_partner_providers_path(school) diff --git a/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_without_javascript_spec.rb b/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_without_javascript_spec.rb index f7ad47a4a..815913d59 100644 --- a/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_without_javascript_spec.rb +++ b/spec/system/placements/support/schools/partner_providers/support_user_adds_a_partner_provider_without_javascript_spec.rb @@ -17,7 +17,7 @@ create(:provider, :placements, name: "London") create(:claims_provider, name: "Claims") - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user adds a partner provider" do @@ -99,13 +99,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_add_partner_provider_page_for(school) visit new_add_partner_provider_placements_school_partner_providers_path(school) diff --git a/spec/system/placements/support/schools/partner_providers/support_user_deletes_a_partner_provider_spec.rb b/spec/system/placements/support/schools/partner_providers/support_user_deletes_a_partner_provider_spec.rb index 603fe84a2..b2d5650ae 100644 --- a/spec/system/placements/support/schools/partner_providers/support_user_deletes_a_partner_provider_spec.rb +++ b/spec/system/placements/support/schools/partner_providers/support_user_deletes_a_partner_provider_spec.rb @@ -20,7 +20,7 @@ before do partnership another_partnership - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user deletes a partner provider" do @@ -54,13 +54,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_view_the_partner_provider_show_page_for(school:, provider:) visit placements_school_partner_provider_path(school, provider) diff --git a/spec/system/placements/support/schools/partner_providers/view_a_partner_provider_as_support_user_spec.rb b/spec/system/placements/support/schools/partner_providers/view_a_partner_provider_as_support_user_spec.rb index 0233a2915..6bff6842a 100644 --- a/spec/system/placements/support/schools/partner_providers/view_a_partner_provider_as_support_user_spec.rb +++ b/spec/system/placements/support/schools/partner_providers/view_a_partner_provider_as_support_user_spec.rb @@ -8,7 +8,7 @@ before do partnership - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user views a school partner provider" do @@ -19,13 +19,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_providers_page_for(school) visit placements_school_partner_providers_path(school) diff --git a/spec/system/placements/support/schools/partner_providers/view_partner_school_list_as_support_user_spec.rb b/spec/system/placements/support/schools/partner_providers/view_partner_school_list_as_support_user_spec.rb index a80f8759b..c327148dd 100644 --- a/spec/system/placements/support/schools/partner_providers/view_partner_school_list_as_support_user_spec.rb +++ b/spec/system/placements/support/schools/partner_providers/view_partner_school_list_as_support_user_spec.rb @@ -8,7 +8,7 @@ let!(:another_provider) { create(:placements_provider, name: "Burns University", ukprn: "5678") } before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end scenario "Support user views school partner providers page where school has no partner providers" do @@ -26,13 +26,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_partner_providers_page_for(school) visit placements_school_partner_providers_path(school) diff --git a/spec/system/placements/support/schools/placements/support_user_adds_a_placement_spec.rb b/spec/system/placements/support/schools/placements/support_user_adds_a_placement_spec.rb index bf06b6b8d..0cd81bc51 100644 --- a/spec/system/placements/support/schools/placements/support_user_adds_a_placement_spec.rb +++ b/spec/system/placements/support/schools/placements/support_user_adds_a_placement_spec.rb @@ -3,33 +3,13 @@ RSpec.describe "Placements / Support / Schools / Placements / Add a placement", service: :placements, type: :system do before do - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end it_behaves_like "an add a placement wizard" private - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - create(:user_membership, user:, organisation: school) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_placements_page visit placements_school_placements_path(school) end diff --git a/spec/system/placements/support/schools/placements/support_user_deletes_a_placement_spec.rb b/spec/system/placements/support/schools/placements/support_user_deletes_a_placement_spec.rb index f3df78e52..851764513 100644 --- a/spec/system/placements/support/schools/placements/support_user_deletes_a_placement_spec.rb +++ b/spec/system/placements/support/schools/placements/support_user_deletes_a_placement_spec.rb @@ -16,7 +16,7 @@ before do placement_2 - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user when_i_visit_the_show_page_for(school, placement_1) end @@ -40,25 +40,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def when_i_visit_the_show_page_for(school, placement) visit placements_school_placement_path(school, placement) end diff --git a/spec/system/placements/support/schools/placements/support_user_edits_a_placement_spec.rb b/spec/system/placements/support/schools/placements/support_user_edits_a_placement_spec.rb index 434d0b8ea..25cd41e8d 100644 --- a/spec/system/placements/support/schools/placements/support_user_edits_a_placement_spec.rb +++ b/spec/system/placements/support/schools/placements/support_user_edits_a_placement_spec.rb @@ -2,18 +2,12 @@ RSpec.describe "Placements / Support / Schools / Placements / Edit a placement", service: :placements, type: :system do - before { given_i_sign_in_as_colin } + before { given_i_am_signed_in_as_a_placements_support_user } it_behaves_like "an edit placement wizard" private - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def and_there_is_an_existing_user_for(user_name) user = create(:placements_support_user, user_name.downcase.to_sym) user_exists_in_dfe_sign_in(user:) diff --git a/spec/system/placements/support/schools/placements/support_user_views_a_placement_spec.rb b/spec/system/placements/support/schools/placements/support_user_views_a_placement_spec.rb index cf54d5244..15fc4b818 100644 --- a/spec/system/placements/support/schools/placements/support_user_views_a_placement_spec.rb +++ b/spec/system/placements/support/schools/placements/support_user_views_a_placement_spec.rb @@ -11,7 +11,7 @@ before do school - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end describe "school phases" do @@ -174,25 +174,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def when_i_visit_the_show_page_for(school, placement) visit placements_school_placement_path(school, placement) end diff --git a/spec/system/placements/support/schools/placements/support_user_views_placements_spec.rb b/spec/system/placements/support/schools/placements/support_user_views_placements_spec.rb index bd3f05ddb..cba1a5896 100644 --- a/spec/system/placements/support/schools/placements/support_user_views_placements_spec.rb +++ b/spec/system/placements/support/schools/placements/support_user_views_placements_spec.rb @@ -14,28 +14,23 @@ let!(:placement3) { create(:placement, mentors: [mentor3], subject: subject3) } let!(:school) { create(:placements_school, mentors: [mentor1, mentor2]) } let!(:another_school) { create(:placements_school) } - let!(:colin) { create(:placements_support_user, :colin) } let(:term) { create(:placements_term, :autumn) } + before { given_i_am_signed_in_as_a_placements_support_user } + scenario "view a school's empty placements list" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_placements_page(another_school) then_i_see_no_results end context "with placements" do scenario "view a school's placements as a support user" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_placements_page(school) then_i_see_a_list_of_the_schools_placements and_i_dont_see_placements_from_another_school end scenario "where the placement has a provider" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_placements_page(school) then_i_see_a_list_of_the_schools_placements and_i_dont_see_placements_from_another_school @@ -43,8 +38,6 @@ end scenario "where the placement has no provider" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_placements_page(school) then_i_see_a_list_of_the_schools_placements and_i_dont_see_placements_from_another_school @@ -52,16 +45,12 @@ end scenario "when the placement has no terms" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in when_i_visit_the_school_placements_page(school) then_i_see_a_list_of_the_schools_placements then_i_see_the_term_name("Any time in the academic year") end scenario "when the placement has terms" do - user_exists_in_dfe_sign_in(user: colin) - given_i_sign_in and_the_placement_has_terms(placement1, term) when_i_visit_the_school_placements_page(school) then_i_see_the_term_name("Autumn term") @@ -70,11 +59,6 @@ private - def given_i_sign_in - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_visit_the_school_placements_page(school) visit placements_school_placements_path(school) end diff --git a/spec/system/placements/support/schools/support_user_adds_a_school_spec.rb b/spec/system/placements/support/schools/support_user_adds_a_school_spec.rb index 07fb6be01..3b5f11a41 100644 --- a/spec/system/placements/support/schools/support_user_adds_a_school_spec.rb +++ b/spec/system/placements/support/schools/support_user_adds_a_school_spec.rb @@ -6,7 +6,7 @@ before do school - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end after { Capybara.app_host = nil } @@ -64,25 +64,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_path - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_path - and_i_click_sign_in - end - def when_i_visit_the_add_organisation_page visit new_add_organisation_placements_support_organisations_path diff --git a/spec/system/placements/support/schools/support_user_adds_a_school_without_javascript_spec.rb b/spec/system/placements/support/schools/support_user_adds_a_school_without_javascript_spec.rb index 5e236a151..5d6f2c371 100644 --- a/spec/system/placements/support/schools/support_user_adds_a_school_without_javascript_spec.rb +++ b/spec/system/placements/support/schools/support_user_adds_a_school_without_javascript_spec.rb @@ -6,7 +6,7 @@ create(:school, name: "Manchester 2") create(:school, name: "London") - given_i_sign_in_as_colin + given_i_am_signed_in_as_a_placements_support_user end scenario "Colin adds a new School" do @@ -79,25 +79,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_page - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_sign_in_as_colin - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_page - and_i_click_sign_in - end - def when_i_visit_the_add_organisation_page visit new_add_organisation_placements_support_organisations_path diff --git a/spec/system/placements/support/schools/view_school_as_support_user_spec.rb b/spec/system/placements/support/schools/view_school_as_support_user_spec.rb index 9fc5b5283..d4d6ebe81 100644 --- a/spec/system/placements/support/schools/view_school_as_support_user_spec.rb +++ b/spec/system/placements/support/schools/view_school_as_support_user_spec.rb @@ -9,7 +9,7 @@ end scenario "Support user navigates to different organisations on the list" do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user when_i_click_on_a_organisation_name(school.name) and_i_click_on("Organisation details") then_i_see_the_school_details @@ -21,13 +21,6 @@ private - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def when_i_click_on_a_organisation_name(name) click_on name end diff --git a/spec/system/placements/support/support_users/support_user_adds_a_support_user_spec.rb b/spec/system/placements/support/support_users/support_user_adds_a_support_user_spec.rb index 279801f27..45168c17d 100644 --- a/spec/system/placements/support/support_users/support_user_adds_a_support_user_spec.rb +++ b/spec/system/placements/support/support_users/support_user_adds_a_support_user_spec.rb @@ -8,10 +8,8 @@ perform_enqueued_jobs { example.run } end - let!(:support_user) { create(:placements_support_user, :colin) } - scenario "Add a support user" do - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form(email_address: "john.doe@education.gov.uk") @@ -22,7 +20,7 @@ end scenario "Attempt to add a support user without an @education.gov.uk email address" do - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form(email_address: "john.doe@example.com") @@ -32,7 +30,7 @@ scenario "Attempt to add a support user with an email that already exists in the system" do given_there_is_a_support_user_with(email_address: "john.doe@education.gov.uk") - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form(email_address: "john.doe@education.gov.uk") @@ -41,7 +39,7 @@ end scenario "Make changes while adding a support user" do - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form(email_address: "john.doe@education.gov.uk") @@ -59,12 +57,6 @@ def given_there_is_a_support_user_with(email_address:) create(:placements_support_user, email: email_address) end - def when_i_sign_in_as_a_support_user(support_user) - user_exists_in_dfe_sign_in(user: support_user) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def and_i_visit_the_support_users_page within(".govuk-header__navigation-list") do click_on "Support users" diff --git a/spec/system/placements/support/support_users/support_user_re_adds_a_discarded_support_user_spec.rb b/spec/system/placements/support/support_users/support_user_re_adds_a_discarded_support_user_spec.rb index 33a1709dd..c1eb98dff 100644 --- a/spec/system/placements/support/support_users/support_user_re_adds_a_discarded_support_user_spec.rb +++ b/spec/system/placements/support/support_users/support_user_re_adds_a_discarded_support_user_spec.rb @@ -8,15 +8,13 @@ perform_enqueued_jobs { example.run } end - let!(:support_user) { create(:placements_support_user, :colin) } - scenario "Re-add a discarded support user" do given_a_discarded_support_user_with( email_address: "john.doe@education.gov.uk", first_name: "John", last_name: "Doe", ) - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form( @@ -41,7 +39,7 @@ first_name: "John", last_name: "Doe", ) - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form( @@ -66,7 +64,7 @@ first_name: "John", last_name: "Doe", ) - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_add_a_support_user and_i_fill_in_the_support_user_form( @@ -84,12 +82,6 @@ def given_a_discarded_support_user_with(email_address:, first_name:, last_name:) create(:placements_support_user, :discarded, email: email_address, first_name:, last_name:) end - def when_i_sign_in_as_a_support_user(support_user) - user_exists_in_dfe_sign_in(user: support_user) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def and_i_visit_the_support_users_page within(".govuk-header__navigation-list") do click_on "Support users" diff --git a/spec/system/placements/support/support_users/support_user_removes_a_support_user_spec.rb b/spec/system/placements/support/support_users/support_user_removes_a_support_user_spec.rb index 411726e4a..3093bfcdd 100644 --- a/spec/system/placements/support/support_users/support_user_removes_a_support_user_spec.rb +++ b/spec/system/placements/support/support_users/support_user_removes_a_support_user_spec.rb @@ -12,7 +12,7 @@ let!(:support_user_to_be_removed) { create(:placements_support_user) } scenario "Remove a support user" do - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_a_support_user(support_user_to_be_removed) and_i_click_on_remove @@ -23,7 +23,7 @@ end scenario "A support user can not remove themselves as a support user" do - when_i_sign_in_as_a_support_user(support_user) + given_i_sign_in_as(support_user) and_i_visit_the_support_users_page and_i_click_on_a_support_user(support_user) then_i_can_not_see_a_remove_link diff --git a/spec/system/placements/support/support_users/support_user_views_a_support_user_spec.rb b/spec/system/placements/support/support_users/support_user_views_a_support_user_spec.rb index 2cbc59cc2..a92ec8958 100644 --- a/spec/system/placements/support/support_users/support_user_views_a_support_user_spec.rb +++ b/spec/system/placements/support/support_users/support_user_views_a_support_user_spec.rb @@ -1,10 +1,10 @@ require "rails_helper" RSpec.describe "Placements / Support Users / Support user views a support user", service: :placements, type: :system do - let!(:support_user) { create(:placements_support_user, :colin) } + let!(:support_user) { create(:placements_support_user) } scenario "View a support user" do - when_i_sign_in_as_a_support_user(support_user) + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_support_users_page and_i_click_on_a_support_user(support_user) i_see_the_details_of_the_support_user(support_user) @@ -12,27 +12,21 @@ private - def when_i_sign_in_as_a_support_user(support_user) - user_exists_in_dfe_sign_in(user: support_user) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def and_i_visit_the_support_users_page within(".govuk-header__navigation-list") do click_on "Support users" end end - def and_i_click_on_a_support_user(_support_user) - click_on "Colin Chapman" + def and_i_click_on_a_support_user(support_user) + click_on support_user.full_name end - def i_see_the_details_of_the_support_user(_support_user) - expect(page).to have_selector("h1", text: "Colin Chapman") + def i_see_the_details_of_the_support_user(support_user) + expect(page).to have_selector("h1", text: support_user.full_name) - expect(page).to have_content "Colin" - expect(page).to have_content "Chapman" - expect(page).to have_content "colin.chapman@education.gov.uk" + expect(page).to have_content support_user.first_name + expect(page).to have_content support_user.last_name + expect(page).to have_content support_user.email end end diff --git a/spec/system/placements/support/support_users/support_user_views_support_users_spec.rb b/spec/system/placements/support/support_users/support_user_views_support_users_spec.rb index ff1b0a2c1..42d3ad9b4 100644 --- a/spec/system/placements/support/support_users/support_user_views_support_users_spec.rb +++ b/spec/system/placements/support/support_users/support_user_views_support_users_spec.rb @@ -6,19 +6,13 @@ let!(:support_user_2) { create(:placements_support_user, created_at: "2024-01-01") } scenario "View list of all support users" do - when_i_sign_in_as_a_support_user(support_user) + given_i_sign_in_as(support_user) and_i_visit_the_support_users_page i_see_the_list_of_all_support_users_ordered_by_latest_created_at_first end private - def when_i_sign_in_as_a_support_user(support_user) - user_exists_in_dfe_sign_in(user: support_user) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def and_i_visit_the_support_users_page within(".govuk-header__navigation-list") do click_on "Support users" diff --git a/spec/system/placements/support/users/support_user_deletes_a_user_spec.rb b/spec/system/placements/support/users/support_user_deletes_a_user_spec.rb index f3a9a726b..07aef6a3b 100644 --- a/spec/system/placements/support/users/support_user_deletes_a_user_spec.rb +++ b/spec/system/placements/support/users/support_user_deletes_a_user_spec.rb @@ -16,7 +16,7 @@ end scenario "user is deleted from a school" do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_user_page(school) when_i_click_on("Delete user") then_i_am_asked_to_confirm(school) @@ -39,7 +39,7 @@ end scenario "user is deleted from a provider" do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_user_page(provider) when_i_click_on("Delete user") then_i_am_asked_to_confirm(provider) @@ -64,7 +64,7 @@ end scenario "user is deleted from one organisation but when other memberships exist" do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user and_i_visit_the_user_page(school) when_i_delete_user_from_school then_user_is_still_member_of_provider @@ -86,13 +86,6 @@ def then_user_is_still_member_of_provider expect(page).to have_content user.full_name end - def given_i_am_signed_in_as_a_support_user - user = create(:placements_support_user, :colin) - user_exists_in_dfe_sign_in(user:) - visit sign_in_path - click_on "Sign in using DfE Sign In" - end - def and_i_visit_the_user_page(organisation) click_on organisation.name within(".app-primary-navigation__list") do diff --git a/spec/system/placements/support/users/support_user_invites_a_new_user_spec.rb b/spec/system/placements/support/users/support_user_invites_a_new_user_spec.rb index 6becb886b..5b5697a47 100644 --- a/spec/system/placements/support/users/support_user_invites_a_new_user_spec.rb +++ b/spec/system/placements/support/users/support_user_invites_a_new_user_spec.rb @@ -17,7 +17,7 @@ end before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end describe "School" do @@ -116,26 +116,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_root_path - visit placements_root_path - end - - def and_i_click_on_sign_in - click_on "Start now" - click_on "Sign in using DfE Sign In" - end - - def given_i_am_signed_in_as_a_support_user - and_there_is_an_existing_user_for("Colin") - and_i_visit_root_path - and_i_click_on_sign_in - end - def when_i_visit_the_users_page_for(organisation:) click_on organisation.name within(".app-primary-navigation__list") do diff --git a/spec/system/placements/support/users/support_user_views_a_user_spec.rb b/spec/system/placements/support/users/support_user_views_a_user_spec.rb index c52cb10bb..1bfb38357 100644 --- a/spec/system/placements/support/users/support_user_views_a_user_spec.rb +++ b/spec/system/placements/support/users/support_user_views_a_user_spec.rb @@ -17,7 +17,7 @@ end before do - given_i_am_signed_in_as_a_support_user + given_i_am_signed_in_as_a_placements_support_user end describe "schools" do @@ -52,25 +52,6 @@ private - def and_there_is_an_existing_user_for(user_name) - user = create(:placements_support_user, user_name.downcase.to_sym) - user_exists_in_dfe_sign_in(user:) - end - - def and_i_visit_the_sign_in_page - visit sign_in_path - end - - def and_i_click_sign_in - click_on "Sign in using DfE Sign In" - end - - def given_i_am_signed_in_as_a_support_user - and_there_is_an_existing_user_for("Colin") - and_i_visit_the_sign_in_page - and_i_click_sign_in - end - def given_users_have_been_assigned_to_the(organisation:) [mary, anne].each do |user| create(:user_membership, user:, organisation:) diff --git a/spec/system/placements/support/view_emails_spec.rb b/spec/system/placements/support/view_emails_spec.rb index d73876daf..38f5d29ad 100644 --- a/spec/system/placements/support/view_emails_spec.rb +++ b/spec/system/placements/support/view_emails_spec.rb @@ -4,8 +4,7 @@ let(:support_user) { create(:placements_support_user) } before do - user_exists_in_dfe_sign_in(user: support_user) - given_i_sign_in + given_i_am_signed_in_as_a_placements_support_user end scenario "User visits the emails page" do