diff --git a/app/services/bulk_upload/lettings/log_creator.rb b/app/services/bulk_upload/lettings/log_creator.rb index 089639d4f..edbf28031 100644 --- a/app/services/bulk_upload/lettings/log_creator.rb +++ b/app/services/bulk_upload/lettings/log_creator.rb @@ -21,6 +21,8 @@ class BulkUpload::Lettings::LogCreator Sentry.capture_exception(e) end end + + bulk_upload.update!(processed: true) end private diff --git a/db/migrate/20230322112117_add_processed_to_bulk_uploads.rb b/db/migrate/20230322112117_add_processed_to_bulk_uploads.rb new file mode 100644 index 000000000..698b31f1e --- /dev/null +++ b/db/migrate/20230322112117_add_processed_to_bulk_uploads.rb @@ -0,0 +1,5 @@ +class AddProcessedToBulkUploads < ActiveRecord::Migration[7.0] + def change + add_column :bulk_uploads, :processed, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 463d7da59..0c3420217 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_03_20_163945) do +ActiveRecord::Schema[7.0].define(version: 2023_03_22_112117) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -40,6 +40,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_20_163945) do t.text "filename" t.integer "needstype" t.integer "expected_log_count" + t.boolean "processed", default: false t.index ["identifier"], name: "index_bulk_uploads_on_identifier", unique: true t.index ["user_id"], name: "index_bulk_uploads_on_user_id" end diff --git a/spec/services/bulk_upload/lettings/log_creator_spec.rb b/spec/services/bulk_upload/lettings/log_creator_spec.rb index 8b320c35f..f6655d956 100644 --- a/spec/services/bulk_upload/lettings/log_creator_spec.rb +++ b/spec/services/bulk_upload/lettings/log_creator_spec.rb @@ -22,6 +22,10 @@ RSpec.describe BulkUpload::Lettings::LogCreator do expect(log.bulk_upload).to eql(bulk_upload) expect(bulk_upload.lettings_logs).to include(log) end + + it "marks bulk upload as processed" do + expect { service.call }.to change(bulk_upload, :processed?).from(false).to(true) + end end context "when a valid csv with several blank rows" do diff --git a/spec/services/bulk_upload/processor_spec.rb b/spec/services/bulk_upload/processor_spec.rb index 2254e1b75..edd049cd8 100644 --- a/spec/services/bulk_upload/processor_spec.rb +++ b/spec/services/bulk_upload/processor_spec.rb @@ -179,65 +179,6 @@ RSpec.describe BulkUpload::Processor do 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, - any_setup_errors?: false, - 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 - - it "deletes the local file afterwards" do - processor.call - - expect(mock_downloader).to have_received(:delete_local_file!) - end - - it "sends correct and upload again mail" do - mail_double = instance_double("ActionMailer::MessageDelivery", deliver_later: nil) - - allow(BulkUploadMailer).to receive(:send_correct_and_upload_again_mail).and_return(mail_double) - - processor.call - - expect(BulkUploadMailer).to have_received(:send_correct_and_upload_again_mail) - expect(mail_double).to have_received(:deliver_later) - 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 - 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 with perfect data" do let(:path) { file_fixture("2022_23_lettings_bulk_upload.csv") }