From 731bad89ffbbde5cfcedcd18dcdec9b2b149f8ad Mon Sep 17 00:00:00 2001 From: Kat Date: Wed, 22 Nov 2023 10:11:24 +0000 Subject: [PATCH] Correctly route to sales owning organisation page --- app/models/form/sales/pages/organisation.rb | 18 ++++++++++++++---- app/services/feature_toggle.rb | 4 ++++ .../form/sales/pages/organisation_spec.rb | 8 ++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/models/form/sales/pages/organisation.rb b/app/models/form/sales/pages/organisation.rb index 6940c2abc..53f10e758 100644 --- a/app/models/form/sales/pages/organisation.rb +++ b/app/models/form/sales/pages/organisation.rb @@ -11,11 +11,15 @@ class Form::Sales::Pages::Organisation < ::Form::Page end def routed_to?(_log, current_user) - if FeatureToggle.merge_organisations_enabled? + return false unless current_user + return true if current_user.support? - return false unless current_user - return true if current_user.support? + if FeatureToggle.sales_managing_organisation_enabled? + return true if stock_owners_with_own_stock_count(current_user) > 1 + return true if current_user.organisation.holds_own_stock? && stock_owners_with_own_stock_count(current_user) >= 1 + end + if FeatureToggle.merge_organisations_enabled? absorbed_stock_owners = current_user.organisation.absorbed_organisations.where(holds_own_stock: true) if current_user.organisation.holds_own_stock? @@ -27,7 +31,13 @@ class Form::Sales::Pages::Organisation < ::Form::Page false else - !!current_user&.support? + !current_user&.support?.nil? end end + +private + + def stock_owners_with_own_stock_count(user) + user.organisation.stock_owners.where(holds_own_stock: true).count + end end diff --git a/app/services/feature_toggle.rb b/app/services/feature_toggle.rb index cdfb31cd9..47ca38b15 100644 --- a/app/services/feature_toggle.rb +++ b/app/services/feature_toggle.rb @@ -43,4 +43,8 @@ class FeatureToggle def self.service_moved? false end + + def self.sales_managing_organisation_enabled? + Rails.env.test? || Rails.env.review? || Rails.env.development? + end end diff --git a/spec/models/form/sales/pages/organisation_spec.rb b/spec/models/form/sales/pages/organisation_spec.rb index 8f160ca53..f6b583640 100644 --- a/spec/models/form/sales/pages/organisation_spec.rb +++ b/spec/models/form/sales/pages/organisation_spec.rb @@ -110,8 +110,8 @@ RSpec.describe Form::Sales::Pages::Organisation, type: :model do ) end - it "is not shown" do - expect(page.routed_to?(log, user)).to eq(false) + it "is shown" do + expect(page.routed_to?(log, user)).to eq(true) end end end @@ -133,8 +133,8 @@ RSpec.describe Form::Sales::Pages::Organisation, type: :model do create(:organisation_relationship, child_organisation: user.organisation) end - it "is not shown" do - expect(page.routed_to?(log, user)).to eq(false) + it "is shown" do + expect(page.routed_to?(log, user)).to eq(true) end end