Browse Source
* feat: mvp commit with address selector from address line 1 and postcode using OS places find endpoint * feat: build out alternative routes through the address lookup flow * refactor: lint * refactor: remove commented lines * feat: make nil safe * feat: test address client * feat: store address input separately * feat: add migration * feat: display inputs in answer label * feat: update data presenter and test * feat: revert precicions schema update * feat: revert precision schema update * feat: migrate new fields to sales logs * feat: update shared log examples tests * feat: use -1 for not listed address for extensibility * feat: add service error to address_selection * feat: handle case when no addresses are found * feat: allow re-entering different uprns * feat: improve error handling and don't accept "no match" precisions * feat: add page tests * feat: confirm uprn on address update * feat: add question tests * feat: don't set minimum match for initial search * feat: mvp commit with address selector from address line 1 and postcode using OS places find endpoint * feat: build out alternative routes through the address lookup flow * refactor: lint * refactor: remove commented lines * feat: make nil safe * feat: test address client * feat: store address input separately * feat: add migration * feat: display inputs in answer label * feat: update data presenter and test * feat: revert precision schema update * feat: migrate new fields to sales logs * feat: update shared log examples tests * feat: use -1 for not listed address for extensibility * feat: add service error to address_selection * feat: handle case when no addresses are found * feat: allow re-entering different uprns * feat: improve error handling and don't accept "no match" precisions * feat: add page tests * feat: confirm uprn on address update * feat: add question tests * feat: don't set minimum match for initial search * feat: add no address found page * feat: allow uprn known to be skipped, and set 0.4 min precision * feat: accept best "good" match in bulk upload * feat: update validations and test * refactor: avoid stubbing using any_instance_of * refactor: use change_table in migrations * feat: add lettings behaviour to sales logs * feat: update sales tests * feat: xit test that is xited in lettings * feat: stub os api in sales row parser * feat: stub os api in sales row parser * feat: add address line 1 to required attributes * feat: update matching details and fix row parser validation * refactor: improve readability * feat: set uprns as option IDs to avoid multiple lookups * feat: add sales uprn_selection * feat: update schema * feat: update tests * feat: remove redundant methods * feat: update error message and fix tests * feat: update tests * feat: update tests and error behaviour * feat: update testspull/2314/head
natdeanlewissoftwire
10 months ago
committed by
GitHub
71 changed files with 1876 additions and 75 deletions
@ -0,0 +1,25 @@
|
||||
class Form::Lettings::Pages::AddressFallback < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address" |
||||
@header = "Q12 - What is the property's address?" |
||||
@depends_on = [ |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil, "address_options_present?" => false }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0, "address_options_present?" => false }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0, "address_options_present?" => false }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::AddressLine1.new(nil, nil, self), |
||||
Form::Lettings::Questions::AddressLine2.new(nil, nil, self), |
||||
Form::Lettings::Questions::TownOrCity.new(nil, nil, self), |
||||
Form::Lettings::Questions::County.new(nil, nil, self), |
||||
Form::Lettings::Questions::PostcodeForFullAddress.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
class Form::Lettings::Pages::AddressMatcher < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address_matcher" |
||||
@header = "Find an address" |
||||
@depends_on = [ |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0 }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0 }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::AddressLine1ForAddressMatcher.new(nil, nil, self), |
||||
Form::Lettings::Questions::PostcodeForAddressMatcher.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,26 @@
|
||||
class Form::Lettings::Pages::NoAddressFound < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "no_address_found" |
||||
@type = "interruption_screen" |
||||
@title_text = { |
||||
"translation" => "soft_validations.no_address_found.title_text", |
||||
"arguments" => [], |
||||
} |
||||
@informative_text = { |
||||
"translation" => "soft_validations.no_address_found.informative_text", |
||||
"arguments" => [], |
||||
} |
||||
@depends_on = [{ "address_options_present?" => false }] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::NoAddressFound.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[address_line1_input] |
||||
end |
||||
end |
@ -0,0 +1,28 @@
|
||||
class Form::Lettings::Pages::UprnSelection < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "uprn_selection" |
||||
@header = "We found some addresses that might be this property" |
||||
@depends_on = [{ "address_options_present?" => true }] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::UprnSelection.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(log, _current_user = nil) |
||||
(log.uprn_known.nil? || log.uprn_known.zero?) && log.address_line1_input.present? && log.postcode_full_input.present? && (1..10).cover?(log.address_options&.count) |
||||
end |
||||
|
||||
def skip_text |
||||
"Search for address again" |
||||
end |
||||
|
||||
def skip_href(log = nil) |
||||
return unless log |
||||
|
||||
"/#{log.model_name.param_key.dasherize}s/#{log.id}/address-matcher" |
||||
end |
||||
end |
@ -0,0 +1,20 @@
|
||||
class Form::Lettings::Questions::AddressLine1ForAddressMatcher < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_line1_input" |
||||
@header = "Address line 1" |
||||
@error_label = "Address line 1" |
||||
@type = "text" |
||||
@plain_label = true |
||||
@check_answer_label = "Find address" |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
@hide_question_number_on_page = true |
||||
end |
||||
|
||||
def answer_label(log, _current_user = nil) |
||||
[ |
||||
log.address_line1_input, |
||||
log.postcode_full_input, |
||||
].select(&:present?).join("\n") |
||||
end |
||||
end |
@ -0,0 +1,9 @@
|
||||
class Form::Lettings::Questions::NoAddressFound < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_search_value_check" |
||||
@header = "No address found" |
||||
@type = "interruption_screen" |
||||
@hidden_in_check_answers = true |
||||
end |
||||
end |
@ -0,0 +1,13 @@
|
||||
class Form::Lettings::Questions::PostcodeForAddressMatcher < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "postcode_full_input" |
||||
@header = "Postcode" |
||||
@type = "text" |
||||
@width = 5 |
||||
@plain_label = true |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
@hide_question_number_on_page = true |
||||
@hidden_in_check_answers = true |
||||
end |
||||
end |
@ -0,0 +1,34 @@
|
||||
class Form::Lettings::Questions::UprnSelection < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "uprn_selection" |
||||
@header = "Select the correct address" |
||||
@type = "radio" |
||||
@check_answer_label = "Select the correct address" |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
end |
||||
|
||||
def answer_options(log = nil, _user = nil) |
||||
answer_opts = { "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" } } |
||||
return answer_opts unless ActiveRecord::Base.connected? |
||||
return answer_opts unless log&.address_options |
||||
|
||||
answer_opts = {} |
||||
|
||||
(0...[log.address_options.count, 10].min).each do |i| |
||||
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] } |
||||
end |
||||
|
||||
answer_opts["divider"] = { "value" => true } |
||||
answer_opts["uprn_not_listed"] = { "value" => "The address is not listed, I want to enter the address manually" } |
||||
answer_opts |
||||
end |
||||
|
||||
def displayed_answer_options(log, user = nil) |
||||
answer_options(log, user) |
||||
end |
||||
|
||||
def hidden_in_check_answers?(log, _current_user = nil) |
||||
(log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options&.count) |
||||
end |
||||
end |
@ -0,0 +1,25 @@
|
||||
class Form::Sales::Pages::AddressFallback < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address" |
||||
@header = "Q12 - What is the property's address?" |
||||
@depends_on = [ |
||||
{ "uprn_known" => nil, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "uprn_known" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "uprn_confirmed" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "uprn_known" => nil, "address_options_present?" => false }, |
||||
{ "uprn_known" => 0, "address_options_present?" => false }, |
||||
{ "uprn_confirmed" => 0, "address_options_present?" => false }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::AddressLine1.new(nil, nil, self), |
||||
Form::Sales::Questions::AddressLine2.new(nil, nil, self), |
||||
Form::Sales::Questions::TownOrCity.new(nil, nil, self), |
||||
Form::Sales::Questions::County.new(nil, nil, self), |
||||
Form::Sales::Questions::PostcodeForFullAddress.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,19 @@
|
||||
class Form::Sales::Pages::AddressMatcher < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address_matcher" |
||||
@header = "Find an address" |
||||
@depends_on = [ |
||||
{ "uprn_known" => nil }, |
||||
{ "uprn_known" => 0 }, |
||||
{ "uprn_confirmed" => 0 }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::AddressLine1ForAddressMatcher.new(nil, nil, self), |
||||
Form::Sales::Questions::PostcodeForAddressMatcher.new(nil, nil, self), |
||||
] |
||||
end |
||||
end |
@ -0,0 +1,26 @@
|
||||
class Form::Sales::Pages::NoAddressFound < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "no_address_found" |
||||
@type = "interruption_screen" |
||||
@title_text = { |
||||
"translation" => "soft_validations.no_address_found.title_text", |
||||
"arguments" => [], |
||||
} |
||||
@informative_text = { |
||||
"translation" => "soft_validations.no_address_found.informative_text", |
||||
"arguments" => [], |
||||
} |
||||
@depends_on = [{ "address_options_present?" => false }] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::NoAddressFound.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def interruption_screen_question_ids |
||||
%w[address_line1_input] |
||||
end |
||||
end |
@ -0,0 +1,28 @@
|
||||
class Form::Sales::Pages::UprnSelection < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "uprn_selection" |
||||
@header = "We found some addresses that might be this property" |
||||
@depends_on = [{ "address_options_present?" => true }] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Sales::Questions::UprnSelection.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def routed_to?(log, _current_user = nil) |
||||
(log.uprn_known.nil? || log.uprn_known.zero?) && log.address_line1_input.present? && log.postcode_full_input.present? && (1..10).cover?(log.address_options&.count) |
||||
end |
||||
|
||||
def skip_text |
||||
"Search for address again" |
||||
end |
||||
|
||||
def skip_href(log = nil) |
||||
return unless log |
||||
|
||||
"/#{log.model_name.param_key.dasherize}s/#{log.id}/address-matcher" |
||||
end |
||||
end |
@ -0,0 +1,20 @@
|
||||
class Form::Sales::Questions::AddressLine1ForAddressMatcher < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_line1_input" |
||||
@header = "Address line 1" |
||||
@error_label = "Address line 1" |
||||
@type = "text" |
||||
@plain_label = true |
||||
@check_answer_label = "Find address" |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
@hide_question_number_on_page = true |
||||
end |
||||
|
||||
def answer_label(log, _current_user = nil) |
||||
[ |
||||
log.address_line1_input, |
||||
log.postcode_full_input, |
||||
].select(&:present?).join("\n") |
||||
end |
||||
end |
@ -0,0 +1,9 @@
|
||||
class Form::Sales::Questions::NoAddressFound < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_search_value_check" |
||||
@header = "No address found" |
||||
@type = "interruption_screen" |
||||
@hidden_in_check_answers = true |
||||
end |
||||
end |
@ -0,0 +1,13 @@
|
||||
class Form::Sales::Questions::PostcodeForAddressMatcher < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "postcode_full_input" |
||||
@header = "Postcode" |
||||
@type = "text" |
||||
@width = 5 |
||||
@plain_label = true |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
@hide_question_number_on_page = true |
||||
@hidden_in_check_answers = true |
||||
end |
||||
end |
@ -0,0 +1,34 @@
|
||||
class Form::Sales::Questions::UprnSelection < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "uprn_selection" |
||||
@header = "Select the correct address" |
||||
@type = "radio" |
||||
@check_answer_label = "Select the correct address" |
||||
@disable_clearing_if_not_routed_or_dynamic_answer_options = true |
||||
end |
||||
|
||||
def answer_options(log = nil, _user = nil) |
||||
answer_opts = { "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" } } |
||||
return answer_opts unless ActiveRecord::Base.connected? |
||||
return answer_opts unless log&.address_options |
||||
|
||||
answer_opts = {} |
||||
|
||||
(0...[log.address_options.count, 10].min).each do |i| |
||||
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] } |
||||
end |
||||
|
||||
answer_opts["divider"] = { "value" => true } |
||||
answer_opts["uprn_not_listed"] = { "value" => "The address is not listed, I want to enter the address manually" } |
||||
answer_opts |
||||
end |
||||
|
||||
def displayed_answer_options(log, user = nil) |
||||
answer_options(log, user) |
||||
end |
||||
|
||||
def hidden_in_check_answers?(log, _current_user = nil) |
||||
(log.uprn_known == 1 || log.uprn_confirmed == 1) || !(1..10).cover?(log.address_options&.count) |
||||
end |
||||
end |
@ -0,0 +1,52 @@
|
||||
require "net/http" |
||||
|
||||
class AddressClient |
||||
attr_reader :address |
||||
attr_accessor :error |
||||
|
||||
ADDRESS = "api.os.uk".freeze |
||||
PATH = "/search/places/v1/find".freeze |
||||
|
||||
def initialize(address) |
||||
@address = address |
||||
end |
||||
|
||||
def call |
||||
unless response.is_a?(Net::HTTPSuccess) && result.present? |
||||
@error = "Address is not recognised. Check the address, or enter the UPRN" |
||||
end |
||||
rescue JSON::ParserError |
||||
@error = "Address is not recognised. Check the address, or enter the UPRN" |
||||
end |
||||
|
||||
def result |
||||
@result ||= JSON.parse(response.body)["results"]&.map { |address| address["DPA"] } |
||||
end |
||||
|
||||
private |
||||
|
||||
def http_client |
||||
client = Net::HTTP.new(ADDRESS, 443) |
||||
client.use_ssl = true |
||||
client.verify_mode = OpenSSL::SSL::VERIFY_PEER |
||||
client.max_retries = 3 |
||||
client.read_timeout = 10 # seconds |
||||
client |
||||
end |
||||
|
||||
def endpoint_uri |
||||
uri = URI(PATH) |
||||
params = { |
||||
query: address, |
||||
key: ENV["OS_DATA_KEY"], |
||||
maxresults: 10, |
||||
minmatch: 0.4, |
||||
} |
||||
uri.query = URI.encode_www_form(params) |
||||
uri.to_s |
||||
end |
||||
|
||||
def response |
||||
@response ||= http_client.request_get(endpoint_uri) |
||||
end |
||||
end |
@ -0,0 +1,21 @@
|
||||
require "net/http" |
||||
|
||||
class AddressDataPresenter |
||||
attr_reader :data |
||||
|
||||
def initialize(data) |
||||
@data = data |
||||
end |
||||
|
||||
def uprn |
||||
data["UPRN"] |
||||
end |
||||
|
||||
def address |
||||
data["ADDRESS"] |
||||
end |
||||
|
||||
def match |
||||
data["MATCH"] |
||||
end |
||||
end |
@ -0,0 +1,8 @@
|
||||
class AddAddressInputFieldsToLettingsLog < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :lettings_logs, bulk: true do |t| |
||||
t.string :address_line1_input |
||||
t.string :postcode_full_input |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,8 @@
|
||||
class AddAddressLookupFieldsToSalesLogs < ActiveRecord::Migration[7.0] |
||||
def change |
||||
change_table :sales_logs, bulk: true do |t| |
||||
t.string :address_line1_input |
||||
t.string :postcode_full_input |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddNoAddressFoundCheckToLettingsLogs < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :lettings_logs, :address_search_value_check, :integer |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddAddressSearchValueCheckToSalesLogs < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :sales_logs, :address_search_value_check, :integer |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddUprnSelectionToLettingsLog < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :lettings_logs, :uprn_selection, :string |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class AddUprnSelectionToSalesLog < ActiveRecord::Migration[7.0] |
||||
def change |
||||
add_column :sales_logs, :uprn_selection, :string |
||||
end |
||||
end |
|
|
|
|
|
|
|
|
@ -0,0 +1,40 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::AddressFallback, 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, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1))) } |
||||
|
||||
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[address_line1 address_line2 town_or_city county postcode_full]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("address") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("Q12 - What is the property's address?") |
||||
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 eq([ |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => nil, "address_options_present?" => false }, |
||||
{ "is_supported_housing?" => false, "uprn_known" => 0, "address_options_present?" => false }, |
||||
{ "is_supported_housing?" => false, "uprn_confirmed" => 0, "address_options_present?" => false }, |
||||
]) |
||||
end |
||||
end |
@ -0,0 +1,33 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::AddressMatcher, 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[address_line1_input postcode_full_input]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("address_matcher") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("Find an address") |
||||
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 eq([{ "is_supported_housing?" => false, "uprn_known" => nil }, { "is_supported_housing?" => false, "uprn_known" => 0 }, { "is_supported_housing?" => false, "uprn_confirmed" => 0 }]) |
||||
end |
||||
end |
@ -0,0 +1,46 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::NoAddressFound, 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) } |
||||
let(:log) { create(:lettings_log) } |
||||
|
||||
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[address_search_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("no_address_found") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "address_options_present?" => false }]) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to eq(true) |
||||
end |
||||
|
||||
it "has the correct title_text" do |
||||
expect(page.title_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.title_text" }) |
||||
end |
||||
|
||||
it "has the correct informative_text" do |
||||
expect(page.informative_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.informative_text" }) |
||||
end |
||||
|
||||
it "has the correct interruption_screen_question_ids" do |
||||
expect(page.interruption_screen_question_ids).to eq(%w[address_line1_input]) |
||||
end |
||||
end |
@ -0,0 +1,44 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Pages::UprnSelection, 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) } |
||||
let(:log) { create(:lettings_log) } |
||||
|
||||
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_selection]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("uprn_selection") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("We found some addresses that might be this property") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be_nil |
||||
end |
||||
|
||||
it "has the correct skip text" do |
||||
"Search for address again" |
||||
end |
||||
|
||||
it "has the correct skip_href" do |
||||
expect(page.skip_href(log)).to eq( |
||||
"/lettings-logs/#{log.id}/address-matcher", |
||||
) |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "address_options_present?" => true }]) |
||||
end |
||||
end |
@ -0,0 +1,62 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::AddressLine1ForAddressMatcher, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("address_line1_input") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Address line 1") |
||||
end |
||||
|
||||
it "has the correct error label" do |
||||
expect(question.error_label).to eq("Address line 1") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Find address") |
||||
end |
||||
|
||||
it "has the correct question_number" do |
||||
expect(question.question_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer label" do |
||||
expect(question.answer_label(log)).to eq("Address line 1\nAA1 1AA") |
||||
end |
||||
|
||||
it "has the correct inferred check answers value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to be_nil |
||||
end |
||||
|
||||
it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do |
||||
expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,44 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::NoAddressFound, type: :model do |
||||
subject(:question) { described_class.new(nil, question_definition, page) } |
||||
|
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("address_search_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("No address found") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to be_nil |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("interruption_screen") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to be_nil |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,62 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::PostcodeForAddressMatcher, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("postcode_full_input") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Postcode") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct question_number" do |
||||
expect(question.question_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer label" do |
||||
expect(question.answer_label(log)).to eq("AA1 1AA") |
||||
end |
||||
|
||||
it "has the correct inferred check answers value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
it "has the correct inferred_answers value" do |
||||
expect(question.inferred_answers).to be_nil |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to be_nil |
||||
end |
||||
|
||||
it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do |
||||
expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,102 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::Questions::UprnSelection, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:log) { create(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
let(:address_client_instance) { AddressClient.new(log.address_string) } |
||||
|
||||
before do |
||||
allow(AddressClient).to receive(:new).and_return(address_client_instance) |
||||
allow(address_client_instance).to receive(:call) |
||||
allow(address_client_instance).to receive(:result).and_return([{ |
||||
"UPRN" => "UPRN", |
||||
"UDPRN" => "UDPRN", |
||||
"ADDRESS" => "full address", |
||||
"SUB_BUILDING_NAME" => "0", |
||||
"BUILDING_NAME" => "building name", |
||||
"THOROUGHFARE_NAME" => "thoroughfare", |
||||
"POST_TOWN" => "posttown", |
||||
"POSTCODE" => "postcode", |
||||
}]) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("uprn_selection") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Select the correct address") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Select the correct address") |
||||
end |
||||
|
||||
it "has the correct question_number" do |
||||
expect(question.question_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("radio") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer options" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: "", headers: {}) |
||||
|
||||
expect(question.answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) |
||||
end |
||||
|
||||
it "has the correct displayed answer options" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: "", headers: {}) |
||||
|
||||
expect(question.displayed_answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) |
||||
end |
||||
|
||||
it "has the correct inferred check answers value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to be_nil |
||||
end |
||||
|
||||
context "when the log has address options" do |
||||
it "has the correct hidden_in_check_answers?" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: '{"results": {"0": "address_0", "1": "address_1", "2": "address_2"}}', headers: {}) |
||||
|
||||
expect(question.hidden_in_check_answers?(log)).to eq(false) |
||||
end |
||||
end |
||||
|
||||
context "when the log does not have address options" do |
||||
before do |
||||
allow(address_client_instance).to receive(:result).and_return(nil) |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers?" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: "", headers: {}) |
||||
|
||||
expect(question.hidden_in_check_answers?(log)).to eq(true) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,40 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::AddressFallback, 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, form: instance_double(Form, start_date: Time.zone.local(2024, 4, 1))) } |
||||
|
||||
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[address_line1 address_line2 town_or_city county postcode_full]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("address") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("Q12 - What is the property's address?") |
||||
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 eq([ |
||||
{ "uprn_known" => nil, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "uprn_known" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "uprn_confirmed" => 0, "uprn_selection" => "uprn_not_listed" }, |
||||
{ "uprn_known" => nil, "address_options_present?" => false }, |
||||
{ "uprn_known" => 0, "address_options_present?" => false }, |
||||
{ "uprn_confirmed" => 0, "address_options_present?" => false }, |
||||
]) |
||||
end |
||||
end |
@ -0,0 +1,33 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::AddressMatcher, 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[address_line1_input postcode_full_input]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("address_matcher") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("Find an address") |
||||
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 eq([{ "uprn_known" => nil }, { "uprn_known" => 0 }, { "uprn_confirmed" => 0 }]) |
||||
end |
||||
end |
@ -0,0 +1,46 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::NoAddressFound, 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) } |
||||
let(:log) { create(:sales_log) } |
||||
|
||||
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[address_search_value_check]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("no_address_found") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to be_nil |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "address_options_present?" => false }]) |
||||
end |
||||
|
||||
it "is interruption screen page" do |
||||
expect(page.interruption_screen?).to eq(true) |
||||
end |
||||
|
||||
it "has the correct title_text" do |
||||
expect(page.title_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.title_text" }) |
||||
end |
||||
|
||||
it "has the correct informative_text" do |
||||
expect(page.informative_text).to eq({ "arguments" => [], "translation" => "soft_validations.no_address_found.informative_text" }) |
||||
end |
||||
|
||||
it "has the correct interruption_screen_question_ids" do |
||||
expect(page.interruption_screen_question_ids).to eq(%w[address_line1_input]) |
||||
end |
||||
end |
@ -0,0 +1,44 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::UprnSelection, 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) } |
||||
let(:log) { create(:sales_log) } |
||||
|
||||
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_selection]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("uprn_selection") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(page.header).to eq("We found some addresses that might be this property") |
||||
end |
||||
|
||||
it "has the correct description" do |
||||
expect(page.description).to be_nil |
||||
end |
||||
|
||||
it "has the correct skip text" do |
||||
"Search for address again" |
||||
end |
||||
|
||||
it "has the correct skip_href" do |
||||
expect(page.skip_href(log)).to eq( |
||||
"/sales-logs/#{log.id}/address-matcher", |
||||
) |
||||
end |
||||
|
||||
it "has correct depends_on" do |
||||
expect(page.depends_on).to eq([{ "address_options_present?" => true }]) |
||||
end |
||||
end |
@ -0,0 +1,62 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::AddressLine1ForAddressMatcher, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("address_line1_input") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Address line 1") |
||||
end |
||||
|
||||
it "has the correct error label" do |
||||
expect(question.error_label).to eq("Address line 1") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Find address") |
||||
end |
||||
|
||||
it "has the correct question_number" do |
||||
expect(question.question_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer label" do |
||||
expect(question.answer_label(log)).to eq("Address line 1\nAA1 1AA") |
||||
end |
||||
|
||||
it "has the correct inferred check answers value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to be_nil |
||||
end |
||||
|
||||
it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do |
||||
expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,44 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::NoAddressFound, type: :model do |
||||
subject(:question) { described_class.new(nil, question_definition, page) } |
||||
|
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("address_search_value_check") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("No address found") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to be_nil |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("interruption_screen") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer_options" do |
||||
expect(question.answer_options).to be_nil |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers" do |
||||
expect(question.hidden_in_check_answers).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,62 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::PostcodeForAddressMatcher, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("postcode_full_input") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Postcode") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct question_number" do |
||||
expect(question.question_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("text") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer label" do |
||||
expect(question.answer_label(log)).to eq("AA1 1AA") |
||||
end |
||||
|
||||
it "has the correct inferred check answers value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
it "has the correct inferred_answers value" do |
||||
expect(question.inferred_answers).to be_nil |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to be_nil |
||||
end |
||||
|
||||
it "has the correct disable_clearing_if_not_routed_or_dynamic_answer_options value" do |
||||
expect(question.disable_clearing_if_not_routed_or_dynamic_answer_options).to eq(true) |
||||
end |
||||
end |
@ -0,0 +1,102 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do |
||||
subject(:question) { described_class.new(question_id, question_definition, page) } |
||||
|
||||
let(:question_id) { nil } |
||||
let(:question_definition) { nil } |
||||
let(:page) { instance_double(Form::Page) } |
||||
let(:log) { create(:sales_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
let(:address_client_instance) { AddressClient.new(log.address_string) } |
||||
|
||||
before do |
||||
allow(AddressClient).to receive(:new).and_return(address_client_instance) |
||||
allow(address_client_instance).to receive(:call) |
||||
allow(address_client_instance).to receive(:result).and_return([{ |
||||
"UPRN" => "UPRN", |
||||
"UDPRN" => "UDPRN", |
||||
"ADDRESS" => "full address", |
||||
"SUB_BUILDING_NAME" => "0", |
||||
"BUILDING_NAME" => "building name", |
||||
"THOROUGHFARE_NAME" => "thoroughfare", |
||||
"POST_TOWN" => "posttown", |
||||
"POSTCODE" => "postcode", |
||||
}]) |
||||
end |
||||
|
||||
it "has correct page" do |
||||
expect(question.page).to eq(page) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(question.id).to eq("uprn_selection") |
||||
end |
||||
|
||||
it "has the correct header" do |
||||
expect(question.header).to eq("Select the correct address") |
||||
end |
||||
|
||||
it "has the correct check_answer_label" do |
||||
expect(question.check_answer_label).to eq("Select the correct address") |
||||
end |
||||
|
||||
it "has the correct question_number" do |
||||
expect(question.question_number).to eq(nil) |
||||
end |
||||
|
||||
it "has the correct type" do |
||||
expect(question.type).to eq("radio") |
||||
end |
||||
|
||||
it "is not marked as derived" do |
||||
expect(question.derived?).to be false |
||||
end |
||||
|
||||
it "has the correct hint" do |
||||
expect(question.hint_text).to be_nil |
||||
end |
||||
|
||||
it "has the correct answer options" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: "", headers: {}) |
||||
|
||||
expect(question.answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) |
||||
end |
||||
|
||||
it "has the correct displayed answer options" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: "", headers: {}) |
||||
|
||||
expect(question.displayed_answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) |
||||
end |
||||
|
||||
it "has the correct inferred check answers value" do |
||||
expect(question.inferred_check_answers_value).to be_nil |
||||
end |
||||
|
||||
it "has the correct check_answers_card_number" do |
||||
expect(question.check_answers_card_number).to be_nil |
||||
end |
||||
|
||||
context "when the log has address options" do |
||||
it "has the correct hidden_in_check_answers?" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: '{"results": {"0": "address_0", "1": "address_1", "2": "address_2"}}', headers: {}) |
||||
|
||||
expect(question.hidden_in_check_answers?(log)).to eq(false) |
||||
end |
||||
end |
||||
|
||||
context "when the log does not have address options" do |
||||
before do |
||||
allow(address_client_instance).to receive(:result).and_return(nil) |
||||
end |
||||
|
||||
it "has the correct hidden_in_check_answers?" do |
||||
stub_request(:get, /api\.os\.uk/) |
||||
.to_return(status: 200, body: "", headers: {}) |
||||
|
||||
expect(question.hidden_in_check_answers?(log)).to eq(true) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,68 @@
|
||||
require "rails_helper" |
||||
|
||||
describe AddressClient do |
||||
let(:client) { described_class.new("123") } |
||||
|
||||
let(:valid_response) do |
||||
{ results: [{ DPA: { UPRN: "12345" } }] }.to_json |
||||
end |
||||
|
||||
def stub_api_request(body:, status: 200) |
||||
stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query=123") |
||||
.to_return(status:, body:, headers: {}) |
||||
end |
||||
|
||||
describe "call" do |
||||
context "when json parse error" do |
||||
before do |
||||
stub_api_request(body: "{", status: 200) |
||||
|
||||
client.call |
||||
end |
||||
|
||||
it "returns error" do |
||||
expect(client.error).to eq("Address is not recognised. Check the address, or enter the UPRN") |
||||
end |
||||
end |
||||
|
||||
context "when http error" do |
||||
before do |
||||
stub_api_request(body: valid_response, status: 500) |
||||
|
||||
client.call |
||||
end |
||||
|
||||
it "returns error" do |
||||
expect(client.error).to eq("Address is not recognised. Check the address, or enter the UPRN") |
||||
end |
||||
end |
||||
|
||||
context "when results empty" do |
||||
before do |
||||
stub_api_request(body: {}.to_json) |
||||
|
||||
client.call |
||||
end |
||||
|
||||
it "returns error" do |
||||
expect(client.error).to eq("Address is not recognised. Check the address, or enter the UPRN") |
||||
end |
||||
end |
||||
|
||||
context "with results" do |
||||
before do |
||||
stub_api_request(body: valid_response) |
||||
|
||||
client.call |
||||
end |
||||
|
||||
it "returns result" do |
||||
expect(client.result).to eq([{ "UPRN" => "12345" }]) |
||||
end |
||||
|
||||
it "returns no error" do |
||||
expect(client.error).to be_nil |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,51 @@
|
||||
require "rails_helper" |
||||
|
||||
describe AddressDataPresenter do |
||||
let(:data) do |
||||
JSON.parse( |
||||
'{ |
||||
"UPRN": "UPRN", |
||||
"UDPRN": "UDPRN", |
||||
"ADDRESS": "full address", |
||||
"SUB_BUILDING_NAME": "0", |
||||
"BUILDING_NAME": "building name", |
||||
"THOROUGHFARE_NAME": "thoroughfare", |
||||
"POST_TOWN": "posttown", |
||||
"POSTCODE": "postcode", |
||||
"STATUS": "APPROVED", |
||||
"DOUBLE_DEPENDENT_LOCALITY": "double dependent locality", |
||||
"DEPENDENT_LOCALITY": "dependent locality", |
||||
"CLASSIFICATION_CODE": "classification code", |
||||
"LOCAL_CUSTODIAN_CODE_DESCRIPTION": "LONDON BOROUGH OF HARINGEY", |
||||
"BLPU_STATE_CODE": "2", |
||||
"BLPU_STATE_CODE_DESCRIPTION": "In use", |
||||
"LAST_UPDATE_DATE": "31/07/2020", |
||||
"ENTRY_DATE": "30/01/2015", |
||||
"BLPU_STATE_DATE": "30/01/2015", |
||||
"LANGUAGE": "EN", |
||||
"MATCH_DESCRIPTION": "EXACT", |
||||
"MATCH": "1.0" |
||||
}', |
||||
) |
||||
end |
||||
|
||||
let(:presenter) { described_class.new(data) } |
||||
|
||||
describe "#uprn" do |
||||
it "returns uprn" do |
||||
expect(presenter.uprn).to eq("UPRN") |
||||
end |
||||
end |
||||
|
||||
describe "#match" do |
||||
it "returns match" do |
||||
expect(presenter.match).to eq("1.0") |
||||
end |
||||
end |
||||
|
||||
describe "#address" do |
||||
it "returns address" do |
||||
expect(presenter.address).to eq("full address") |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue