5 changed files with 225 additions and 13 deletions
@ -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,100 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Form::Lettings::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(:lettings_log, :in_progress, address_line1_input: "Address line 1", postcode_full_input: "AA1 1AA") } |
||||
|
||||
before do |
||||
allow_any_instance_of(AddressClient).to receive(:call) |
||||
allow_any_instance_of(AddressClient).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({ "-1" => { "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({ "-1" => { "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_any_instance_of(AddressClient).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,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("Postcode") |
||||
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