From 4aae303e099e6999d5155585b051457226ae3253 Mon Sep 17 00:00:00 2001 From: Nat Dean-Lewis <94526761+natdeanlewissoftwire@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:55:13 +0000 Subject: [PATCH] CLDC-4290: filter address responses to England only (#3256) * CLDC-4290: filter address responses to england only * CLDC-4290: update test stubs * CLDC-4290: update other stubbed urls --- app/services/address_client.rb | 1 + app/services/uprn_client.rb | 1 + .../lettings/questions/address_search_spec.rb | 2 +- .../sales/questions/address_search_spec.rb | 2 +- spec/request_helper.rb | 20 +++++++++---------- .../address_search_controller_spec.rb | 20 +++++++++---------- spec/services/address_client_spec.rb | 2 +- .../lettings_log_export_service_spec.rb | 2 +- spec/services/uprn_client_spec.rb | 2 +- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/services/address_client.rb b/app/services/address_client.rb index 3fca0a0d0..2d5289eb0 100644 --- a/app/services/address_client.rb +++ b/app/services/address_client.rb @@ -46,6 +46,7 @@ private key: ENV["OS_DATA_KEY"], maxresults: @options[:maxresults] || 10, minmatch: @options[:minmatch] || 0.4, + fq: ["COUNTRY_CODE:E"], } uri.query = URI.encode_www_form(params) uri.to_s diff --git a/app/services/uprn_client.rb b/app/services/uprn_client.rb index 8dcd2e7a0..b61bc1ec3 100644 --- a/app/services/uprn_client.rb +++ b/app/services/uprn_client.rb @@ -49,6 +49,7 @@ private uprn:, key: ENV["OS_DATA_KEY"], dataset: %w[DPA LPI].join(","), + fq: ["COUNTRY_CODE:E"], } uri.query = URI.encode_www_form(params) uri.to_s diff --git a/spec/models/form/lettings/questions/address_search_spec.rb b/spec/models/form/lettings/questions/address_search_spec.rb index 8635aa017..256531a65 100644 --- a/spec/models/form/lettings/questions/address_search_spec.rb +++ b/spec/models/form/lettings/questions/address_search_spec.rb @@ -48,7 +48,7 @@ RSpec.describe Form::Lettings::Questions::AddressSearch, type: :model do ], }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=123") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=123") .to_return(status: 200, body:, headers: {}) end diff --git a/spec/models/form/sales/questions/address_search_spec.rb b/spec/models/form/sales/questions/address_search_spec.rb index a2a2b51c9..e8dfb9038 100644 --- a/spec/models/form/sales/questions/address_search_spec.rb +++ b/spec/models/form/sales/questions/address_search_spec.rb @@ -48,7 +48,7 @@ RSpec.describe Form::Sales::Questions::AddressSearch, type: :model do ], }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=123") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=123") .to_return(status: 200, body:, headers: {}) end diff --git a/spec/request_helper.rb b/spec/request_helper.rb index 5b867ecde..ac6e2659d 100644 --- a/spec/request_helper.rb +++ b/spec/request_helper.rb @@ -18,14 +18,14 @@ module RequestHelper .to_return(status: 200, body: "{\"status\":200,\"result\":{\"postcode\":\"ZZ1 1ZZ\",\"admin_district\":\"Westminster\",\"codes\":{\"admin_district\":\"E09000033\"}}}", headers: {}) body = { results: [{ DPA: { UPRN: "10033558653" } }] }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key&maxresults=10&minmatch=0.4&query=Address%20line%201,%20SW1A%201AA") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key&maxresults=10&minmatch=0.4&query=Address%20line%201,%20SW1A%201AA") .to_return(status: 200, body:, headers: {}) body = { results: [{ DPA: { "POSTCODE": "SW1A 1AA", "POST_TOWN": "London", "PO_BOX_NUMBER": "The Mall, City Of Westminster" } }] }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key&uprn=1") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key&uprn=1") .to_return(status: 200, body:, headers: {}) - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key&uprn=10033558653") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key&uprn=10033558653") .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=10033558653") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=10033558653") .to_return(status: 200, body:, headers: {}) WebMock.stub_request(:post, /api.notifications.service.gov.uk\/v2\/notifications\/email/) @@ -45,7 +45,7 @@ module RequestHelper ], }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=1") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=1") .to_return(status: 200, body:, headers: {}) body = { @@ -61,7 +61,7 @@ module RequestHelper ], }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key&uprn=121") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key&uprn=121") .to_return(status: 200, body:, headers: {}) body = { @@ -76,7 +76,7 @@ module RequestHelper ], }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=123") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=123") .to_return(status: 200, body:, headers: {}) body = { @@ -91,13 +91,13 @@ module RequestHelper ], }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=12") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=12") .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=1234567890123") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=1234567890123") .to_return(status: 404, body: "", headers: {}) - template = Addressable::Template.new "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query={+address_query}" + template = Addressable::Template.new "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query={+address_query}" WebMock.stub_request(:get, template) .to_return do |request| address = request.uri.query_values["query"].split(",") diff --git a/spec/requests/address_search_controller_spec.rb b/spec/requests/address_search_controller_spec.rb index a9fff4ace..9287689fe 100644 --- a/spec/requests/address_search_controller_spec.rb +++ b/spec/requests/address_search_controller_spec.rb @@ -152,9 +152,9 @@ RSpec.describe AddressSearchController, type: :request do before do body = { results: [{ DPA: { "ADDRESS": "100, Test Street", "UPRN": "100" } }] }.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") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&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") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=100") .to_return(status: 200, body: uprn_body, headers: {}) end @@ -170,9 +170,9 @@ RSpec.describe AddressSearchController, type: :request do before do body = { results: [{ DPA: nil }] }.to_json uprn_body = { results: [{ DPA: { "ADDRESS": "321, 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=321") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=321") .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=321") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=321") .to_return(status: 200, body: uprn_body, headers: {}) end @@ -199,9 +199,9 @@ RSpec.describe AddressSearchController, type: :request do before do address_body = { results: [{ DPA: { "ADDRESS": "Path not taken", UPRN: "111" } }] }.to_json uprn_body = { results: [{ DPA: { "ADDRESS": "2, Test Street", UPRN: "123456" } }] }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=123456") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=123456") .to_return(status: 200, body: address_body, headers: {}) - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=123456") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=123456") .to_return(status: 200, body: uprn_body, headers: {}) end @@ -217,9 +217,9 @@ RSpec.describe AddressSearchController, type: :request do before do address_body = { results: [{ DPA: { "ADDRESS": "70, Test Street", UPRN: "123777" } }] }.to_json uprn_body = { results: [{ DPA: { "ADDRESS": "Path not taken", UPRN: "111" } }] }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=70,") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=70,") .to_return(status: 200, body: address_body, headers: {}) - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=70,") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=70,") .to_return(status: 200, body: uprn_body, headers: {}) end @@ -235,9 +235,9 @@ RSpec.describe AddressSearchController, type: :request do before do address_body = { results: [{ DPA: { "ADDRESS": "111, Test Street", UPRN: "123777" } }] }.to_json uprn_body = { results: [{ DPA: { "ADDRESS": "70 Bean Road", UPRN: "111" } }] }.to_json - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=111") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&maxresults=10&minmatch=0.2&query=111") .to_return(status: 200, body: address_body, headers: {}) - WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=111") + WebMock.stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=111") .to_return(status: 200, body: uprn_body, headers: {}) end diff --git a/spec/services/address_client_spec.rb b/spec/services/address_client_spec.rb index 0a222f0c7..cdfa6d672 100644 --- a/spec/services/address_client_spec.rb +++ b/spec/services/address_client_spec.rb @@ -8,7 +8,7 @@ describe AddressClient do end def stub_api_request(body:, status: 200) - stub_request(:get, "https://api.os.uk/search/places/v1/find?key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query=123") + stub_request(:get, "https://api.os.uk/search/places/v1/find?fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&maxresults=10&minmatch=0.4&query=123") .to_return(status:, body:, headers: {}) end diff --git a/spec/services/exports/lettings_log_export_service_spec.rb b/spec/services/exports/lettings_log_export_service_spec.rb index 53dd0fd0f..335617aec 100644 --- a/spec/services/exports/lettings_log_export_service_spec.rb +++ b/spec/services/exports/lettings_log_export_service_spec.rb @@ -158,7 +158,7 @@ RSpec.describe Exports::LettingsLogExportService do before do Timecop.freeze(start_time) Singleton.__init__(FormHandler) - stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=100023336956") + stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=100023336956") .to_return(status: 200, body: '{"status":200,"results":[{"DPA":{ "PO_BOX_NUMBER": "fake", "ORGANISATION_NAME": "org", diff --git a/spec/services/uprn_client_spec.rb b/spec/services/uprn_client_spec.rb index 8d5c45ed9..f574be20f 100644 --- a/spec/services/uprn_client_spec.rb +++ b/spec/services/uprn_client_spec.rb @@ -8,7 +8,7 @@ describe UprnClient do end def stub_api_request(body:, status: 200) - stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA,LPI&key=OS_DATA_KEY&uprn=123") + stub_request(:get, "https://api.os.uk/search/places/v1/uprn?dataset=DPA%2CLPI&fq=COUNTRY_CODE%3AE&key=OS_DATA_KEY&uprn=123") .to_return(status:, body:, headers: {}) end