Browse Source

tests: update tests

pull/1173/head
natdeanlewissoftwire 3 years ago
parent
commit
e89cc30957
  1. 31
      app/controllers/schemes_controller.rb
  2. 4
      app/models/scheme.rb
  3. 2
      app/services/imports/scheme_location_import_service.rb
  4. 16
      spec/features/schemes_helpers.rb
  5. 31
      spec/features/schemes_spec.rb
  6. 2
      spec/helpers/schemes_helper_spec.rb
  7. 42
      spec/requests/schemes_controller_spec.rb
  8. 4
      spec/services/imports/scheme_import_service_spec.rb

31
app/controllers/schemes_controller.rb

@ -94,8 +94,10 @@ class SchemesController < ApplicationController
if @scheme.errors.empty? && @scheme.save if @scheme.errors.empty? && @scheme.save
redirect_to scheme_primary_client_group_path(@scheme) redirect_to scheme_primary_client_group_path(@scheme)
else else
@scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation]) if @scheme.errors.any? { |error| error.attribute == :owning_organisation}
@scheme.errors.delete(:owning_organisation) @scheme.errors.add(:owning_organisation_id, message: @scheme.errors[:organisation])
@scheme.errors.delete(:owning_organisation)
end
render :new, status: :unprocessable_entity render :new, status: :unprocessable_entity
end end
end end
@ -233,7 +235,6 @@ private
required_params = params.require(:scheme).permit(:service_name, required_params = params.require(:scheme).permit(:service_name,
:sensitive, :sensitive,
:owning_organisation_id, :owning_organisation_id,
:managing_organisation_id,
:scheme_type, :scheme_type,
:registered_under_care_act, :registered_under_care_act,
:id, :id,
@ -245,14 +246,6 @@ private
:intended_stay, :intended_stay,
:confirmed) :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] required_params[:sensitive] = required_params[:sensitive].to_i if required_params[:sensitive]
if current_user.data_coordinator? if current_user.data_coordinator?
@ -261,22 +254,6 @@ private
required_params required_params
end 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 def search_term
params["search"] params["search"]
end end

4
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]) } Scheme.intended_stays.keys.excluding("Missing").map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize, description: hints[key.to_sym]) }
end end
def arrangement_type_same?
arrangement_type.present? && ARRANGEMENT_TYPE[arrangement_type.to_sym] == "D"
end
def validate_confirmed 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] 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]

2
app/services/imports/scheme_location_import_service.rb

@ -38,8 +38,6 @@ module Imports
end_date: attributes["end_date"], end_date: attributes["end_date"],
# These values were set by the scheme import (management groups) # These values were set by the scheme import (management groups)
owning_organisation_id: source_scheme.owning_organisation_id, owning_organisation_id: source_scheme.owning_organisation_id,
# change this?
managing_organisation_id: source_scheme.managing_organisation_id,
service_name: source_scheme.service_name, service_name: source_scheme.service_name,
arrangement_type: source_scheme.arrangement_type, arrangement_type: source_scheme.arrangement_type,
old_id: source_scheme.old_id, old_id: source_scheme.old_id,

16
spec/features/schemes_helpers.rb

@ -38,11 +38,16 @@ module SchemesHelpers
click_button "Save and continue" click_button "Save and continue"
end end
def fill_in_and_save_secondary_client_group_confirmation def fill_in_and_save_secondary_client_group_confirmation_yes
choose "Yes" choose "Yes"
click_button "Save and continue" click_button "Save and continue"
end 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 def fill_in_and_save_secondary_client_group
choose "Offenders and people at risk of offending" choose "Offenders and people at risk of offending"
click_button "Save and continue" click_button "Save and continue"
@ -97,8 +102,15 @@ module SchemesHelpers
def create_and_save_a_scheme def create_and_save_a_scheme
fill_in_and_save_scheme_details fill_in_and_save_scheme_details
fill_in_and_save_primary_client_group 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_secondary_client_group
fill_in_and_save_support fill_in_and_save_support
end 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 end

31
spec/features/schemes_spec.rb

