@ -10,6 +10,11 @@ RSpec.describe Imports::SalesLogsImportService do
let ( :organisation ) { FactoryBot . create ( :organisation , old_visible_id : " 1 " , provider_type : " PRP " ) }
let ( :managing_organisation ) { FactoryBot . create ( :organisation , old_visible_id : " 2 " , provider_type : " PRP " ) }
let ( :remote_folder ) { " sales_logs " }
let ( :shared_ownership_sales_log_id ) { " 0ead17cb-1668-442d-898c-0d52879ff592 " }
let ( :shared_ownership_sales_log_id2 ) { " 166fc004-392e-47a8-acb8-1c018734882b " }
let ( :outright_sale_sales_log_id ) { " 00d2343e-d5fa-4c89-8400-ec3854b0f2b4 " }
let ( :discounted_ownership_sales_log_id ) { " 0b4a68df-30cc-474a-93c0-a56ce8fdad3b " }
def open_file ( directory , filename )
File . open ( " #{ directory } / #{ filename } .xml " )
@ -29,28 +34,22 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " when importing sales logs " do
let ( :remote_folder ) { " sales_logs " }
let ( :sales_log_id ) { " 0ead17cb-1668-442d-898c-0d52879ff592 " }
let ( :sales_log_id2 ) { " 166fc004-392e-47a8-acb8-1c018734882b " }
let ( :sales_log_id3 ) { " 00d2343e-d5fa-4c89-8400-ec3854b0f2b4 " }
let ( :sales_log_id4 ) { " 0b4a68df-30cc-474a-93c0-a56ce8fdad3b " }
before do
# Stub the S3 file listing and download
allow ( storage_service ) . to receive ( :list_files )
. and_return ( %W[ #{ remote_folder } / #{ sales_log_id } .xml #{ remote_folder } / #{ sales_log_id2 } .xml #{ remote_folder } / #{ sales_log_id3 } .xml #{ remote_folder } / #{ sales_log_id4 } .xml ] )
. and_return ( %W[ #{ remote_folder } / #{ shared_ownership_sales_log_id } .xml #{ remote_folder } / #{ shared_ownership_sales_log_id2 } .xml #{ remote_folder } / #{ outright_sale_sales_log_id } .xml #{ remote_folder } / #{ discounted_ownership_sales_log_id } .xml ] )
allow ( storage_service ) . to receive ( :get_file_io )
. with ( " #{ remote_folder } / #{ sales_log_id } .xml " )
. and_return ( open_file ( fixture_directory , sales_log_id ) , open_file ( fixture_directory , sales_log_id ) )
. with ( " #{ remote_folder } / #{ shared_ownership_sales_log_id } .xml " )
. and_return ( open_file ( fixture_directory , shared_ownership_s ales_log_id ) , open_file ( fixture_directory , shared_ownership_ sales_log_id) )
allow ( storage_service ) . to receive ( :get_file_io )
. with ( " #{ remote_folder } / #{ sales_log_id2 } .xml " )
. and_return ( open_file ( fixture_directory , sales_log_id2 ) , open_file ( fixture_directory , sales_log_id2 ) )
. with ( " #{ remote_folder } / #{ shared_ownership_s ales_log_id2 } .xml " )
. and_return ( open_file ( fixture_directory , shared_ownership_s ales_log_id2 ) , open_file ( fixture_directory , shared_ownership_ sales_log_id2) )
allow ( storage_service ) . to receive ( :get_file_io )
. with ( " #{ remote_folder } / #{ sales_log_id3 } .xml " )
. and_return ( open_file ( fixture_directory , sales_log_id3 ) , open_file ( fixture_directory , sales_log_id3 ) )
. with ( " #{ remote_folder } / #{ outright_sale_ sales_log_id} .xml " )
. and_return ( open_file ( fixture_directory , outright_sale_ sales_log_id) , open_file ( fixture_directory , outright_sale_ sales_log_id) )
allow ( storage_service ) . to receive ( :get_file_io )
. with ( " #{ remote_folder } / #{ sales_log_id4 } .xml " )
. and_return ( open_file ( fixture_directory , sales_log_id4 ) , open_file ( fixture_directory , sales_log_id4 ) )
. with ( " #{ remote_folder } / #{ discounted_ownership_ sales_log_id} .xml " )
. and_return ( open_file ( fixture_directory , discounted_ownership_ sales_log_id) , open_file ( fixture_directory , discounted_ownership_ sales_log_id) )
end
it " successfully creates all sales logs " do
@ -70,30 +69,30 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " when there are status discrepancies " do
let ( :sales_log_id5 ) { " 893ufj2s-lq77-42m4-rty6-ej09gh585uy1 " }
let ( :sales_log_id6 ) { " 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd " }
let ( :sales_log_file ) { open_file ( fixture_directory , sales_log_id5 ) }
let ( :shared_ownership_sales_log_id3 ) { " 893ufj2s-lq77-42m4-rty6-ej09gh585uy1 " }
let ( :shared_ownership_sales_log_id4 ) { " 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd " }
let ( :sales_log_file ) { open_file ( fixture_directory , shared_ownership_sales_log_id3 ) }
let ( :sales_log_xml ) { Nokogiri :: XML ( sales_log_file ) }
before do
allow ( storage_service ) . to receive ( :get_file_io )
. with ( " #{ remote_folder } / #{ sales_log_id5 } .xml " )
. and_return ( open_file ( fixture_directory , sales_log_id5 ) , open_file ( fixture_directory , sales_log_id5 ) )
. with ( " #{ remote_folder } / #{ shared_ownership_sales_log_id3 } .xml " )
. and_return ( open_file ( fixture_directory , shared_ownership_sales_log_id3 ) , open_file ( fixture_directory , shared_ownership_sales_log_id3 ) )
allow ( storage_service ) . to receive ( :get_file_io )
. with ( " #{ remote_folder } / #{ sales_log_id6 } .xml " )
. and_return ( open_file ( fixture_directory , sales_log_id6 ) , open_file ( fixture_directory , sales_log_id6 ) )
. with ( " #{ remote_folder } / #{ shared_ownership_sales_log_id4 } .xml " )
. and_return ( open_file ( fixture_directory , shared_ownership_sales_log_id4 ) , open_file ( fixture_directory , shared_ownership_sales_log_id4 ) )
end
it " the logger logs a warning with the sales log's old id/filename " do
expect ( logger ) . to receive ( :warn ) . with ( / is not completed / ) . once
expect ( logger ) . to receive ( :warn ) . with ( / sales log with old id: #{ sales_log_id5 } is incomplete but status should be complete / ) . once
expect ( logger ) . to receive ( :warn ) . with ( / sales log with old id: #{ shared_ownership_sales_log_id3 } is incomplete but status should be complete / ) . once
sales_log_service . send ( :create_log , sales_log_xml )
end
it " on completion the ids of all logs with status discrepancies are logged in a warning " do
allow ( storage_service ) . to receive ( :list_files )
. and_return ( %W[ #{ remote_folder } / #{ sales_log_id5 } .xml #{ remote_folder } / #{ sales_log_id6 } .xml ] )
. and_return ( %W[ #{ remote_folder } / #{ shared_ownership_sales_log_id3 } .xml #{ remote_folder } / #{ shared_ownership_sales_log_id4 } .xml ] )
expect ( logger ) . to receive ( :warn ) . with ( / is not completed / ) . twice
expect ( logger ) . to receive ( :warn ) . with ( / is incomplete but status should be complete / ) . twice
expect ( logger ) . to receive ( :warn ) . with ( / The following sales logs had status discrepancies: \ [893ufj2s-lq77-42m4-rty6-ej09gh585uy1, 5ybz29dj-l33t-k1l0-hj86-n4k4ma77xkcd \ ] / )
@ -108,7 +107,7 @@ RSpec.describe Imports::SalesLogsImportService do
let ( :sales_log_xml ) { Nokogiri :: XML ( sales_log_file ) }
context " and the organisation legacy ID does not exist " do
let ( :sales_log_id ) { " 0ead17cb-1668-442d-898c-0d52879ff592 " }
let ( :sales_log_id ) { shared_ownership_sales_log_id }
before { sales_log_xml . at_xpath ( " //xmlns:OWNINGORGID " ) . content = 99_999 }
@ -119,7 +118,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " when the mortgage lender is set to an existing option " do
let ( :sales_log_id ) { " 0b4a68df-30cc-474a-93c0-a56ce8fdad3b " }
let ( :sales_log_id ) { discounted_ownership_sales_log_id }
before do
sales_log_xml . at_xpath ( " //xmlns:Q34a " ) . content = " halifax "
@ -135,7 +134,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " when the mortgage lender is set to a non existing option " do
let ( :sales_log_id ) { " 0b4a68df-30cc-474a-93c0-a56ce8fdad3b " }
let ( :sales_log_id ) { discounted_ownership_sales_log_id }
before do
sales_log_xml . at_xpath ( " //xmlns:Q34a " ) . content = " something else "
@ -152,7 +151,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " when the armedforcesspouse is not answered " do
let ( :sales_log_id ) { " 0b4a68df-30cc-474a-93c0-a56ce8fdad3b " }
let ( :sales_log_id ) { discounted_ownership_sales_log_id }
before do
sales_log_xml . at_xpath ( " //xmlns:ARMEDFORCESSPOUSE " ) . content = " "
@ -168,7 +167,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " with shared ownership type " do
let ( :sales_log_id ) { " 0ead17cb-1668-442d-898c-0d52879ff592 " }
let ( :sales_log_id ) { shared_ownership_sales_log_id }
it " successfully creates a completed shared ownership log " do
allow ( logger ) . to receive ( :warn ) . and_return ( nil )
@ -181,7 +180,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " with discounted ownership type " do
let ( :sales_log_id ) { " 0b4a68df-30cc-474a-93c0-a56ce8fdad3b " }
let ( :sales_log_id ) { discounted_ownership_sales_log_id }
it " successfully creates a completed discounted ownership log " do
allow ( logger ) . to receive ( :warn ) . and_return ( nil )
@ -194,7 +193,7 @@ RSpec.describe Imports::SalesLogsImportService do
end
context " with outright sale type " do
let ( :sales_log_id ) { " 00d2343e-d5fa-4c89-8400-ec3854b0f2b4 " }
let ( :sales_log_id ) { outright_sale_sales_log_id }
it " successfully creates a completed outright sale log " do
allow ( logger ) . to receive ( :warn ) . and_return ( nil )