Browse Source

Show HousingProvider in CYA when not inferred

CLDC-20-more-ac-fixes3
Jack S 2 years ago
parent
commit
2a0e16d26a
  1. 11
      app/models/form/lettings/questions/housing_provider.rb
  2. 56
      spec/models/form/lettings/questions/housing_provider_spec.rb

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) def hidden_in_check_answers?(_log, user = nil)
@current_user = user @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 end
def enabled def enabled

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

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

Loading…
Cancel
Save