From e89cc309574870a2bdbe24a05bc04bb0524b90bc Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 11 Jan 2023 11:41:31 +0000 Subject: [PATCH] tests: update tests --- app/controllers/schemes_controller.rb | 31 ++------------ app/models/scheme.rb | 4 -- .../imports/scheme_location_import_service.rb | 2 - spec/features/schemes_helpers.rb | 16 ++++++- spec/features/schemes_spec.rb | 31 +++----------- spec/helpers/schemes_helper_spec.rb | 2 - spec/requests/schemes_controller_spec.rb | 42 ++----------------- .../imports/scheme_import_service_spec.rb | 4 +- 8 files changed, 28 insertions(+), 104 deletions(-) diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index ad274d074..4e0cac8ae 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -94,8 +94,10 @@ class SchemesController < ApplicationController if @scheme.errors.empty? && @scheme.save redirect_to scheme_primary_client_group_path(@scheme) else - @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) - @scheme.errors.delete(:owning_organisation) + if @scheme.errors.any? { |error| error.attribute == :owning_organisation} + @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) + @scheme.errors.delete(:owning_organisation) + end render :new, status: :unprocessable_entity end end @@ -233,7 +235,6 @@ private required_params = params.require(:scheme).permit(:service_name, :sensitive, :owning_organisation_id, - :managing_organisation_id, :scheme_type, :registered_under_care_act, :id, @@ -245,14 +246,6 @@ private :intended_stay, :confirmed) - if arrangement_type_changed_to_different_org?(required_params) - required_params[:managing_organisation_id] = nil - end - - if arrangement_type_set_to_same_org?(required_params) - required_params[:managing_organisation_id] = required_params[:owning_organisation_id] || @scheme.owning_organisation_id - end - required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive] if current_user.data_coordinator? @@ -261,22 +254,6 @@ private required_params end - def arrangement_type_set_to_same_org?(required_params) - return unless @scheme - - arrangement_type_value(required_params[:arrangement_type]) == "D" || (required_params[:arrangement_type].blank? && @scheme.arrangement_type_same?) - end - - def arrangement_type_changed_to_different_org?(required_params) - return unless @scheme - - @scheme.arrangement_type_same? && arrangement_type_value(required_params[:arrangement_type]) != "D" && required_params[:managing_organisation_id].blank? - end - - def arrangement_type_value(key) - key.present? ? Scheme::ARRANGEMENT_TYPE[key.to_sym] : nil - end - def search_term params["search"] end diff --git a/app/models/scheme.rb b/app/models/scheme.rb index ced65ac67..a5a0af5ae 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -190,10 +190,6 @@ class Scheme < ApplicationRecord Scheme.intended_stays.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) } end - def arrangement_type_same? - arrangement_type.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D" - end - def validate_confirmed required_attributes = attribute_names - %w[id created_at updated_at old_id old_visible_id confirmed end_date sensitive secondary_client_group total_units has_other_client_group deactivation_date deactivation_date_type managing_organisation_id] diff --git a/app/services/imports/scheme_location_import_service.rb b/app/services/imports/scheme_location_import_service.rb index 5b77dfddd..ab5faad27 100644 --- a/app/services/imports/scheme_location_import_service.rb +++ b/app/services/imports/scheme_location_import_service.rb @@ -38,8 +38,6 @@ module Imports end_date: attributes["end_date"], # These values were set by the scheme import (management groups) owning_organisation_id: source_scheme.owning_organisation_id, - # change this? - managing_organisation_id: source_scheme.managing_organisation_id, service_name: source_scheme.service_name, arrangement_type: source_scheme.arrangement_type, old_id: source_scheme.old_id, diff --git a/spec/features/schemes_helpers.rb b/spec/features/schemes_helpers.rb index 68c5d9dee..4ce1063c1 100644 --- a/spec/features/schemes_helpers.rb +++ b/spec/features/schemes_helpers.rb @@ -38,11 +38,16 @@ module SchemesHelpers click_button "Save and continue" end - def fill_in_and_save_secondary_client_group_confirmation + def fill_in_and_save_secondary_client_group_confirmation_yes choose "Yes" click_button "Save and continue" end + def fill_in_and_save_secondary_client_group_confirmation_no + choose "No" + click_button "Save and continue" + end + def fill_in_and_save_secondary_client_group choose "Offenders and people at risk of offending" click_button "Save and continue" @@ -97,8 +102,15 @@ module SchemesHelpers def create_and_save_a_scheme fill_in_and_save_scheme_details fill_in_and_save_primary_client_group - fill_in_and_save_secondary_client_group_confirmation + fill_in_and_save_secondary_client_group_confirmation_yes fill_in_and_save_secondary_client_group fill_in_and_save_support end + + def create_and_save_a_scheme_no_secondary_client_group + fill_in_and_save_scheme_details + fill_in_and_save_primary_client_group + fill_in_and_save_secondary_client_group_confirmation_no + fill_in_and_save_support + end end diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 4d8d460b9..9521ceaac 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -553,11 +553,11 @@ RSpec.describe "Schemes scheme Features" do context "when changing scheme answers" do before do - create_and_save_a_scheme + create_and_save_a_scheme_no_secondary_client_group end it "displays change links" do - assert_selector "a", text: "Change", count: 12 + assert_selector "a", text: "Change", count: 11 end it "allows changing details questions" do @@ -579,9 +579,10 @@ RSpec.describe "Schemes scheme Features" do end it "indicates if the scheme is not complete" do - click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) - choose "Another registered stock owner" + click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first) + choose "Yes" click_button "Save and continue" + visit("/schemes/#{scheme.id}/check-answers") expect(page).to have_content("You didn’t answer this question") end end @@ -610,29 +611,7 @@ RSpec.describe "Schemes scheme Features" do fill_in_and_save_scheme_details({ "housing_stock_owners" => "Another registered stock owner" }) end - it "lets me fill in the managing organisation details" do - expect(page).to have_content "Which organisation provides the support services used by this scheme?" - end - - it "lets me fill in the scheme details after navigating back" do - click_link "Back" - expect(page).to have_current_path("/schemes/#{scheme.id}/details") - expect(page).to have_content "Scheme name" - expect(page).to have_content "This scheme contains confidential information" - expect(page).to have_content "What is this type of scheme?" - expect(page).to have_content "Who provides the support services used by this scheme?" - expect(page).to have_content "Is this scheme registered under the Care Standards Act 2000?" - end - - it "returns to the support service provider after amending the question" do - click_link "Back" - click_button "Save and continue" - expect(page).to have_current_path("/schemes/#{scheme.id}/support-services-provider") - end - it "lets the primary client group to be selected" do - select another_organisation.name, from: "scheme-managing-organisation-id-field" - click_button "Save and continue" expect(page).to have_content "What client group is this scheme intended for?" end diff --git a/spec/helpers/schemes_helper_spec.rb b/spec/helpers/schemes_helper_spec.rb index af9f133ed..1b1b1f531 100644 --- a/spec/helpers/schemes_helper_spec.rb +++ b/spec/helpers/schemes_helper_spec.rb @@ -120,7 +120,6 @@ RSpec.describe SchemesHelper do { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" }, { name: "Housing stock owned by", value: "Acme LTD Owning", edit: true }, { name: "Support services provided by", value: "A registered charity or voluntary organisation" }, - { name: "Organisation providing support", value: "Acme LTD Managing" }, { name: "Primary client group", value: "Rough sleepers" }, { name: "Has another client group", value: "Yes" }, { name: "Secondary client group", value: "Refugees (permanent)" }, @@ -140,7 +139,6 @@ RSpec.describe SchemesHelper do { name: "Type of scheme", value: "Housing for older people" }, { name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" }, { name: "Support services provided by", value: "A registered charity or voluntary organisation" }, - { name: "Organisation providing support", value: "Acme LTD Managing" }, { name: "Primary client group", value: "Rough sleepers" }, { name: "Has another client group", value: "Yes" }, { name: "Secondary client group", value: "Refugees (permanent)" }, diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 5417e79f1..7d8e7b595 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -451,7 +451,7 @@ RSpec.describe SchemesController, type: :request do expect { post "/schemes", params: }.to change(Scheme, :count).by(1) follow_redirect! expect(response).to have_http_status(:ok) - expect(page).to have_content("Which organisation provides the support services used by this scheme?") + expect(page).to have_content(" What client group is this scheme intended for?") end it "creates a new scheme for user organisation with valid params" do @@ -557,7 +557,7 @@ RSpec.describe SchemesController, type: :request do expect { post "/schemes", params: }.to change(Scheme, :count).by(1) follow_redirect! expect(response).to have_http_status(:ok) - expect(page).to have_content("Which organisation provides the support services used by this scheme?") + expect(page).to have_content("What client group is this scheme intended for?") end it "creates a new scheme for user organisation with valid params" do @@ -642,11 +642,11 @@ RSpec.describe SchemesController, type: :request do end context "when confirming unfinished scheme" do - let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: "V", confirmed: true, page: "check-answers" } } } + let(:params) { { scheme: { owning_organisation_id: user.organisation.id, arrangement_type: nil, confirmed: true, page: "check-answers" } } } it "does not allow the scheme to be confirmed" do expect(response).to have_http_status(:unprocessable_entity) - expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.managing_organisation_id.invalid")) + expect(page).to have_content(I18n.t("activerecord.errors.models.scheme.attributes.arrangement_type.invalid")) end end @@ -654,7 +654,6 @@ RSpec.describe SchemesController, type: :request do let(:params) do { scheme: { service_name: "", - managing_organisation_id: "", primary_client_group: "", secondary_client_group: "", scheme_type: "", @@ -696,36 +695,6 @@ RSpec.describe SchemesController, type: :request do end end - context "when updating support services provider" do - let(:params) { { scheme: { arrangement_type: "Another organisation", managing_organisation_id: organisation.id, page: "support-services-provider" } } } - - it "renders primary client group after successful update" do - follow_redirect! - expect(response).to have_http_status(:ok) - expect(page).to have_content("What client group is this scheme intended for?") - end - - it "updates a scheme with valid params" do - follow_redirect! - expect(scheme_to_update.reload.managing_organisation_id).to eq(organisation.id) - end - - context "when updating from check answers page" do - let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group", check_answers: "true" } } } - - it "renders check answers page after successful update" do - follow_redirect! - expect(response).to have_http_status(:ok) - expect(page).to have_content("Check your changes before creating this scheme") - end - - it "updates a scheme with valid params" do - follow_redirect! - expect(scheme_to_update.reload.primary_client_group).to eq("Homeless families with support needs") - end - end - end - context "when updating primary client group" do let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } } @@ -871,7 +840,6 @@ RSpec.describe SchemesController, type: :request do registered_under_care_act: "No", page: "details", owning_organisation_id: organisation.id, - managing_organisation_id: organisation.id, arrangement_type: "D" } } end @@ -1171,7 +1139,6 @@ RSpec.describe SchemesController, type: :request do expect(scheme_to_update.reload.sensitive).to eq("Yes") expect(scheme_to_update.reload.registered_under_care_act).to eq("No") expect(scheme_to_update.reload.owning_organisation_id).to eq(another_organisation.id) - expect(scheme_to_update.reload.managing_organisation_id).to eq(another_organisation.id) end context "when updating from check answers page" do @@ -1189,7 +1156,6 @@ RSpec.describe SchemesController, type: :request do expect(scheme_to_update.reload.scheme_type).to eq("Foyer") expect(scheme_to_update.reload.sensitive).to eq("Yes") expect(scheme_to_update.reload.registered_under_care_act).to eq("No") - expect(scheme_to_update.reload.managing_organisation_id).to eq(scheme_to_update.owning_organisation_id) end end end diff --git a/spec/services/imports/scheme_import_service_spec.rb b/spec/services/imports/scheme_import_service_spec.rb index 97e9359b5..ac31584c3 100644 --- a/spec/services/imports/scheme_import_service_spec.rb +++ b/spec/services/imports/scheme_import_service_spec.rb @@ -44,7 +44,6 @@ RSpec.describe Imports::SchemeImportService do it "matches expected values" do scheme = scheme_service.create_scheme(scheme_xml) expect(scheme.owning_organisation).to eq(owning_org) - expect(scheme.managing_organisation).to eq(managing_org) expect(scheme.old_id).to eq("6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d") expect(scheme.old_visible_id).to eq("0123") expect(scheme.service_name).to eq("Management Group") @@ -67,10 +66,9 @@ RSpec.describe Imports::SchemeImportService do scheme_xml.at_xpath("//mgmtgroup:agent").content = "" end - it "assigns both owning and managing organisation to the same one" do + it "assigns owning organisation" do scheme = scheme_service.create_scheme(scheme_xml) expect(scheme.owning_organisation).to eq(owning_org) - expect(scheme.managing_organisation).to eq(owning_org) end end end