19 changed files with 588 additions and 31 deletions
|
|
|
|
@ -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::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,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, "address_selection" => 100 }, |
||||
{ "uprn_known" => 0, "address_selection" => 100 }, |
||||
{ "uprn_confirmed" => 0, "address_selection" => 100 }, |
||||
{ "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,44 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Pages::AddressSelection, 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_selection]) |
||||
end |
||||
|
||||
it "has the correct id" do |
||||
expect(page.id).to eq("address_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,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,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,102 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Sales::Questions::AddressSelection, 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("address_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({ "100" => { "value" => "The address is not listed, I want to enter the address manually" }, "0" => { "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({ "100" => { "value" => "The address is not listed, I want to enter the address manually" }, "0" => { "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,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 |
||||
Loading…
Reference in new issue