Browse Source

Address PO review comments and add missing specs

CLDC-2068-request-and-validate-UPRN
Jack S 2 years ago
parent
commit
90d00f5c9d
  1. 2
      app/models/form/sales/pages/address.rb
  2. 14
      app/models/form/sales/pages/property_local_authority.rb
  3. 2
      app/models/form/sales/pages/uprn.rb
  4. 2
      app/models/form/sales/pages/uprn_confirmation.rb
  5. 4
      app/models/form/sales/questions/property_local_authority.rb
  6. 2
      app/models/form/sales/questions/uprn.rb
  7. 2
      app/models/form/sales/questions/uprn_known.rb
  8. 5
      spec/helpers/question_view_helper_spec.rb
  9. 40
      spec/models/form/sales/pages/address_spec.rb
  10. 60
      spec/models/form/sales/pages/property_local_authority_spec.rb
  11. 26
      spec/models/form/sales/pages/uprn_confirmation_spec.rb
  12. 36
      spec/models/form/sales/pages/uprn_spec.rb
  13. 18
      spec/models/form/sales/questions/property_local_authority_spec.rb
  14. 26
      spec/models/form/sales/questions/uprn_confirmation_spec.rb
  15. 2
      spec/models/form/sales/questions/uprn_known_spec.rb
  16. 37
      spec/models/form/sales/questions/uprn_spec.rb

2
app/models/form/sales/pages/address.rb

@ -15,7 +15,7 @@ class Form::Sales::Pages::Address < ::Form::Page
]
end
def routed_to?(log, _current_user)
def routed_to?(log, _current_user = nil)
return false if log.uprn_known.nil?
log.uprn_confirmed != 1 || log.uprn_known.zero?

14
app/models/form/sales/pages/property_local_authority.rb

@ -9,14 +9,20 @@ class Form::Sales::Pages::PropertyLocalAuthority < ::Form::Page
def questions
@questions ||= [
Form::Sales::Questions::PropertyLocalAuthorityKnown.new(nil, nil, self),
la_known_question,
Form::Sales::Questions::PropertyLocalAuthority.new(nil, nil, self),
]
].compact
end
def routed_to?(log, _current_user)
def routed_to?(log, _current_user = nil)
return false if log.uprn_known.nil? && form.start_date.year >= 2023
super
true
end
def la_known_question
if form.start_date.year < 2023
Form::Sales::Questions::PropertyLocalAuthorityKnown.new(nil, nil, self)
end
end
end

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

@ -10,7 +10,7 @@ class Form::Sales::Pages::Uprn < ::Form::Page
]
end
def routed_to?(log, _current_user)
def routed_to?(log, _current_user = nil)
log.uprn_known == 1
end

2
app/models/form/sales/pages/uprn_confirmation.rb

@ -11,7 +11,7 @@ class Form::Sales::Pages::UprnConfirmation < ::Form::Page
]
end
def routed_to?(log, _current_user)
def routed_to?(log, _current_user = nil)
log.uprn.present? && log.uprn_known == 1
end
end

4
app/models/form/sales/questions/property_local_authority.rb

@ -11,4 +11,8 @@ class Form::Sales::Questions::PropertyLocalAuthority < ::Form::Question
def answer_options
{ "" => "Select an option" }.merge(LocalAuthority.active(form.start_date).england.map { |la| [la.code, la.name] }.to_h)
end
def hidden_in_check_answers?(log, _current_user = nil)
log.saledate && log.saledate.year >= 2023
end
end

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

@ -20,7 +20,7 @@ class Form::Sales::Questions::Uprn < ::Form::Question
log.town_or_city,
log.county,
log.postcode_full,
(LocalAuthority.find_by(code: log.uprn)&.name if log.uprn.present?),
(LocalAuthority.find_by(code: log.la)&.name if log.la.present?),
].select(&:present?)
return unless value.any?

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

@ -3,7 +3,7 @@ class Form::Sales::Questions::UprnKnown < ::Form::Question
super
@id = "uprn_known"
@check_answer_label = "UPRN known?"
@header = "Do you know the sale UPRN?"
@header = "Do you know the property UPRN?"
@type = "radio"
@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>

