Browse Source

[CLDC-2260] Move UPRN Known and UPRN questions to same page (#1537)

* Set uprn_known to 1 when setting UPRN

* Move fake to dev+test gemfile block

So that we can use factories in local

* Move UPRN known and UPRN questions to single UPRN page
pull/1554/head
Jack 2 years ago committed by GitHub
parent
commit
37fab3fe25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Gemfile
  2. 5
      app/models/form/lettings/pages/uprn.rb
  3. 16
      app/models/form/lettings/pages/uprn_known.rb
  4. 13
      app/models/form/lettings/questions/uprn.rb
  5. 2
      app/models/form/lettings/questions/uprn_known.rb
  6. 1
      app/models/form/lettings/subsections/property_information.rb
  7. 1
      app/models/form/sales/pages/uprn.rb
  8. 12
      app/models/form/sales/pages/uprn_known.rb
  9. 13
      app/models/form/sales/questions/uprn.rb
  10. 8
      app/models/form/sales/questions/uprn_known.rb
  11. 1
      app/models/form/sales/subsections/property_information.rb
  12. 1
      app/models/log.rb
  13. 51
      spec/models/form/lettings/pages/uprn_known_spec.rb
  14. 10
      spec/models/form/lettings/pages/uprn_spec.rb
  15. 4
      spec/models/form/lettings/questions/uprn_known_spec.rb
  16. 46
      spec/models/form/lettings/questions/uprn_spec.rb
  17. 1
      spec/models/form/lettings/subsections/property_information_spec.rb
  18. 33
      spec/models/form/sales/pages/uprn_known_spec.rb
  19. 2
      spec/models/form/sales/pages/uprn_spec.rb
  20. 4
      spec/models/form/sales/questions/uprn_known_spec.rb
  21. 47
      spec/models/form/sales/questions/uprn_spec.rb
  22. 1
      spec/models/form/sales/subsections/property_information_spec.rb
  23. 1
      spec/models/lettings_log_spec.rb
  24. 1
      spec/models/sales_log_spec.rb

2
Gemfile

@ -70,6 +70,7 @@ group :development, :test do
gem "byebug", platforms: %i[mri mingw x64_mingw] gem "byebug", platforms: %i[mri mingw x64_mingw]
gem "dotenv-rails" gem "dotenv-rails"
gem "factory_bot_rails" gem "factory_bot_rails"
gem "faker"
gem "pry-byebug" gem "pry-byebug"
gem "parallel_tests" gem "parallel_tests"
@ -93,7 +94,6 @@ group :test do
gem "capybara", require: false gem "capybara", require: false
gem "capybara-lockstep" gem "capybara-lockstep"
gem "capybara-screenshot" gem "capybara-screenshot"
gem "faker"
gem "rspec-rails", require: false gem "rspec-rails", require: false
gem "selenium-webdriver", require: false gem "selenium-webdriver", require: false
gem "simplecov", require: false gem "simplecov", require: false

5
app/models/form/lettings/pages/uprn.rb

@ -6,14 +6,13 @@ class Form::Lettings::Pages::Uprn < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Lettings::Questions::UprnKnown.new(nil, nil, self),
Form::Lettings::Questions::Uprn.new(nil, nil, self), Form::Lettings::Questions::Uprn.new(nil, nil, self),
] ]
end end
def routed_to?(log, _current_user = nil) def routed_to?(log, _current_user = nil)
return false if log.is_supported_housing? !log.is_supported_housing?
log.uprn_known == 1
end end
def skip_text def skip_text

16
app/models/form/lettings/pages/uprn_known.rb

@ -1,16 +0,0 @@
class Form::Lettings::Pages::UprnKnown < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "uprn_known"
end
def questions
@questions ||= [
Form::Lettings::Questions::UprnKnown.new(nil, nil, self),
]
end
def routed_to?(log, _current_user = nil)
!log.is_supported_housing?
end
end

13
app/models/form/lettings/questions/uprn.rb

