@ -439,6 +439,81 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
end
end
context " and it has a record with invalid equity " do
let ( :sales_log_id ) { " shared_ownership_sales_log " }
before do
sales_log_xml . at_xpath ( " //xmlns:Q23Equity " ) . content = " 78 "
end
it " intercepts the relevant validation error " do
expect ( logger ) . to receive ( :warn ) . with ( / Log shared_ownership_sales_log: Removing equity as the equity is invalid / )
expect { sales_log_service . send ( :create_log , sales_log_xml ) }
. not_to raise_error
end
it " clears out the invalid answers " do
allow ( logger ) . to receive ( :warn )
sales_log_service . send ( :create_log , sales_log_xml )
sales_log = SalesLog . find_by ( old_id : sales_log_id )
expect ( sales_log ) . not_to be_nil
expect ( sales_log . equity ) . to be_nil
end
end
context " and it has a record with invalid equity (under_min) " do
let ( :sales_log_id ) { " shared_ownership_sales_log " }
before do
sales_log_xml . at_xpath ( " //xmlns:Q23Equity " ) . content = " 20 "
end
it " intercepts the relevant validation error " do
expect ( logger ) . to receive ( :warn ) . with ( / Log shared_ownership_sales_log: Removing equity as the equity is invalid / )
expect { sales_log_service . send ( :create_log , sales_log_xml ) }
. not_to raise_error
end
it " clears out the invalid answers " do
allow ( logger ) . to receive ( :warn )
sales_log_service . send ( :create_log , sales_log_xml )
sales_log = SalesLog . find_by ( old_id : sales_log_id )
expect ( sales_log ) . not_to be_nil
expect ( sales_log . equity ) . to be_nil
end
end
context " and it has a record with postcode in invalid format " do
let ( :sales_log_id ) { " shared_ownership_sales_log " }
before do
sales_log_xml . at_xpath ( " //xmlns:Q14Postcode " ) . content = " L3132AF "
sales_log_xml . at_xpath ( " //xmlns:Q14ONSLACode " ) . content = " E07000223 "
end
it " intercepts the relevant validation error " do
expect ( logger ) . to receive ( :warn ) . with ( / Log shared_ownership_sales_log: Removing postcode as the postcode is invalid / )
expect { sales_log_service . send ( :create_log , sales_log_xml ) }
. not_to raise_error
end
it " clears out the invalid answers and sets correct la " do
allow ( logger ) . to receive ( :warn )
sales_log_service . send ( :create_log , sales_log_xml )
sales_log = SalesLog . find_by ( old_id : sales_log_id )
expect ( sales_log ) . not_to be_nil
expect ( sales_log . postcode_full ) . to be_nil
expect ( sales_log . pcodenk ) . to eq ( 1 ) # not known
expect ( sales_log . la ) . to eq ( " E07000223 " ) # not known
end
end
context " and setup field has validation error in incomplete log " do
context " and setup field has validation error in incomplete log " do
let ( :sales_log_id ) { " shared_ownership_sales_log " }
let ( :sales_log_id ) { " shared_ownership_sales_log " }
@ -501,7 +576,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
it " intercepts the relevant validation error " do
it " intercepts the relevant validation error " do
expect ( logger ) . to receive ( :warn ) . with ( / Enter a postcode in the correct format, for example AA1 1AA / )
expect ( logger ) . to receive ( :warn ) . with ( / Removing field postcode_full from log triggering validation: wrong_format / )
expect { sales_log_service . send ( :create_log , sales_log_xml ) }
expect { sales_log_service . send ( :create_log , sales_log_xml ) }
. not_to raise_error
. not_to raise_error
end
end
@ -518,6 +593,20 @@ RSpec.describe Imports::SalesLogsImportService do
end
end
end
end
context " when there is information about 7 people " do
let ( :sales_log_id ) { " shared_ownership_sales_log " }
before do
sales_log_xml . at_xpath ( " //xmlns:P7Age " ) . content = " 22 "
sales_log_xml . at_xpath ( " //xmlns:LiveInOther " ) . content = " 10 "
end
it " does not try to save information about person 7 " do
expect { sales_log_service . send ( :create_log , sales_log_xml ) }
. not_to raise_error
end
end
context " and it has an invalid record with invalid contracts exchange date " do
context " and it has an invalid record with invalid contracts exchange date " do
let ( :sales_log_id ) { " shared_ownership_sales_log " }
let ( :sales_log_id ) { " shared_ownership_sales_log " }