Browse Source

Merge remote-tracking branch 'origin/CLDC-3857-Add-new-questions-to-organisation-setup' into CLDC-3857-Add-new-questions-to-organisation-setup

pull/2971/head
Manny Dinssa 2 months ago
parent
commit
5817d43b8a
  1. 2
      Gemfile.lock
  2. 6
      app/controllers/address_search_controller.rb
  3. 2
      app/models/form/lettings/subsections/property_information.rb
  4. 16
      spec/models/form/lettings/subsections/property_information_spec.rb
  5. 40
      spec/requests/address_search_controller_spec.rb

2
Gemfile.lock

@ -343,7 +343,7 @@ GEM
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
raabro (1.4.0) raabro (1.4.0)
racc (1.8.1) racc (1.8.1)
rack (3.1.11) rack (3.1.12)
rack-attack (6.7.0) rack-attack (6.7.0)
rack (>= 1.0, < 4) rack (>= 1.0, < 4)
rack-mini-profiler (3.3.1) rack-mini-profiler (3.3.1)

6
app/controllers/address_search_controller.rb

@ -5,7 +5,9 @@ class AddressSearchController < ApplicationController
def index def index
query = params[:query] 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 # Query is all numbers and greater than 5 digits, assume it's a UPRN
service = UprnClient.new(query) service = UprnClient.new(query)
service.call service.call
@ -38,7 +40,7 @@ class AddressSearchController < ApplicationController
address_service.call address_service.call
uprn_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? if address_service.error.present? && uprn_service.error.present?
render json: { error: "Address and UPRN are not recognised." }, status: :not_found render json: { error: "Address and UPRN are not recognised." }, status: :not_found

2
app/models/form/lettings/subsections/property_information.rb

@ -56,6 +56,8 @@ class Form::Lettings::Subsections::PropertyInformation < ::Form::Subsection
end end
def displayed_in_tasklist?(log) def displayed_in_tasklist?(log)
return true if form.start_year_2025_or_later?
!(log.is_supported_housing? && log.is_renewal?) !(log.is_supported_housing? && log.is_renewal?)
end end
end end

16
spec/models/form/lettings/subsections/property_information_spec.rb

@ -84,6 +84,14 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do
], ],
) )
end 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 end
context "when 2025" do context "when 2025" do
@ -118,6 +126,14 @@ RSpec.describe Form::Lettings::Subsections::PropertyInformation, type: :model do
], ],
) )
end 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
end end

40
spec/requests/address_search_controller_spec.rb

@ -144,5 +144,45 @@ RSpec.describe AddressSearchController, type: :request do
expect(sales_log.la).to eq(nil) expect(sales_log.la).to eq(nil)
end end
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
end end

Loading…
Cancel
Save