|
|
|
@ -729,5 +729,353 @@ RSpec.describe "Lettings Log Features" do
|
|
|
|
|
expect(duplicate_log.duplicate_set_id).to be_nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when filling out address fields" do |
|
|
|
|
let(:lettings_log) { create(:lettings_log, :setup_completed, assigned_to: user) } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
body = { |
|
|
|
|
results: [ |
|
|
|
|
{ |
|
|
|
|
DPA: { |
|
|
|
|
"POSTCODE": "AA1 1AA", |
|
|
|
|
"POST_TOWN": "Bristol", |
|
|
|
|
"ORGANISATION_NAME": "Some place", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}.to_json |
|
|
|
|
|
|
|
|
|
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=111") |
|
|
|
|
.to_return(status: 200, body:, headers: {}) |
|
|
|
|
|
|
|
|
|
body = { results: [{ DPA: { UPRN: "111" } }] }.to_json |
|
|
|
|
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?query=Address+line+1%2C+AA1+1AA&key=OS_DATA_KEY&maxresults=10&minmatch=0.4") |
|
|
|
|
.to_return(status: 200, body:, headers: {}) |
|
|
|
|
|
|
|
|
|
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA11AA") |
|
|
|
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 1AA\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) |
|
|
|
|
|
|
|
|
|
WebMock.stub_request(:get, "https://api.postcodes.io/postcodes/AA12AA") |
|
|
|
|
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"AA1 2AA\",\"admin_district\":\"Wigan\",\"codes\":{\"admin_district\":\"E08000010\"}}}", headers: {}) |
|
|
|
|
|
|
|
|
|
body = { results: [] }.to_json |
|
|
|
|
WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?query=Address+line+1%2C+AA1+1AB&key=OS_DATA_KEY&maxresults=10&minmatch=0.4") |
|
|
|
|
.to_return(status: 200, body:, headers: {}) |
|
|
|
|
|
|
|
|
|
visit("/lettings-logs/#{lettings_log.id}/uprn") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and uprn is known and answered" do |
|
|
|
|
before do |
|
|
|
|
choose "Yes" |
|
|
|
|
fill_in("lettings_log[uprn]", with: "111") |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and uprn is confirmed" do |
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(1) # yes |
|
|
|
|
expect(lettings_log.uprn).to eq("111") |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Some Place") |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq("Bristol") |
|
|
|
|
expect(lettings_log.address_line1_input).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq(nil) |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E09000033") |
|
|
|
|
|
|
|
|
|
choose "Yes" |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
|
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(1) # yes |
|
|
|
|
expect(lettings_log.uprn).to eq("111") |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(1) # yes |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Some Place") |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq("Bristol") |
|
|
|
|
expect(lettings_log.address_line1_input).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq(nil) |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E09000033") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and changes to uprn not known" do |
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
visit("/lettings-logs/#{lettings_log.id}/uprn") |
|
|
|
|
|
|
|
|
|
choose "No" |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
|
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1_input).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq(nil) |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq(nil) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and uprn is not confirmed" do |
|
|
|
|
before do |
|
|
|
|
choose "No, I want to search for the address instead" |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
|
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1_input).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq(nil) |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq(nil) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and uprn is not known" do |
|
|
|
|
before do |
|
|
|
|
choose "No" |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1_input).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq(nil) |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq(nil) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and the address is not found" do |
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
fill_in("lettings_log[address_line1_input]", with: "Address line 1") |
|
|
|
|
fill_in("lettings_log[postcode_full_input]", with: "AA1 1AB") |
|
|
|
|
click_button("Search") |
|
|
|
|
|
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AB") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq(nil) |
|
|
|
|
|
|
|
|
|
click_button("Confirm and continue") |
|
|
|
|
|
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_full).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AB") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(0) |
|
|
|
|
expect(lettings_log.la).to eq(nil) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and address is found, re-searched and not found" do |
|
|
|
|
before do |
|
|
|
|
fill_in("lettings_log[address_line1_input]", with: "Address line 1") |
|
|
|
|
fill_in("lettings_log[postcode_full_input]", with: "AA1 1AA") |
|
|
|
|
click_button("Search") |
|
|
|
|
visit("/lettings-logs/#{lettings_log.id}/address-matcher") |
|
|
|
|
|
|
|
|
|
fill_in("lettings_log[address_line1_input]", with: "Address line 1") |
|
|
|
|
fill_in("lettings_log[postcode_full_input]", with: "AA1 1AB") |
|
|
|
|
click_button("Search") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "routes to the correct page" do |
|
|
|
|
expect(page).to have_current_path("/lettings-logs/#{lettings_log.id}/no-address-found") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and the user selects 'address_not_listed'" do |
|
|
|
|
before do |
|
|
|
|
fill_in("lettings_log[address_line1_input]", with: "Address line 1") |
|
|
|
|
fill_in("lettings_log[postcode_full_input]", with: "AA1 1AA") |
|
|
|
|
click_button("Search") |
|
|
|
|
choose "The address is not listed, I want to enter the address manually" |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq("uprn_not_listed") |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq(nil) |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E09000033") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and the user enters a new address manually" do |
|
|
|
|
context "without changing a valid postcode" do |
|
|
|
|
before do |
|
|
|
|
fill_in("lettings_log[town_or_city]", with: "Town") |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq("uprn_not_listed") |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.address_line2).to eq("") |
|
|
|
|
expect(lettings_log.town_or_city).to eq("Town") |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E09000033") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with changing the postcode" do |
|
|
|
|
before do |
|
|
|
|
fill_in("lettings_log[town_or_city]", with: "Town") |
|
|
|
|
fill_in("lettings_log[postcode_full]", with: "AA12AA") |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(0) # no |
|
|
|
|
expect(lettings_log.uprn).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(nil) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq("uprn_not_listed") |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 2AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.address_line2).to eq("") |
|
|
|
|
expect(lettings_log.town_or_city).to eq("Town") |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E08000010") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and the user selects 'address_not_listed' and then changes their mind and selects an address" do |
|
|
|
|
before do |
|
|
|
|
fill_in("lettings_log[address_line1_input]", with: "Address line 1") |
|
|
|
|
fill_in("lettings_log[postcode_full_input]", with: "AA1 1AA") |
|
|
|
|
click_button("Search") |
|
|
|
|
choose "The address is not listed, I want to enter the address manually" |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
|
|
|
|
|
visit("/lettings-logs/#{lettings_log.id}/uprn-selection") |
|
|
|
|
choose("lettings-log-uprn-selection-111-field", allow_label_click: true) |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(1) |
|
|
|
|
expect(lettings_log.uprn).to eq("111") |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(1) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Some Place") |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq("Bristol") |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E09000033") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and possible addresses found and selected" do |
|
|
|
|
before do |
|
|
|
|
fill_in("lettings_log[address_line1_input]", with: "Address line 1") |
|
|
|
|
fill_in("lettings_log[postcode_full_input]", with: "AA1 1AA") |
|
|
|
|
click_button("Search") |
|
|
|
|
choose("lettings-log-uprn-selection-111-field", allow_label_click: true) |
|
|
|
|
click_button("Save and continue") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "sets correct address fields" do |
|
|
|
|
lettings_log.reload |
|
|
|
|
expect(lettings_log.uprn_known).to eq(1) |
|
|
|
|
expect(lettings_log.uprn).to eq("111") |
|
|
|
|
expect(lettings_log.uprn_confirmed).to eq(1) |
|
|
|
|
expect(lettings_log.uprn_selection).to eq(nil) |
|
|
|
|
expect(lettings_log.postcode_known).to eq(1) |
|
|
|
|
expect(lettings_log.postcode_full).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_line1).to eq("Some Place") |
|
|
|
|
expect(lettings_log.address_line2).to eq(nil) |
|
|
|
|
expect(lettings_log.town_or_city).to eq("Bristol") |
|
|
|
|
expect(lettings_log.address_line1_input).to eq("Address line 1") |
|
|
|
|
expect(lettings_log.postcode_full_input).to eq("AA1 1AA") |
|
|
|
|
expect(lettings_log.address_search_value_check).to eq(nil) |
|
|
|
|
expect(lettings_log.la).to eq("E09000033") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|