5
spec/helpers/question_view_helper_spec.rb

@ -83,7 +83,10 @@ RSpec.describe QuestionViewHelper do
end
context "when viewing a question with a plain label" do
xit "returns an options hash with nil size" do
let(:question) { OpenStruct.new(header: "Some question header", plain_label: true) }
it "returns an options hash with nil size" do
expect(question_view_helper).to eq({ size: nil, tag: "div", text: "Some question header" })
end
end
end

40
spec/models/form/sales/pages/address_spec.rb

@ -31,7 +31,43 @@ RSpec.describe Form::Sales::Pages::Address, type: :model do
expect(page.depends_on).to be_nil
end
xit "has correct routed_to" do
expect(page.routed_to?).to be_nil
describe "has correct routed_to?" do
context "when uprn_known == nil" do
let(:log) { create(:sales_log, uprn_known: nil) }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
context "when uprn_confirmed != 1" do
let(:log) do
create(:sales_log, uprn_known: 1, uprn_confirmed: 0)
end
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_known == 0" do
let(:log) do
create(:sales_log, uprn_known: 0, uprn_confirmed: 0)
end
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn_confirmed == 1 && uprn_known != 0" do
let(:log) do
create(:sales_log, uprn_known: 1, uprn_confirmed: 1)
end
it "returns true" do
expect(page.routed_to?(log)).to eq(false)
end
end
end
end

60
spec/models/form/sales/pages/property_local_authority_spec.rb

@ -12,13 +12,31 @@ RSpec.describe Form::Sales::Pages::PropertyLocalAuthority, type: :model do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(
%w[
la_known
la
],
)
describe "has correct questions" do
context "when 2022" do
let(:start_date) { Time.utc(2022, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(
%w[
la_known
la
],
)
end
end
context "when 2023" do
let(:start_date) { Time.utc(2023, 2, 8) }
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(
%w[
la
],
)
end
end
end
it "has the correct id" do
@ -39,6 +57,32 @@ RSpec.describe Form::Sales::Pages::PropertyLocalAuthority, type: :model do
}])
end
xit "it has the correct routed_to?" do
describe "has correct routed_to?" do
context "when start_date < 2023" do
let(:log) { create(:sales_log, uprn_known: 1) }
let(:start_date) { Time.utc(2022, 2, 8) }
it "returns false" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when start_date >= 2023" do
let(:log) { create(:sales_log, uprn_known: 1) }
let(:start_date) { Time.utc(2023, 2, 8) }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when start_date < 2023 and uprn_known: nil" do
let(:log) { create(:sales_log, uprn_known: nil) }
let(:start_date) { Time.utc(2023, 2, 8) }
it "returns true" do
expect(page.routed_to?(log)).to eq(false)
end
end
end
end

26
spec/models/form/sales/pages/uprn_confirmation_spec.rb

@ -31,7 +31,29 @@ RSpec.describe Form::Sales::Pages::UprnConfirmation, type: :model do
expect(page.depends_on).to be_nil
end
xit "has correct routed_to" do
expect(page.routed_to?).to be_nil
describe "has correct routed_to?" do
context "when uprn present && uprn_known == 1 " do
let(:log) { create(:sales_log, uprn_known: 1, uprn: "123456789") }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
context "when uprn = nil" do
let(:log) { create(:sales_log, uprn_known: 1, uprn: nil) }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
context "when uprn_known == 0" do
let(:log) { create(:sales_log, uprn_known: 0, uprn: "123456789") }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
end
end

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