@ -5,9 +5,14 @@ class Form::Lettings::Questions::Uprn < ::Form::Question
@check_answer_label = "UPRN" @check_answer_label = "UPRN"
@header = "What is the property's UPRN" @header = "What is the property's UPRN"
@type = "text" @type = "text"
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355."
@width = 10 @width = 10
@question_number = 11 @question_number = 11
@inferred_check_answers_value = [
{
"condition" => { "uprn_known" => 0 },
"value" => "Not known",
},
]
end end
def unanswered_error_message def unanswered_error_message
@ -15,6 +20,8 @@ class Form::Lettings::Questions::Uprn < ::Form::Question
end end
def get_extra_check_answer_value(log) def get_extra_check_answer_value(log)
return unless log.uprn_known == 1
value = [ value = [
log.address_line1, log.address_line1,
log.address_line2, log.address_line2,
@ -28,8 +35,4 @@ class Form::Lettings::Questions::Uprn < ::Form::Question
"\n\n#{value.join("\n")}" "\n\n#{value.join("\n")}"
end end
def hidden_in_check_answers?(log, _current_user = nil)
log.uprn_known != 1
end
end end

2
app/models/form/lettings/questions/uprn_known.rb

@ -8,6 +8,8 @@ class Form::Lettings::Questions::UprnKnown < ::Form::Question
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.<br><br> @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.<br><br>
You can continue without the UPRN, but it means we will need you to enter the address of the property." You can continue without the UPRN, but it means we will need you to enter the address of the property."
@conditional_for = { "uprn" => [1] }
@hidden_in_check_answers = true
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {

1
app/models/form/lettings/subsections/property_information.rb

@ -30,7 +30,6 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection
def uprn_questions def uprn_questions
if form.start_date.year >= 2023 if form.start_date.year >= 2023
[ [
Form::Lettings::Pages::UprnKnown.new(nil, nil, self),
Form::Lettings::Pages::Uprn.new(nil, nil, self), Form::Lettings::Pages::Uprn.new(nil, nil, self),
Form::Lettings::Pages::UprnConfirmation.new(nil, nil, self), Form::Lettings::Pages::UprnConfirmation.new(nil, nil, self),
Form::Lettings::Pages::Address.new(nil, nil, self), Form::Lettings::Pages::Address.new(nil, nil, self),

1
app/models/form/sales/pages/uprn.rb

@ -6,6 +6,7 @@ class Form::Sales::Pages::Uprn < ::Form::Page
def questions def questions
@questions ||= [ @questions ||= [
Form::Sales::Questions::UprnKnown.new(nil, nil, self),
Form::Sales::Questions::Uprn.new(nil, nil, self), Form::Sales::Questions::Uprn.new(nil, nil, self),
] ]
end end

12
app/models/form/sales/pages/uprn_known.rb

@ -1,12 +0,0 @@
class Form::Sales::Pages::UprnKnown < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "uprn_known"
end
def questions
@questions ||= [
Form::Sales::Questions::UprnKnown.new(nil, nil, self),
]
end
end

13
app/models/form/sales/questions/uprn.rb

@ -5,9 +5,14 @@ class Form::Sales::Questions::Uprn < ::Form::Question
@check_answer_label = "UPRN" @check_answer_label = "UPRN"
@header = "What is the property's UPRN" @header = "What is the property's UPRN"
@type = "text" @type = "text"
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355."
@width = 10 @width = 10
@question_number = 14 @question_number = 14
@inferred_check_answers_value = [
{
"condition" => { "uprn_known" => 0 },
"value" => "Not known",
},
]
end end
def unanswered_error_message def unanswered_error_message
@ -15,6 +20,8 @@ class Form::Sales::Questions::Uprn < ::Form::Question
end end
def get_extra_check_answer_value(log) def get_extra_check_answer_value(log)
return unless log.uprn_known == 1
value = [ value = [
log.address_line1, log.address_line1,
log.address_line2, log.address_line2,
@ -28,8 +35,4 @@ class Form::Sales::Questions::Uprn < ::Form::Question
"\n\n#{value.join("\n")}" "\n\n#{value.join("\n")}"
end end
def hidden_in_check_answers?(log, _current_user = nil)
log.uprn_known != 1
end
end end

8
app/models/form/sales/questions/uprn_known.rb

@ -8,6 +8,14 @@ class Form::Sales::Questions::UprnKnown < ::Form::Question
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.<br><br> @hint_text = "The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.<br><br>
You can continue without the UPRN, but it means we will need you to enter the address of the property." You can continue without the UPRN, but it means we will need you to enter the address of the property."
@conditional_for = { "uprn" => [1] }
@inferred_check_answers_value = [
{
"condition" => { "uprn_known" => 0 },
"value" => "Not known",
},
]
@hidden_in_check_answers = true
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {

1
app/models/form/sales/subsections/property_information.rb

@ -24,7 +24,6 @@ class Form::Sales::Subsections::PropertyInformation < ::Form::Subsection
def uprn_questions def uprn_questions
if form.start_date.year >= 2023 if form.start_date.year >= 2023
[ [
Form::Sales::Pages::UprnKnown.new(nil, nil, self),
Form::Sales::Pages::Uprn.new(nil, nil, self), Form::Sales::Pages::Uprn.new(nil, nil, self),
Form::Sales::Pages::UprnConfirmation.new(nil, nil, self), Form::Sales::Pages::UprnConfirmation.new(nil, nil, self),
Form::Sales::Pages::Address.new(nil, nil, self), Form::Sales::Pages::Address.new(nil, nil, self),

1
app/models/log.rb

@ -52,6 +52,7 @@ class Log < ApplicationRecord
presenter = UprnDataPresenter.new(service.result) presenter = UprnDataPresenter.new(service.result)
self.uprn_known = 1
self.uprn_confirmed = nil self.uprn_confirmed = nil
self.address_line1 = presenter.address_line1 self.address_line1 = presenter.address_line1
self.address_line2 = presenter.address_line2 self.address_line2 = presenter.address_line2

51
spec/models/form/lettings/pages/uprn_known_spec.rb

@ -1,51 +0,0 @@
require "rails_helper"
RSpec.describe Form::Lettings::Pages::UprnKnown, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[uprn_known])
end
it "has the correct id" do
expect(page.id).to eq("uprn_known")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
describe "has correct routed_to?" do
context "when needstype != 2" do
let(:log) { create(:lettings_log, needstype: nil) }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when needstype == 2" do
let(:log) { create(:lettings_log, needstype: 2) }
it "returns true" do
expect(page.routed_to?(log)).to eq(false)
end
end
end
end

10
spec/models/form/lettings/pages/uprn_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Form::Lettings::Pages::Uprn, type: :model do
end end
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[uprn]) expect(page.questions.map(&:id)).to eq(%w[uprn_known uprn])
end end
it "has the correct id" do it "has the correct id" do
@ -36,14 +36,6 @@ RSpec.describe Form::Lettings::Pages::Uprn, type: :model do
end end
describe "has correct routed_to?" do describe "has correct routed_to?" do
context "when uprn_known != 1" do
let(:log) { create(:lettings_log, uprn_known: 0) }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
context "when uprn_known == 1" do context "when uprn_known == 1" do
let(:log) { create(:lettings_log, uprn_known: 1) } let(:log) { create(:lettings_log, uprn_known: 1) }

4
spec/models/form/lettings/questions/uprn_known_spec.rb

@ -39,7 +39,7 @@ RSpec.describe Form::Lettings::Questions::UprnKnown, type: :model do
end end
it "has correct conditional for" do it "has correct conditional for" do
expect(question.conditional_for).to be_nil expect(question.conditional_for).to eq({ "uprn" => [1] })
end end
it "has the correct unanswered_error_message" do it "has the correct unanswered_error_message" do
@ -54,6 +54,6 @@ RSpec.describe Form::Lettings::Questions::UprnKnown, type: :model do
end end
it "has the correct hidden_in_check_answers" do it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to be_nil expect(question.hidden_in_check_answers).to eq(true)
end end
end end

46
spec/models/form/lettings/questions/uprn_spec.rb

@ -36,7 +36,7 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
end end
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to eq("The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.") expect(question.hint_text).to be_nil
end end
it "has the correct unanswered_error_message" do it "has the correct unanswered_error_message" do
@ -61,32 +61,44 @@ RSpec.describe Form::Lettings::Questions::Uprn, type: :model do
county: "Test County", county: "Test County",
postcode_full: "AA1 1AA", postcode_full: "AA1 1AA",
la: "E09000003", la: "E09000003",
uprn_known:,
) )
end end
it "returns formatted value" do context "when uprn known nil" do
expect(question.get_extra_check_answer_value(log)).to eq( let(:uprn_known) { nil }
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster",
) it "returns formatted value" do
expect(question.get_extra_check_answer_value(log)).to be_nil
end
end end
end
end
describe "has the correct hidden_in_check_answers" do context "when uprn known" do
context "when uprn_known == 1" do let(:uprn_known) { 1 }
let(:log) { create(:lettings_log, uprn_known: 1) }
it "returns false" do it "returns formatted value" do
expect(question.hidden_in_check_answers?(log)).to eq(false) expect(question.get_extra_check_answer_value(log)).to eq(
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster",
)
end
end end
end
context "when uprn_known != 1" do context "when uprn not known" do
let(:log) { create(:lettings_log, uprn_known: 0) } let(:uprn_known) { 0 }
it "returns false" do it "returns formatted value" do
expect(question.hidden_in_check_answers?(log)).to eq(true) expect(question.get_extra_check_answer_value(log)).to be_nil
end
end end
end end
end end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => {
"uprn_known" => 0,
},
"value" => "Not known",
}])
end
end end

1
spec/models/form/lettings/subsections/property_information_spec.rb

@ -45,7 +45,6 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do
it "has correct pages" do it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq( expect(property_information.pages.map(&:id)).to eq(
%w[ %w[
uprn_known
uprn uprn
uprn_confirmation uprn_confirmation
address address

33
spec/models/form/sales/pages/uprn_known_spec.rb

@ -1,33 +0,0 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::UprnKnown, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[uprn_known])
end
it "has the correct id" do
expect(page.id).to eq("uprn_known")
end
it "has the correct header" do
expect(page.header).to be_nil
end
it "has the correct description" do
expect(page.description).to be_nil
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

2
spec/models/form/sales/pages/uprn_spec.rb

@ -12,7 +12,7 @@ RSpec.describe Form::Sales::Pages::Uprn, type: :model do
end end
it "has correct questions" do it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[uprn]) expect(page.questions.map(&:id)).to eq(%w[uprn_known uprn])
end end
it "has the correct id" do it "has the correct id" do

4
spec/models/form/sales/questions/uprn_known_spec.rb

@ -39,7 +39,7 @@ RSpec.describe Form::Sales::Questions::UprnKnown, type: :model do
end end
it "has correct conditional for" do it "has correct conditional for" do
expect(question.conditional_for).to be_nil expect(question.conditional_for).to eq({ "uprn" => [1] })
end end
it "has the correct unanswered_error_message" do it "has the correct unanswered_error_message" do
@ -54,6 +54,6 @@ RSpec.describe Form::Sales::Questions::UprnKnown, type: :model do
end end
it "has the correct hidden_in_check_answers" do it "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to be_nil expect(question.hidden_in_check_answers).to eq(true)
end end
end end

47
spec/models/form/sales/questions/uprn_spec.rb

@ -36,7 +36,7 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
end end
it "has the correct hint" do it "has the correct hint" do
expect(question.hint_text).to eq("The Unique Property Reference Number (UPRN) is a unique number system created by Ordnance Survey and used by housing providers and sectors UK-wide. For example 10010457355.") expect(question.hint_text).to be_nil
end end
it "has the correct unanswered_error_message" do it "has the correct unanswered_error_message" do
@ -61,33 +61,44 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
county: "Test County", county: "Test County",
postcode_full: "AA1 1AA", postcode_full: "AA1 1AA",
la: "E09000003", la: "E09000003",
uprn_known:,
) )
end end
it "returns formatted value" do context "when uprn known nil" do
expect(question.get_extra_check_answer_value(log)).to eq( let(:uprn_known) { nil }
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster",
) it "returns formatted value" do
expect(question.get_extra_check_answer_value(log)).to be_nil
end
end end
end
end
describe "has the correct hidden_in_check_answers" do context "when uprn known" do
context "when uprn_known == 1" do let(:uprn_known) { 1 }
let(:log) { create(:sales_log) }
it "returns false" do it "returns formatted value" do
log.uprn_known = 1 expect(question.get_extra_check_answer_value(log)).to eq(
expect(question.hidden_in_check_answers?(log)).to eq(false) "\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster",
)
end
end end
end
context "when uprn_known != 1" do context "when uprn not known" do
let(:log) { create(:sales_log, uprn_known: 0) } let(:uprn_known) { 0 }
it "returns false" do it "returns formatted value" do
expect(question.hidden_in_check_answers?(log)).to eq(true) expect(question.get_extra_check_answer_value(log)).to be_nil
end
end end
end end
end end
it "has the correct inferred_check_answers_value" do
expect(question.inferred_check_answers_value).to eq([{
"condition" => {
"uprn_known" => 0,
},
"value" => "Not known",
}])
end
end end

1
spec/models/form/sales/subsections/property_information_spec.rb

@ -41,7 +41,6 @@ RSpec.describe Form::Sales::Subsections::PropertyInformation, type: :model do
it "has correct pages" do it "has correct pages" do
expect(property_information.pages.map(&:id)).to eq( expect(property_information.pages.map(&:id)).to eq(
%w[ %w[
uprn_known
uprn uprn
uprn_confirmation uprn_confirmation
address address

1
spec/models/lettings_log_spec.rb

@ -3140,6 +3140,7 @@ RSpec.describe LettingsLog do
.and change(lettings_log, :postcode_full).from(nil).to("POSTCODE") .and change(lettings_log, :postcode_full).from(nil).to("POSTCODE")
.and change(lettings_log, :uprn_confirmed).from(1).to(nil) .and change(lettings_log, :uprn_confirmed).from(1).to(nil)
.and change(lettings_log, :county).from("county").to(nil) .and change(lettings_log, :county).from("county").to(nil)
.and change(lettings_log, :uprn_known).from(nil).to(1)
end end
end end

1
spec/models/sales_log_spec.rb

@ -559,6 +559,7 @@ RSpec.describe SalesLog, type: :model do
.and change(sales_log, :postcode_full).from(nil).to("POSTCODE") .and change(sales_log, :postcode_full).from(nil).to("POSTCODE")
.and change(sales_log, :uprn_confirmed).from(1).to(nil) .and change(sales_log, :uprn_confirmed).from(1).to(nil)
.and change(sales_log, :county).from("county").to(nil) .and change(sales_log, :county).from("county").to(nil)
.and change(sales_log, :uprn_known).from(nil).to(1)
end end
end end

Loading…
Cancel
Save