From a4d9687c8c243b3e68637bcde8ed4b10569d704d Mon Sep 17 00:00:00 2001 From: Kat <54268893+kosiakkatrina@users.noreply.github.com> Date: Mon, 10 Mar 2025 17:13:37 +0000 Subject: [PATCH] Add search controller tests --- .../address_search_controller_spec.rb | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) 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