Browse Source

[CLDC-20] Address more ACs (#1020)

* Bugfix provider_type on nil

* Do not infer managing org

* Always show 'your org' to non support users

* Never show created_by_id in CYA

* Show HousingProvider in CYA when not inferred

* Always show ManagingOrganisation

* Spec fix

* Show ManagingOrganisation if managing agents >=1

* typo
pull/1019/head
Jack S 2 years ago committed by GitHub
parent
commit
c0541b054b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/models/derived_variables/lettings_log_variables.rb
  2. 9
      app/models/form/lettings/pages/managing_organisation.rb
  3. 4
      app/models/form/lettings/questions/created_by_id.rb
  4. 11
      app/models/form/lettings/questions/housing_provider.rb
  5. 8
      app/models/form/lettings/questions/managing_organisation.rb
  6. 6
      spec/features/lettings_log_spec.rb
  7. 48
      spec/models/form/lettings/pages/managing_organisation_spec.rb
  8. 14
      spec/models/form/lettings/questions/created_by_id_spec.rb
  9. 48
      spec/models/form/lettings/questions/housing_provider_spec.rb
  10. 44
      spec/models/form/lettings/questions/managing_organisation_spec.rb

4
app/models/derived_variables/lettings_log_variables.rb

@ -49,8 +49,8 @@ module DerivedVariables::LettingsLogVariables
self.waityear = 2
if is_general_needs?
# fixed term
self.prevten = 32 if managing_organisation.provider_type == "PRP"
self.prevten = 30 if managing_organisation.provider_type == "LA"
self.prevten = 32 if managing_organisation&.provider_type == "PRP"
self.prevten = 30 if managing_organisation&.provider_type == "LA"
end
end

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

@ -25,13 +25,6 @@ class Form::Lettings::Pages::ManagingOrganisation < ::Form::Page
return false unless organisation
return true unless organisation.holds_own_stock?
managing_agents = organisation.managing_agents
return false if managing_agents.count.zero?
return true if managing_agents.count > 1
log.update!(managing_organisation: managing_agents.first)
false
organisation.managing_agents.count >= 1
end
end

4
app/models/form/lettings/questions/created_by_id.rb

@ -35,8 +35,8 @@ class Form::Lettings::Questions::CreatedById < ::Form::Question
answer_options[value]
end
def hidden_in_check_answers?(_log, current_user)
!current_user.support?
def hidden_in_check_answers?(_log, _current_user)
true
end
def derived?

11
app/models/form/lettings/questions/housing_provider.rb

@ -42,10 +42,15 @@ class Form::Lettings::Questions::HousingProvider < ::Form::Question
def hidden_in_check_answers?(_log, user = nil)
@current_user = user
return false unless @current_user
return false if @current_user.support?
return false if current_user.support?
housing_providers_answer_options.count < 2
housing_providers = current_user.organisation.housing_providers
if current_user.organisation.holds_own_stock?
housing_providers.count.zero?
else
housing_providers.count <= 1
end
end
def enabled

8
app/models/form/lettings/questions/managing_organisation.rb

@ -21,7 +21,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
if log.owning_organisation.holds_own_stock?
opts[log.owning_organisation.id] = "#{log.owning_organisation.name} (Owning organisation)"
end
elsif current_user.organisation.holds_own_stock?
else
opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)"
end
@ -47,11 +47,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
def hidden_in_check_answers?(_log, user = nil)
@current_user = user
return false unless @current_user
return false if @current_user.support?
managing_organisations_answer_options.count < 2
@current_user.nil?
end
def enabled

6
spec/features/lettings_log_spec.rb

@ -89,8 +89,7 @@ RSpec.describe "Lettings Log Features" do
log_id = page.current_path.scan(/\d/).join
visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Housing provider #{support_user.organisation.name}")
expect(page).to have_content("Log owner #{support_user.name}")
expect(page).to have_content("You have answered 3 of 9 questions")
expect(page).to have_content("You have answered 2 of 8 questions")
end
end
end
@ -119,8 +118,7 @@ RSpec.describe "Lettings Log Features" do
expect(page).to have_current_path("/lettings-logs/#{log_id}/needs-type")
visit("lettings-logs/#{log_id}/setup/check-answers")
expect(page).not_to have_content("Owning organisation #{user.organisation.name}")
expect(page).not_to have_content("User #{user.name}")
expect(page).to have_content("You have answered 0 of 6 questions")
expect(page).not_to have_content("Log owner #{user.name}")
end
end

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

@ -40,10 +40,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
it "is not shown" do
expect(page.routed_to?(log, nil)).to eq(false)
end
it "does not update managing_organisation_id" do
expect { page.routed_to?(log, nil) }.not_to change(log.reload, :managing_organisation)
end
end
context "when support" do
@ -56,10 +52,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
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 owning_organisation not set" do
@ -69,10 +61,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
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
@ -84,10 +72,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
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 "with >1 managing_agents" do
@ -99,10 +83,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
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 "with 1 managing_agents" do
@ -117,12 +97,8 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "updates managing_organisation_id" do
expect { page.routed_to?(log, user) }.to change(log.reload, :managing_organisation).to(managing_agent)
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
end
end
@ -137,10 +113,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
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
@ -152,10 +124,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
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 "with >1 managing_agents" do
@ -167,10 +135,6 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
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 "with 1 managing_agents" do
@ -185,12 +149,8 @@ RSpec.describe Form::Lettings::Pages::ManagingOrganisation, type: :model do
)
end
it "is not shown" do
expect(page.routed_to?(log, user)).to eq(false)
end
it "updates managing_organisation_id" do
expect { page.routed_to?(log, user) }.to change(log.reload, :managing_organisation).to(managing_agent)
it "is shown" do
expect(page.routed_to?(log, user)).to eq(true)
end
end
end

