Browse Source

CLDC-1797 Do not route to managing org if it can be inferred (#1747)

* Do not route to managing org if it can be inferred

* Update feature test
pull/1751/head
kosiakkatrina 1 year ago committed by GitHub
parent
commit
6fb57142ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/form/lettings/pages/managing_organisation.rb
  2. 8
      spec/features/lettings_log_spec.rb
  3. 21
      spec/models/form/lettings/pages/managing_organisation_spec.rb

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

@ -20,6 +20,7 @@ class Form::Lettings::Pages::ManagingOrganisation < ::Form::Page
end end
return false unless organisation return false unless organisation
return false if log.owning_organisation != organisation && !organisation.holds_own_stock?
return true unless organisation.holds_own_stock? return true unless organisation.holds_own_stock?
organisation.managing_agents.count >= 1 organisation.managing_agents.count >= 1

8
spec/features/lettings_log_spec.rb

@ -338,7 +338,7 @@ RSpec.describe "Lettings Log Features" do
let!(:org_rel1) { create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: owning_org1) } let!(:org_rel1) { create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: owning_org1) }
let!(:org_rel2) { create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: owning_org2) } let!(:org_rel2) { create(:organisation_relationship, child_organisation: user.organisation, parent_organisation: owning_org2) }
it "shows the managing organisation question" do it "does not show the managing organisation question, because managing organisation can be inferred" do
user.organisation.update!(holds_own_stock: false) user.organisation.update!(holds_own_stock: false)
visit("/lettings-logs") visit("/lettings-logs")
click_button("Create a new lettings log") click_button("Create a new lettings log")
@ -347,13 +347,11 @@ RSpec.describe "Lettings Log Features" do
expect(page).to have_current_path("/lettings-logs/#{log_id}/stock-owner") expect(page).to have_current_path("/lettings-logs/#{log_id}/stock-owner")
select(owning_org1.name, from: "lettings-log-owning-organisation-id-field") select(owning_org1.name, from: "lettings-log-owning-organisation-id-field")
click_button("Save and continue") click_button("Save and continue")
expect(page).to have_current_path("/lettings-logs/#{log_id}/managing-organisation")
select(user.organisation.name, from: "lettings-log-managing-organisation-id-field")
click_button("Save and continue")
visit("lettings-logs/#{log_id}/setup/check-answers") visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Managing agent User org", normalize_ws: true) expect(page).not_to have_content("Managing agent User org", normalize_ws: true)
expect(user.organisation.stock_owners).to eq([org_rel1.parent_organisation, org_rel2.parent_organisation]) expect(user.organisation.stock_owners).to eq([org_rel1.parent_organisation, org_rel2.parent_organisation])
expect(LettingsLog.find(log_id).managing_organisation).to eq(user.organisation)
end end
end end

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

@ -105,15 +105,30 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
context "when not support" do context "when not support" do
context "when does not hold own stock" do context "when does not hold own stock" do
let(:user) do let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false))
end context "and the user's organisation is selected as owning organisation" do
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)
end end
end end
context "and a different than the user's organisation is selected as owning organisation" do
let(:stock_owner) { create(:organisation, holds_own_stock: true) }
let(:log) { create(:lettings_log, owning_organisation: stock_owner) }
before do
create(:organisation_relationship, parent_organisation: stock_owner, child_organisation: user.organisation)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
end
end
context "when holds own stock" do context "when holds own stock" do
let(:user) do let(:user) do
create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true))

Loading…
Cancel
Save