@ -91,7 +91,7 @@ RSpec.describe BulkUpload::Processor do
end
end
end
end
context " when processing a bulk upload with errors " do
context " when processing a bulk upload with errors but below threshold (therefore creates logs) " do
let ( :mock_downloader ) do
let ( :mock_downloader ) do
instance_double (
instance_double (
BulkUpload :: Downloader ,
BulkUpload :: Downloader ,
@ -101,12 +101,68 @@ RSpec.describe BulkUpload::Processor do
)
)
end
end
let ( :mock_validator ) do
instance_double (
BulkUpload :: Lettings :: Validator ,
invalid? : false ,
call : nil ,
create_logs? : true ,
)
end
before do
before do
allow ( BulkUpload :: Downloader ) . to receive ( :new ) . with ( bulk_upload : ) . and_return ( mock_downloader )
allow ( BulkUpload :: Downloader ) . to receive ( :new ) . with ( bulk_upload : ) . and_return ( mock_downloader )
allow ( BulkUpload :: Lettings :: Validator ) . to receive ( :new ) . and_return ( mock_validator )
end
it " deletes the local file afterwards " do
processor . call
expect ( mock_downloader ) . to have_received ( :delete_local_file! )
end
end
it " persist the validation errors " do
it " sends fix errors email " do
expect { processor . call } . to change ( BulkUploadError , :count )
mail_double = instance_double ( " ActionMailer::MessageDelivery " , deliver_later : nil )
allow ( BulkUploadMailer ) . to receive ( :send_bulk_upload_with_errors_mail ) . and_return ( mail_double )
processor . call
expect ( BulkUploadMailer ) . to have_received ( :send_bulk_upload_with_errors_mail )
expect ( mail_double ) . to have_received ( :deliver_later )
end
it " does not send success email " do
allow ( BulkUploadMailer ) . to receive ( :send_bulk_upload_complete_mail ) . and_call_original
processor . call
expect ( BulkUploadMailer ) . not_to have_received ( :send_bulk_upload_complete_mail )
end
end
context " when processing a bulk upload with errors but above threshold (therefore does not create logs) " do
let ( :mock_downloader ) do
instance_double (
BulkUpload :: Downloader ,
call : nil ,
path : file_fixture ( " 2022_23_lettings_bulk_upload.csv " ) ,
delete_local_file! : nil ,
)
end
let ( :mock_validator ) do
instance_double (
BulkUpload :: Lettings :: Validator ,
invalid? : false ,
call : nil ,
create_logs? : false ,
)
end
before do
allow ( BulkUpload :: Downloader ) . to receive ( :new ) . with ( bulk_upload : ) . and_return ( mock_downloader )
allow ( BulkUpload :: Lettings :: Validator ) . to receive ( :new ) . and_return ( mock_validator )
end
end
it " deletes the local file afterwards " do
it " deletes the local file afterwards " do
@ -115,6 +171,14 @@ RSpec.describe BulkUpload::Processor do
expect ( mock_downloader ) . to have_received ( :delete_local_file! )
expect ( mock_downloader ) . to have_received ( :delete_local_file! )
end
end
it " does not send fix errors email " do
allow ( BulkUploadMailer ) . to receive ( :send_bulk_upload_with_errors_mail ) . and_call_original
processor . call
expect ( BulkUploadMailer ) . not_to have_received ( :send_bulk_upload_with_errors_mail )
end
it " does not send success email " do
it " does not send success email " do
allow ( BulkUploadMailer ) . to receive ( :send_bulk_upload_complete_mail ) . and_call_original
allow ( BulkUploadMailer ) . to receive ( :send_bulk_upload_complete_mail ) . and_call_original
@ -165,6 +229,14 @@ RSpec.describe BulkUpload::Processor do
expect ( mock_creator ) . to have_received ( :call )
expect ( mock_creator ) . to have_received ( :call )
end
end
it " does not send fix errors email " do
allow ( BulkUploadMailer ) . to receive ( :send_bulk_upload_with_errors_mail ) . and_call_original
processor . call
expect ( BulkUploadMailer ) . not_to have_received ( :send_bulk_upload_with_errors_mail )
end
it " sends success email " do
it " sends success email " do
mail_double = instance_double ( " ActionMailer::MessageDelivery " , deliver_later : nil )
mail_double = instance_double ( " ActionMailer::MessageDelivery " , deliver_later : nil )