@ -81,6 +81,36 @@ RSpec.describe Imports::SalesLogsImportService do
expect ( updated_logs ) . to eq ( 0 )
expect ( updated_logs ) . to eq ( 0 )
end
end
it " does not import the log if a duplicate log exists on the system (that was not migrated from old CORE) " do
expect ( logger ) . not_to receive ( :error )
expect ( logger ) . not_to receive ( :warn )
expect ( logger ) . not_to receive ( :info ) . with ( / Updating sales log / )
expect ( logger ) . to receive ( :info ) . with ( / Duplicate log with id \ d+ found for log shared_ownership_sales_log, skipping log / )
expect ( logger ) . to receive ( :info ) . with ( / Duplicate log with id \ d+ found for log shared_ownership_sales_log2, skipping log / )
expect ( logger ) . to receive ( :info ) . with ( / Duplicate log with id \ d+ found for log outright_sale_sales_log, skipping log / )
expect ( logger ) . to receive ( :info ) . with ( / Duplicate log with id \ d+ found for log discounted_ownership_sales_log, skipping log / )
sales_log_service . create_logs ( remote_folder )
expect ( SalesLog . count ) . to eq ( 4 )
SalesLog . update_all ( old_id : nil )
sales_log_service . create_logs ( remote_folder )
expect ( SalesLog . count ) . to eq ( 4 )
end
it " imports the log if a duplicate imported log exists on the system (with different legacy ID) " do
expect ( logger ) . not_to receive ( :error )
expect ( logger ) . not_to receive ( :warn )
expect ( logger ) . not_to receive ( :info ) . with ( / Updating sales log / )
sales_log_service . create_logs ( remote_folder )
expect ( SalesLog . count ) . to eq ( 4 )
SalesLog . all . each { | log | log . update ( old_id : " old_id_ #{ rand ( 1 .. 999_999 ) } " ) }
sales_log_service . create_logs ( remote_folder )
expect ( SalesLog . count ) . to eq ( 8 )
end
context " with updates allowed " do
context " with updates allowed " do
subject ( :sales_log_service ) { described_class . new ( storage_service , logger , allow_updates : true ) }
subject ( :sales_log_service ) { described_class . new ( storage_service , logger , allow_updates : true ) }