diff --git a/Gemfile.lock b/Gemfile.lock index bcd977d68..3d1a3f0d3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -343,7 +343,7 @@ GEM activesupport (>= 3.0.0) raabro (1.4.0) racc (1.8.1) - rack (3.1.11) + rack (3.1.12) rack-attack (6.7.0) rack (>= 1.0, < 4) rack-mini-profiler (3.3.1) diff --git a/app/controllers/address_search_controller.rb b/app/controllers/address_search_controller.rb index 616d5b702..74cda65c2 100644 --- a/app/controllers/address_search_controller.rb +++ b/app/controllers/address_search_controller.rb @@ -5,7 +5,9 @@ class AddressSearchController < ApplicationController def index query = params[:query] - if query.match?(/\A\d+\z/) && query.length > 5 + if query.nil? + render json: { error: "Query cannot be blank." }, status: :bad_request + elsif query.match?(/\A\d+\z/) && query.length > 5 # Query is all numbers and greater than 5 digits, assume it's a UPRN service = UprnClient.new(query) service.call @@ -38,7 +40,7 @@ class AddressSearchController < ApplicationController address_service.call uprn_service.call - results = ([uprn_service.result] || []) + (address_service.result || []) + results = [uprn_service.result, *address_service.result].compact if address_service.error.present? && uprn_service.error.present? render json: { error: "Address and UPRN are not recognised." }, status: :not_found diff --git a/app/models/form/lettings/subsections/property_information.rb b/app/models/form/lettings/subsections/property_information.rb index 475ff0a8c..3b827bf48 100644 --- a/app/models/form/lettings/subsections/property_information.rb +++ b/app/models/form/lettings/subsections/property_information.rb @@ -56,6 +56,8 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection end def displayed_in_tasklist?(log) + return true if form.start_year_2025_or_later? + !(log.is_supported_housing? && log.is_renewal?) end end diff --git a/spec/models/form/lettings/subsections/property_information_spec.rb b/spec/models/form/lettings/subsections/property_information_spec.rb index 2630c83d4..ed0add494 100644 --- a/spec/models/form/lettings/subsections/property_information_spec.rb +++ b/spec/models/form/lettings/subsections/property_information_spec.rb @@ -84,6 +84,14 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do ], ) end + + context "when it is supported housing and a renewal" do + let(:log) { FactoryBot.build(:lettings_log, needstype: 2, renewal: 1) } + + it "is not displayed in tasklist" do + expect(property_information.displayed_in_tasklist?(log)).to eq(false) + end + end end context "when 2025" do @@ -118,6 +126,14 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do ], ) end + + context "when it is supported housing and a renewal" do + let(:log) { FactoryBot.build(:lettings_log, needstype: 2, renewal: 1) } + + it "is displayed in tasklist" do + expect(property_information.displayed_in_tasklist?(log)).to eq(true) + end + end end end diff --git a/spec/requests/address_search_controller_spec.rb b/spec/requests/address_search_controller_spec.rb index 5c2acd11a..7c8523abe 100644 --- a/spec/requests/address_search_controller_spec.rb +++ b/spec/requests/address_search_controller_spec.rb @@ -144,5 +144,45 @@ RSpec.describe AddressSearchController, type: :request do expect(sales_log.la).to eq(nil) end end + + context "when searching by address and UPRN" do + let(:sales_log) { create(:sales_log, :completed, manual_address_entry_selected: false, assigned_to: user) } + + context "and theres no uprn returned" do + before do + body = { results: [{ DPA: { "ADDRESS": "1, Test Street", "UPRN": "123" } }] }.to_json + uprn_body = { results: [{ DPA: nil }] }.to_json + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=100") + .to_return(status: 200, body:, headers: {}) + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=100") + .to_return(status: 200, body: uprn_body, headers: {}) + end + + it "returns the address results" do + get "/address-search?query=100" + + expect(response).to have_http_status(:ok) + expect(response.body).to eq([{ text: "1, Test Street", value: "123" }].to_json) + end + end + + context "and theres no address returned" do + before do + body = { results: [{ DPA: nil }] }.to_json + uprn_body = { results: [{ DPA: { "ADDRESS": "2, Test Street", UPRN: "321" } }] }.to_json + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=100") + .to_return(status: 200, body:, headers: {}) + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=100") + .to_return(status: 200, body: uprn_body, headers: {}) + end + + it "returns the address results" do + get "/address-search?query=100" + + expect(response).to have_http_status(:ok) + expect(response.body).to eq([{ text: "2, Test Street", value: "321" }].to_json) + end + end + end end end