@ -5,7 +5,7 @@ RSpec.describe BulkUploadMailer do
let ( :notify_client ) { instance_double ( Notifications :: Client ) }
let ( :user ) { create ( :user , email : " user@example.com " ) }
let ( :bulk_upload ) { build ( :bulk_upload , :lettings , user : ) }
let ( :bulk_upload ) { create ( :bulk_upload , :lettings , user : ) }
before do
allow ( Notifications :: Client ) . to receive ( :new ) . and_return ( notify_client )
@ -75,4 +75,56 @@ RSpec.describe BulkUploadMailer do
end
end
end
describe " # send_correct_and_upload_again_mail " do
context " when 2 columns with errors " do
before do
create ( :bulk_upload_error , bulk_upload : , col : " A " )
create ( :bulk_upload_error , bulk_upload : , col : " B " )
end
it " sends correctly formed email with A, B " do
expect ( notify_client ) . to receive ( :send_email ) . with (
email_address : user . email ,
template_id : described_class :: BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID ,
personalisation : {
filename : bulk_upload . filename ,
upload_timestamp : bulk_upload . created_at . to_fs ( :govuk_date_and_time ) ,
year_combo : bulk_upload . year_combo ,
lettings_or_sales : bulk_upload . log_type ,
error_description : " We noticed that you have a lot of similar errors in column A, B. Please correct your data export and upload again. " ,
summary_report_link : " http://localhost:3000/lettings-logs/bulk-upload-results/ #{ bulk_upload . id } /summary " ,
} ,
)
mailer . send_correct_and_upload_again_mail ( bulk_upload : )
end
end
context " when 4 columns with errors " do
before do
create ( :bulk_upload_error , bulk_upload : , col : " A " )
create ( :bulk_upload_error , bulk_upload : , col : " B " )
create ( :bulk_upload_error , bulk_upload : , col : " C " )
create ( :bulk_upload_error , bulk_upload : , col : " D " )
end
it " sends correctly formed email with A, B, C and more " do
expect ( notify_client ) . to receive ( :send_email ) . with (
email_address : user . email ,
template_id : described_class :: BULK_UPLOAD_FAILED_CSV_ERRORS_TEMPLATE_ID ,
personalisation : {
filename : bulk_upload . filename ,
upload_timestamp : bulk_upload . created_at . to_fs ( :govuk_date_and_time ) ,
year_combo : bulk_upload . year_combo ,
lettings_or_sales : bulk_upload . log_type ,
error_description : " We noticed that you have a lot of similar errors in column A, B, C and more. Please correct your data export and upload again. " ,
summary_report_link : " http://localhost:3000/lettings-logs/bulk-upload-results/ #{ bulk_upload . id } /summary " ,
} ,
)
mailer . send_correct_and_upload_again_mail ( bulk_upload : )
end
end
end
end