From a8a730c6f738a4e519f9671fc69ac73bf79fe985 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Mon, 11 Mar 2024 11:32:26 +0000 Subject: [PATCH] feat: remove redundant methods --- app/services/address_data_presenter.rb | 32 ------------------- .../lettings/questions/uprn_selection_spec.rb | 8 ++--- .../sales/questions/uprn_selection_spec.rb | 8 ++--- .../lettings/year2024/row_parser_spec.rb | 18 +++++++++++ .../sales/year2024/row_parser_spec.rb | 2 +- 5 files changed, 27 insertions(+), 41 deletions(-) diff --git a/app/services/address_data_presenter.rb b/app/services/address_data_presenter.rb index 3e024d276..c72f32f43 100644 --- a/app/services/address_data_presenter.rb +++ b/app/services/address_data_presenter.rb @@ -11,38 +11,6 @@ class AddressDataPresenter data["UPRN"] end - def address_line1 - data.values_at( - "PO_BOX_NUMBER", - "ORGANISATION_NAME", - "DEPARTMENT_NAME", - "SUB_BUILDING_NAME", - "BUILDING_NAME", - "BUILDING_NUMBER", - "DEPENDENT_THOROUGHFARE_NAME", - "THOROUGHFARE_NAME", - ).compact - .join(", ") - .titleize - end - - def address_line2 - data.values_at( - "DOUBLE_DEPENDENT_LOCALITY", "DEPENDENT_LOCALITY" - ).compact - .join(", ") - .titleize - .presence - end - - def town_or_city - data["POST_TOWN"].titleize - end - - def postcode - data["POSTCODE"] - end - def address data["ADDRESS"] end diff --git a/spec/models/form/lettings/questions/uprn_selection_spec.rb b/spec/models/form/lettings/questions/uprn_selection_spec.rb index 9d863967d..de009a8c9 100644 --- a/spec/models/form/lettings/questions/uprn_selection_spec.rb +++ b/spec/models/form/lettings/questions/uprn_selection_spec.rb @@ -57,14 +57,14 @@ RSpec.describe Form::Lettings::Questions::UprnSelection, type: :model do end it "has the correct answer options" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: "", headers: {}) expect(question.answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) end it "has the correct displayed answer options" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: "", headers: {}) expect(question.displayed_answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) @@ -80,7 +80,7 @@ RSpec.describe Form::Lettings::Questions::UprnSelection, type: :model do context "when the log has address options" do it "has the correct hidden_in_check_answers?" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: '{"results": {"0": "address_0", "1": "address_1", "2": "address_2"}}', headers: {}) expect(question.hidden_in_check_answers?(log)).to eq(false) @@ -93,7 +93,7 @@ RSpec.describe Form::Lettings::Questions::UprnSelection, type: :model do end it "has the correct hidden_in_check_answers?" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: "", headers: {}) expect(question.hidden_in_check_answers?(log)).to eq(true) diff --git a/spec/models/form/sales/questions/uprn_selection_spec.rb b/spec/models/form/sales/questions/uprn_selection_spec.rb index 36eee429b..1b9aaba39 100644 --- a/spec/models/form/sales/questions/uprn_selection_spec.rb +++ b/spec/models/form/sales/questions/uprn_selection_spec.rb @@ -57,14 +57,14 @@ RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do end it "has the correct answer options" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: "", headers: {}) expect(question.answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) end it "has the correct displayed answer options" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: "", headers: {}) expect(question.displayed_answer_options(log)).to eq({ "uprn_not_listed" => { "value" => "The address is not listed, I want to enter the address manually" }, "UPRN" => { "value" => "full address" }, "divider" => { "value" => true } }) @@ -80,7 +80,7 @@ RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do context "when the log has address options" do it "has the correct hidden_in_check_answers?" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: '{"results": {"0": "address_0", "1": "address_1", "2": "address_2"}}', headers: {}) expect(question.hidden_in_check_answers?(log)).to eq(false) @@ -93,7 +93,7 @@ RSpec.describe Form::Sales::Questions::UprnSelection, type: :model do end it "has the correct hidden_in_check_answers?" do - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: "", headers: {}) expect(question.hidden_in_check_answers?(log)).to eq(true) diff --git a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb index fe09d6aa5..98dd2ab53 100644 --- a/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb @@ -87,6 +87,24 @@ RSpec.describe BulkUpload::Lettings::Year2024::RowParser do stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) + stub_request(:get, /api\.os\.uk\/search\/places\/v1\/find/) + .to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result address line 1", POST_TOWN: "result town or city", POSTCODE: "AA1 1AA", UPRN: "12345" } }] }.to_json, headers: {}) + + stub_request(:get, /api\.os\.uk\/search\/places\/v1\/uprn/) + .to_return(status: 200, body: '{"status":200,"results":[{"DPA":{ + "PO_BOX_NUMBER": "fake", + "ORGANISATION_NAME": "org", + "DEPARTMENT_NAME": "name", + "SUB_BUILDING_NAME": "building", + "BUILDING_NAME": "name", + "BUILDING_NUMBER": "number", + "DEPENDENT_THOROUGHFARE_NAME": "data", + "THOROUGHFARE_NAME": "thing", + "POST_TOWN": "London", + "POSTCODE": "SE2 6RT" + + }}]}', headers: {}) + parser.valid? end diff --git a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb index dfa69f7e7..ba2edf33a 100644 --- a/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2024/row_parser_spec.rb @@ -243,7 +243,7 @@ RSpec.describe BulkUpload::Sales::Year2024::RowParser do stub_request(:get, /api\.postcodes\.io/) .to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\", \"codes\":{\"admin_district\": \"E08000003\"}}}", headers: {}) - stub_request(:get, /api.os.uk/) + stub_request(:get, /api\.os\.uk/) .to_return(status: 200, body: { results: [{ DPA: { MATCH: 0.9, BUILDING_NAME: "result address line 1", POST_TOWN: "result town or city", POSTCODE: "AA1 1AA", UPRN: "12345" } }] }.to_json, headers: {}) parser.valid?