14
spec/models/form/lettings/questions/created_by_id_spec.rb

@ -51,20 +51,8 @@ RSpec.describe Form::Lettings::Questions::CreatedById, type: :model do
expect(question.derived?).to be true
end
context "when the current user is support" do
let(:support_user) { build(:user, :support) }
it "is shown in check answers" do
expect(question.hidden_in_check_answers?(nil, support_user)).to be false
end
end
context "when the current user is not support" do
let(:user) { build(:user) }
it "is not shown in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be true
end
expect(question.hidden_in_check_answers?(nil, user_1)).to be true
end
context "when the owning organisation is already set" do

48
spec/models/form/lettings/questions/housing_provider_spec.rb

@ -83,35 +83,65 @@ RSpec.describe Form::Lettings::Questions::HousingProvider, type: :model do
end
describe "#hidden_in_check_answers?" do
context "when housing providers < 2" do
context "when not support user" do
let(:user) { create(:user) }
context "when support" do
let(:user) { create(:user, :support) }
it "is not hidden in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false
end
end
context "when org holds own stock", :aggregate_failures do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: true)) }
context "when housing providers == 0" do
before do
user.organisation.housing_providers.delete_all
end
it "is hidden in check answers" do
expect(user.organisation.housing_providers.count).to eq(0)
expect(question.hidden_in_check_answers?(nil, user)).to be true
end
end
context "when support" do
let(:user) { create(:user, :support) }
context "when housing providers != 0" do
before do
create(:organisation_relationship, :owning, child_organisation: user.organisation)
end
it "is not hiddes in check answers" do
it "is visible in check answers" do
expect(user.organisation.housing_providers.count).to eq(1)
expect(question.hidden_in_check_answers?(nil, user)).to be false
end
end
end
context "when housing providers >= 2" do
let(:user) { create(:user) }
context "when org does not hold own stock", :aggregate_failures do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
context "when housing providers <= 1" do
before do
create(:organisation_relationship, :owning, child_organisation: user.organisation)
end
it "is hidden in check answers" do
expect(user.organisation.housing_providers.count).to eq(1)
expect(question.hidden_in_check_answers?(nil, user)).to be true
end
end
context "when housing providers >= 2" do
before do
create(:organisation_relationship, :owning, child_organisation: user.organisation)
create(:organisation_relationship, :owning, child_organisation: user.organisation)
end
it "is not hidden in check answers" do
it "is visible in check answers" do
expect(user.organisation.housing_providers.count).to eq(2)
expect(question.hidden_in_check_answers?(nil, user)).to be false
end
end
end
end
end

44
spec/models/form/lettings/questions/managing_organisation_spec.rb

@ -73,6 +73,27 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end
end
context "when user not support and does not own stock" do
let(:user) { create(:user, :data_coordinator, organisation: create(:organisation, holds_own_stock: false)) }
let(:log) { create(:lettings_log) }
let!(:org_rel1) { create(:organisation_relationship, :managing, parent_organisation: user.organisation) }
let!(:org_rel2) { create(:organisation_relationship, :managing, parent_organisation: user.organisation) }
let(:options) do
{
"" => "Select an option",
user.organisation.id => "#{user.organisation.name} (Your organisation)",
org_rel1.child_organisation.id => org_rel1.child_organisation.name,
org_rel2.child_organisation.id => org_rel2.child_organisation.name,
}
end
it "shows managing agents with own org at the top" do
expect(question.displayed_answer_options(log, user)).to eq(options)
end
end
context "when support user and org does not own own stock" do
let(:user) { create(:user, :support) }
let(:log_owning_org) { create(:organisation, holds_own_stock: false) }
@ -121,34 +142,19 @@ RSpec.describe Form::Lettings::Questions::ManagingOrganisation, type: :model do
end
describe "#hidden_in_check_answers?" do
context "when housing providers < 2" do
context "when not support user" do
context "when user present" do
let(:user) { create(:user) }
it "is hidden in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be true
end
end
context "when support" do
let(:user) { create(:user, :support) }
it "is not hiddes in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false
end
end
end
context "when managing agents >= 2" do
let(:user) { create(:user) }
before do
create(:organisation_relationship, :managing, parent_organisation: user.organisation)
create(:organisation_relationship, :managing, parent_organisation: user.organisation)
end
context "when user not provided" do
let(:user) { create(:user, :support) }
it "is not hidden in check answers" do
expect(question.hidden_in_check_answers?(nil, user)).to be false
expect(question.hidden_in_check_answers?(nil)).to be true
end
end
end

Loading…
Cancel
Save