Browse Source

feat: remove redundant methods

pull/2278/head
natdeanlewissoftwire 2 years ago
parent
commit
a8a730c6f7
  1. 32
      app/services/address_data_presenter.rb
  2. 8
      spec/models/form/lettings/questions/uprn_selection_spec.rb
  3. 8
      spec/models/form/sales/questions/uprn_selection_spec.rb
  4. 18
      spec/services/bulk_upload/lettings/year2024/row_parser_spec.rb
  5. 2
      spec/services/bulk_upload/sales/year2024/row_parser_spec.rb

32
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

8
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)

8
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)

18
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

2
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?

Loading…
Cancel
Save