Browse Source

CLDC-2139 Show location details under scheme when inferred (#1460)

* feat: display location name and postcode in scheme iff inferred

* feat: add tests

* refactor: po review

* Bump nokogiri (#1530)

---------

Co-authored-by: Jack <113976590+bibblobcode@users.noreply.github.com>
pull/1548/head
natdeanlewissoftwire 2 years ago committed by GitHub
parent
commit
c35826313e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/models/form/lettings/questions/scheme_id.rb
  2. 6
      app/models/form/question.rb
  3. 2
      spec/models/form/lettings/questions/address_line1_spec.rb
  4. 39
      spec/models/form/lettings/questions/scheme_id_spec.rb
  5. 2
      spec/models/form/sales/questions/address_line1_spec.rb
  6. 1
      spec/models/lettings_log_spec.rb

9
app/models/form/lettings/questions/scheme_id.rb

@ -9,6 +9,11 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question
@guidance_position = GuidancePosition::BOTTOM @guidance_position = GuidancePosition::BOTTOM
@guidance_partial = "scheme_selection" @guidance_partial = "scheme_selection"
@question_number = 9 @question_number = 9
@inferred_answers = {
"location.name": {
"scheme_has_multiple_locations?": false,
},
}
end end
def answer_options def answer_options
@ -41,6 +46,10 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question
!supported_housing_selected?(lettings_log) !supported_housing_selected?(lettings_log)
end end
def get_extra_check_answer_value(lettings_log)
lettings_log.form.get_question("postcode_full", nil).label_from_value(lettings_log.postcode_full) unless lettings_log.scheme_has_multiple_locations?
end
private private
def supported_housing_selected?(lettings_log) def supported_housing_selected?(lettings_log)

6
app/models/form/question.rb

@ -317,7 +317,11 @@ private
end end
def enabled_inferred_answers(inferred_answers, log) def enabled_inferred_answers(inferred_answers, log)
inferred_answers.filter { |_key, value| value.all? { |condition_key, condition_value| log[condition_key] == condition_value } } inferred_answers.filter do |_attribute, condition|
condition.all? do |condition_key, condition_value|
log.public_send(condition_key) == condition_value
end
end
end end
def inferred_answer_value(log) def inferred_answer_value(log)

2
spec/models/form/lettings/questions/address_line1_spec.rb

@ -64,7 +64,7 @@ RSpec.describe Form::Lettings::Questions::AddressLine1, type: :model do
end end
end end
context "when la is present but inferred" do context "when la is present and inferred" do
let(:log) { create(:lettings_log, la: "E09000003") } let(:log) { create(:lettings_log, la: "E09000003") }
before do before do

39
spec/models/form/lettings/questions/scheme_id_spec.rb

@ -39,6 +39,45 @@ RSpec.describe Form::Lettings::Questions::SchemeId, type: :model do
expect(question.derived?).to be false expect(question.derived?).to be false
end end
it "has the correct inferred_answers" do
expect(question.inferred_answers).to eq({
"location.name": {
"scheme_has_multiple_locations?": false,
},
})
end
describe "has the correct get_extra_check_answer_value" do
let(:scheme) { create(:scheme) }
context "when locations are present but not inferred" do
let(:lettings_log) { create(:lettings_log) }
before do
allow(lettings_log).to receive(:scheme_has_multiple_locations?).and_return(true)
end
it "returns nil" do
expect(question.get_extra_check_answer_value(lettings_log)).to be_nil
end
end
context "when location is present and inferred" do
let!(:location) { create(:location, scheme:) }
let!(:lettings_log) { create(:lettings_log, scheme:, location:) }
let(:real_2022_2023_form) { Form.new("config/forms/2022_2023.json") }
before do
allow(lettings_log).to receive(:scheme_has_multiple_locations?).and_return(false)
allow(lettings_log).to receive(:form).and_return(real_2022_2023_form)
end
it "returns the postcode" do
expect(question.get_extra_check_answer_value(lettings_log)).to eq(location.postcode)
end
end
end
context "when a user is signed in" do context "when a user is signed in" do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:organisation_2) { FactoryBot.create(:organisation) } let(:organisation_2) { FactoryBot.create(:organisation) }

2
spec/models/form/sales/questions/address_line1_spec.rb

@ -64,7 +64,7 @@ RSpec.describe Form::Sales::Questions::AddressLine1, type: :model do
end end
end end
context "when la is present but inferred" do context "when la is present and inferred" do
let(:log) { create(:sales_log, la: "E09000003") } let(:log) { create(:sales_log, la: "E09000003") }
before do before do

1
spec/models/lettings_log_spec.rb

@ -7,7 +7,6 @@ RSpec.describe LettingsLog do
let(:created_by_user) { create(:user) } let(:created_by_user) { create(:user) }
let(:owning_organisation) { created_by_user.organisation } let(:owning_organisation) { created_by_user.organisation }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") } let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
let(:fake_2022_2023_form) { Form.new("spec/fixtures/forms/2022_2023.json") }
around do |example| around do |example|
Timecop.freeze(Time.utc(2022, 1, 1)) do Timecop.freeze(Time.utc(2022, 1, 1)) do

Loading…
Cancel
Save