Browse Source

Hide managing org if housing provider not answered (#1015)

(only for support)
pull/1017/head
Jack S 2 years ago committed by GitHub
parent
commit
d3fc4b7fe8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/models/form/lettings/pages/managing_organisation.rb
  2. 20
      spec/models/form/lettings/pages/managing_organisation_spec.rb

12
app/models/form/lettings/pages/managing_organisation.rb

@ -15,9 +15,17 @@ class Form::Lettings::Pages::ManagingOrganisation < ::Form::Page
def routed_to?(log, current_user) def routed_to?(log, current_user)
return false unless current_user return false unless current_user
return true unless current_user.organisation.holds_own_stock?
managing_agents = current_user.organisation.managing_agents organisation = if current_user.support?
log.owning_organisation
else
current_user.organisation
end
return false unless organisation
return true unless organisation.holds_own_stock?
managing_agents = organisation.managing_agents
return false if managing_agents.count.zero? return false if managing_agents.count.zero?
return true if managing_agents.count > 1 return true if managing_agents.count > 1

20
spec/models/form/lettings/pages/managing_organisation_spec.rb

@ -51,6 +51,7 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
let(:user) do let(:user) do
create(:user, :support, organisation: create(:organisation, holds_own_stock: false)) create(:user, :support, organisation: create(:organisation, holds_own_stock: false))
end end
let(:log) { create(:lettings_log, owning_organisation: user.organisation) }
it "is shown" do it "is shown" do
expect(page.routed_to?(log, user)).to eq(true) expect(page.routed_to?(log, user)).to eq(true)
@ -61,6 +62,19 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
end end
end end
context "when owning_organisation not set" do
let(:user) { create(:user, :support) }
let(:log) { create(:lettings_log, owning_organisation: nil) }
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "does not update managing_organisation_id" do
expect { page.routed_to?(log, user) }.not_to change(log.reload, :managing_organisation)
end
end
context "when holds own stock" do context "when holds own stock" do
let(:user) do let(:user) do
create(:user, :support, organisation: create(:organisation, holds_own_stock: true)) create(:user, :support, organisation: create(:organisation, holds_own_stock: true))
@ -78,8 +92,8 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
context "with >1 managing_agents" do context "with >1 managing_agents" do
before do before do
create(:organisation_relationship, :managing, parent_organisation: user.organisation) create(:organisation_relationship, :managing, parent_organisation: log.owning_organisation)
create(:organisation_relationship, :managing, parent_organisation: user.organisation) create(:organisation_relationship, :managing, parent_organisation: log.owning_organisation)
end end
it "is shown" do it "is shown" do
@ -99,7 +113,7 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
:organisation_relationship, :organisation_relationship,
:managing, :managing,
child_organisation: managing_agent, child_organisation: managing_agent,
parent_organisation: user.organisation, parent_organisation: log.owning_organisation,
) )
end end

Loading…
Cancel
Save