@ -553,11 +553,11 @@ RSpec.describe "Schemes scheme Features" do
context "when changing scheme answers" do context "when changing scheme answers" do
before do before do
create_and_save_a_scheme create_and_save_a_scheme_no_secondary_client_group
end end
it "displays change links" do it "displays change links" do
assert_selector "a", text: "Change", count: 12 assert_selector "a", text: "Change", count: 11
end end
it "allows changing details questions" do it "allows changing details questions" do
@ -579,9 +579,10 @@ RSpec.describe "Schemes scheme Features" do
end end
it "indicates if the scheme is not complete" do it "indicates if the scheme is not complete" do
click_link("Change", href: "/schemes/#{scheme.id}/details?check_answers=true", match: :first) click_link("Change", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?check_answers=true", match: :first)
choose "Another registered stock owner" choose "Yes"
click_button "Save and continue" click_button "Save and continue"
visit("/schemes/#{scheme.id}/check-answers")
expect(page).to have_content("You didn’t answer this question") expect(page).to have_content("You didn’t answer this question")
end end
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" }) fill_in_and_save_scheme_details({ "housing_stock_owners" => "Another registered stock owner" })
end 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 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?" expect(page).to have_content "What client group is this scheme intended for?"
end end

2
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: "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: "Housing stock owned by", value: "Acme LTD Owning", edit: true },
{ name: "Support services provided by", value: "A registered charity or voluntary organisation" }, { 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: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" }, { name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" }, { 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: "Type of scheme", value: "Housing for older people" },
{ name: "Registered under Care Standards Act 2000", value: "Yes – registered care home providing personal care" }, { 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: "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: "Primary client group", value: "Rough sleepers" },
{ name: "Has another client group", value: "Yes" }, { name: "Has another client group", value: "Yes" },
{ name: "Secondary client group", value: "Refugees (permanent)" }, { name: "Secondary client group", value: "Refugees (permanent)" },

42
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) expect { post "/schemes", params: }.to change(Scheme, :count).by(1)
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) 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 end
it "creates a new scheme for user organisation with valid params" do 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) expect { post "/schemes", params: }.to change(Scheme, :count).by(1)
follow_redirect! follow_redirect!
expect(response).to have_http_status(:ok) 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 end
it "creates a new scheme for user organisation with valid params" do it "creates a new scheme for user organisation with valid params" do
@ -642,11 +642,11 @@ RSpec.describe SchemesController, type: :request do
end end
context "when confirming unfinished scheme" do 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 it "does not allow the scheme to be confirmed" do
expect(response).to have_http_status(:unprocessable_entity) 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
end end
@ -654,7 +654,6 @@ RSpec.describe SchemesController, type: :request do
let(:params) do let(:params) do
{ scheme: { { scheme: {
service_name: "", service_name: "",
managing_organisation_id: "",
primary_client_group: "", primary_client_group: "",
secondary_client_group: "", secondary_client_group: "",
scheme_type: "", scheme_type: "",
@ -696,36 +695,6 @@ RSpec.describe SchemesController, type: :request do
end end
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 context "when updating primary client group" do
let(:params) { { scheme: { primary_client_group: "Homeless families with support needs", page: "primary-client-group" } } } 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", registered_under_care_act: "No",
page: "details", page: "details",
owning_organisation_id: organisation.id, owning_organisation_id: organisation.id,
managing_organisation_id: organisation.id,
arrangement_type: "D" } } arrangement_type: "D" } }
end 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.sensitive).to eq("Yes")
expect(scheme_to_update.reload.registered_under_care_act).to eq("No") 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.owning_organisation_id).to eq(another_organisation.id)
expect(scheme_to_update.reload.managing_organisation_id).to eq(another_organisation.id)
end end
context "when updating from check answers page" do 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.scheme_type).to eq("Foyer")
expect(scheme_to_update.reload.sensitive).to eq("Yes") 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.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 end
end end

4
spec/services/imports/scheme_import_service_spec.rb

@ -44,7 +44,6 @@ RSpec.describe Imports::SchemeImportService do
it "matches expected values" do it "matches expected values" do
scheme = scheme_service.create_scheme(scheme_xml) scheme = scheme_service.create_scheme(scheme_xml)
expect(scheme.owning_organisation).to eq(owning_org) 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_id).to eq("6d6d7618b58affe2a150a5ef2e9f4765fa6cd05d")
expect(scheme.old_visible_id).to eq("0123") expect(scheme.old_visible_id).to eq("0123")
expect(scheme.service_name).to eq("Management Group") expect(scheme.service_name).to eq("Management Group")
@ -67,10 +66,9 @@ RSpec.describe Imports::SchemeImportService do
scheme_xml.at_xpath("//mgmtgroup:agent").content = "" scheme_xml.at_xpath("//mgmtgroup:agent").content = ""
end 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) scheme = scheme_service.create_scheme(scheme_xml)
expect(scheme.owning_organisation).to eq(owning_org) expect(scheme.owning_organisation).to eq(owning_org)
expect(scheme.managing_organisation).to eq(owning_org)
end end
end end
end end

Loading…
Cancel
Save