|
|
|
|
@ -106,5 +106,67 @@ RSpec.shared_examples "shared log examples" do |log_type|
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe "#process_address_change!" do |
|
|
|
|
context "when address_line1_input and postcode_full_input set to a value" do |
|
|
|
|
let(:log) do |
|
|
|
|
log = build( |
|
|
|
|
log_type, |
|
|
|
|
address_selection: 0, |
|
|
|
|
address_line1: "Address line 1", |
|
|
|
|
postcode_full: "AA1 1AA", |
|
|
|
|
county: "county", |
|
|
|
|
) |
|
|
|
|
log.save!(validate: false) |
|
|
|
|
log |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "updates log fields" do |
|
|
|
|
log.address_line1_input = "New address line 1" |
|
|
|
|
log.postcode_full_input = "BB2 2BB" |
|
|
|
|
|
|
|
|
|
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", |
|
|
|
|
}]) |
|
|
|
|
|
|
|
|
|
expect { log.process_address_change! }.to change(log, :address_line1).from("Address line 1").to("0, Building Name, Thoroughfare") |
|
|
|
|
.and change(log, :town_or_city).from(nil).to("Posttown") |
|
|
|
|
.and change(log, :postcode_full).from("AA1 1AA").to("POSTCODE") |
|
|
|
|
.and change(log, :uprn_confirmed).from(nil).to(1) |
|
|
|
|
.and change(log, :uprn).from(nil).to("UPRN") |
|
|
|
|
.and change(log, :uprn_known).from(nil).to(1) |
|
|
|
|
.and change(log, :address_selection).from(0).to(nil) |
|
|
|
|
.and change(log, :county).from("county").to(nil) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when address inputs are nil" do |
|
|
|
|
let(:log) { create(log_type, address_selection: nil, address_line1_input: nil, postcode_full_input: nil) } |
|
|
|
|
|
|
|
|
|
it "does not update log" do |
|
|
|
|
expect { log.process_address_change! }.not_to change(log, :attributes) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when service errors" do |
|
|
|
|
let(:log) { build(log_type, :in_progress, address_selection: 0, address_line1_input: "123", postcode_full_input: "AA1 1AA") } |
|
|
|
|
let(:error_message) { "error" } |
|
|
|
|
|
|
|
|
|
it "adds error to log" do |
|
|
|
|
allow_any_instance_of(AddressClient).to receive(:call) |
|
|
|
|
allow_any_instance_of(AddressClient).to receive(:error).and_return(error_message) |
|
|
|
|
|
|
|
|
|
expect { log.process_address_change! }.to change { log.errors[:address_selection] }.from([]).to([error_message]) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
# rubocop:enable RSpec/AnyInstance |
|
|
|
|
|