|
|
|
@ -220,6 +220,87 @@ RSpec.describe Imports::SalesLogsImportService do
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with 23/24 logs" do |
|
|
|
|
around do |example| |
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 4, 1)) do |
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
example.run |
|
|
|
|
end |
|
|
|
|
Timecop.return |
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:DAY").content = "10" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:MONTH").content = "4" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:YEAR").content = "2023" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:UPRN").content = "" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:AddressLine1").content = "address 1" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:AddressLine2").content = "address 2" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:TownCity").content = "towncity" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:County").content = "county" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = "A1 1AA" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with outright sale type" do |
|
|
|
|
let(:sales_log_id) { "outright_sale_sales_log" } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:Q44MonthlyCharges").content = "40" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "successfully creates a completed outright sale log" do |
|
|
|
|
expect(logger).not_to receive(:error) |
|
|
|
|
expect(logger).not_to receive(:warn) |
|
|
|
|
expect(logger).not_to receive(:info) |
|
|
|
|
expect { sales_log_service.send(:create_log, sales_log_xml) } |
|
|
|
|
.to change(SalesLog, :count).by(1) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with shared sale type" do |
|
|
|
|
let(:sales_log_id) { "shared_ownership_sales_log" } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:joint").content = "1 Yes" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:JointMore").content = "2 No" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:PREVSHARED").content = "1" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:Q16aProplen2").content = "0" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:P2Eth").content = "2 White: Irish" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:P2Nat").content = "18 United Kingdom" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:buy2livein").content = "1" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "successfully creates a completed shared sale log" do |
|
|
|
|
expect(logger).not_to receive(:error) |
|
|
|
|
expect(logger).not_to receive(:warn) |
|
|
|
|
expect(logger).not_to receive(:info) |
|
|
|
|
expect { sales_log_service.send(:create_log, sales_log_xml) } |
|
|
|
|
.to change(SalesLog, :count).by(1) |
|
|
|
|
sales_log = SalesLog.find_by(old_id: sales_log_id) |
|
|
|
|
expect(sales_log.proplen_asked).to eq(1) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "with discounted sale type" do |
|
|
|
|
let(:sales_log_id) { "shared_ownership_sales_log" } |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:PREVSHARED").content = "1" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:Q20Bedrooms").content = "2" |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "successfully creates a completed shared sale log" do |
|
|
|
|
expect(logger).not_to receive(:error) |
|
|
|
|
expect(logger).not_to receive(:warn) |
|
|
|
|
expect(logger).not_to receive(:info) |
|
|
|
|
expect { sales_log_service.send(:create_log, sales_log_xml) } |
|
|
|
|
.to change(SalesLog, :count).by(1) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "and the mortgage soft validation is triggered (mortgage_value_check)" do |
|
|
|
|
let(:sales_log_id) { "discounted_ownership_sales_log" } |
|
|
|
|
|
|
|
|
@ -1336,6 +1417,97 @@ RSpec.describe Imports::SalesLogsImportService do
|
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when setting location fields for 23/24 logs" do |
|
|
|
|
let(:sales_log_id) { "outright_sale_sales_log" } |
|
|
|
|
|
|
|
|
|
around do |example| |
|
|
|
|
Timecop.freeze(Time.zone.local(2023, 4, 1)) do |
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
example.run |
|
|
|
|
end |
|
|
|
|
Timecop.return |
|
|
|
|
Singleton.__init__(FormHandler) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:DAY").content = "10" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:MONTH").content = "4" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:YEAR").content = "2023" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:UPRN").content = "123456781234" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:AddressLine1").content = "address 1" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:AddressLine2").content = "address 2" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:TownCity").content = "towncity" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:County").content = "county" |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:Q14Postcode").content = "A1 1AA" |
|
|
|
|
|
|
|
|
|
body = { |
|
|
|
|
results: [ |
|
|
|
|
{ |
|
|
|
|
DPA: { |
|
|
|
|
"POSTCODE": "LS16 6FT", |
|
|
|
|
"POST_TOWN": "Westminster", |
|
|
|
|
"PO_BOX_NUMBER": "321", |
|
|
|
|
"DOUBLE_DEPENDENT_LOCALITY": "Double Dependent Locality", |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
}.to_json |
|
|
|
|
|
|
|
|
|
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123456781234") |
|
|
|
|
.to_return(status: 200, body:, headers: {}) |
|
|
|
|
stub_request(:get, "https://api.os.uk/search/places/v1/uprn?key=OS_DATA_KEY&uprn=123") |
|
|
|
|
.to_return(status: 500, body: "{}", headers: {}) |
|
|
|
|
|
|
|
|
|
WebMock.stub_request(:get, /api.postcodes.io\/postcodes\/LS166FT/) |
|
|
|
|
.to_return(status: 200, body: '{"status":200,"result":{"admin_district":"Westminster","codes":{"admin_district":"E08000035"}}}', headers: {}) |
|
|
|
|
|
|
|
|
|
allow(logger).to receive(:warn).and_return(nil) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "correctly sets address if uprn is not given" do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:UPRN").content = "" |
|
|
|
|
sales_log_service.send(:create_log, sales_log_xml) |
|
|
|
|
|
|
|
|
|
sales_log = SalesLog.find_by(old_id: sales_log_id) |
|
|
|
|
expect(sales_log&.uprn_known).to eq(0) # no |
|
|
|
|
expect(sales_log&.uprn).to be_nil |
|
|
|
|
expect(sales_log&.address_line1).to eq("address 1") |
|
|
|
|
expect(sales_log&.address_line2).to eq("address 2") |
|
|
|
|
expect(sales_log&.town_or_city).to eq("towncity") |
|
|
|
|
expect(sales_log&.county).to eq("county") |
|
|
|
|
expect(sales_log&.postcode_full).to eq("A1 1AA") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "correctly sets address and uprn if uprn is given" do |
|
|
|
|
sales_log_service.send(:create_log, sales_log_xml) |
|
|
|
|
|
|
|
|
|
sales_log = SalesLog.find_by(old_id: sales_log_id) |
|
|
|
|
expect(sales_log&.uprn_known).to eq(1) |
|
|
|
|
expect(sales_log&.uprn).to eq("123456781234") |
|
|
|
|
expect(sales_log&.address_line1).to eq("321") |
|
|
|
|
expect(sales_log&.address_line2).to eq("Double Dependent Locality") |
|
|
|
|
expect(sales_log&.town_or_city).to eq("Westminster") |
|
|
|
|
expect(sales_log&.postcode_full).to eq("LS16 6FT") |
|
|
|
|
expect(sales_log&.la).to eq("E08000035") |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it "correctly sets address and uprn if uprn is given but not recognised" do |
|
|
|
|
sales_log_xml.at_xpath("//xmlns:UPRN").content = "123" |
|
|
|
|
|
|
|
|
|
sales_log_service.send(:create_log, sales_log_xml) |
|
|
|
|
|
|
|
|
|
sales_log = SalesLog.find_by(old_id: sales_log_id) |
|
|
|
|
expect(sales_log&.uprn_known).to eq(0) |
|
|
|
|
expect(sales_log&.uprn).to be_nil |
|
|
|
|
expect(sales_log&.address_line1).to eq("address 1") |
|
|
|
|
expect(sales_log&.address_line2).to eq("address 2") |
|
|
|
|
expect(sales_log&.town_or_city).to eq("towncity") |
|
|
|
|
expect(sales_log&.county).to eq("county") |
|
|
|
|
expect(sales_log&.postcode_full).to eq("A1 1AA") |
|
|
|
|
expect(sales_log&.la).to eq("E09000033") |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context "when setting default buyer 1 previous tenancy" do |
|
|
|
|
let(:sales_log_id) { "outright_sale_sales_log" } |
|
|
|
|
|
|
|
|
|