@ -35,11 +35,39 @@ RSpec.describe Form::Sales::Pages::Uprn, type: :model do
expect(page.skip_text).to eq("Enter address instead")
end
xit "has correct routed_to?" do
expect(page.routed_to?).to be_nil
describe "has correct routed_to?" do
context "when uprn_known != 1" do
let(:log) { create(:sales_log, uprn_known: 0) }
it "returns false" do
expect(page.routed_to?(log)).to eq(false)
end
end
context "when uprn_known == 1" do
let(:log) { create(:sales_log, uprn_known: 1) }
it "returns true" do
expect(page.routed_to?(log)).to eq(true)
end
end
end
xit "has correct skip_href" do
expect(page.skip_href).to be_nil
describe "has correct skip_href" do
context "when log is nil" do
it "is nil" do
expect(page.skip_href).to be_nil
end
end
context "when log is present" do
let(:log) { create(:sales_log) }
it "points to address page" do
expect(page.skip_href(log)).to eq(
"/sales-logs/#{log.id}/address",
)
end
end
end
end

18
spec/models/form/sales/questions/property_local_authority_spec.rb

@ -667,4 +667,22 @@ RSpec.describe Form::Sales::Questions::PropertyLocalAuthority, type: :model do
})
end
end
describe "has the correct hidden_in_check_answers" do
context "when saledate.year before 2023" do
let(:log) { build(:sales_log, saledate: Time.zone.parse("2022-07-01")) }
it "returns false" do
expect(question.hidden_in_check_answers?(log)).to eq(false)
end
end
context "when saledate.year >= 2023" do
let(:log) { build(:sales_log, saledate: Time.zone.parse("2023-07-01")) }
it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end
end
end
end

26
spec/models/form/sales/questions/uprn_confirmation_spec.rb

@ -62,7 +62,29 @@ RSpec.describe Form::Sales::Questions::UprnConfirmation, type: :model do
end
end
xit "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq("UPRN must be 12 digits or less")
describe "has the correct hidden_in_check_answers" do
context "when uprn_known != 1 && uprn_confirmed == nil" do
let(:log) { create(:sales_log, uprn_known: 0, uprn_confirmed: nil) }
it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end
end
context "when uprn_known == 1 && uprn_confirmed == nil" do
let(:log) { create(:sales_log, uprn_known: 1, uprn_confirmed: nil) }
it "returns false" do
expect(question.hidden_in_check_answers?(log)).to eq(false)
end
end
context "when uprn_known != 1 && uprn_confirmed == 1" do
let(:log) { create(:sales_log, uprn_known: 1, uprn_confirmed: 1) }
it "returns true" do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end
end
end
end

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

@ -16,7 +16,7 @@ RSpec.describe Form::Sales::Questions::UprnKnown, type: :model do
end
it "has the correct header" do
expect(question.header).to eq("Do you know the sale UPRN?")
expect(question.header).to eq("Do you know the property UPRN?")
end
it "has the correct check_answer_label" do

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

@ -41,25 +41,48 @@ RSpec.describe Form::Sales::Questions::Uprn, type: :model do
describe "get_extra_check_answer_value" do
context "when address is not present" do
it "returns nil" do
log = create(:sales_log)
let(:log) { create(:sales_log) }
it "returns nil" do
expect(question.get_extra_check_answer_value(log)).to be_nil
end
end
context "when address is present" do
it "returns formatted value" do
log = create(:sales_log, address_line1: "1, Test Street", town_or_city: "Test Town", county: "Test County", postcode_full: "AA1 1AA")
let(:log) do
create(
:sales_log,
address_line1: "1, Test Street",
town_or_city: "Test Town",
county: "Test County",
postcode_full: "AA1 1AA",
la: "E09000003",
)
end
it "returns formatted value" do
expect(question.get_extra_check_answer_value(log)).to eq(
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA",
"\n\n1, Test Street\nTest Town\nTest County\nAA1 1AA\nWestminster",
)
end
end
end
xit "has the correct hidden_in_check_answers" do
expect(question.hidden_in_check_answers).to eq("UPRN must be 12 digits or less")
describe "has the correct hidden_in_check_answers" do
context "when uprn_known == 1" do
let(:log) { create(:sales_log, uprn_known: 1) }
it "returns false" do
expect(question.hidden_in_check_answers?(log)).to eq(false)
end
end
context "when uprn_known != 1" do
let(:log) { create(:sales_log, uprn_known: 0) }
it "returns false" do
expect(question.hidden_in_check_answers?(log)).to eq(true)
end
end
end
end

Loading…
Cancel
Save