Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/controllers/order_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def error_report
private

def create_params
params.require(:order_import).permit(:upload_file, :fail_on_error, :send_receipts)
attributes = [:upload_file, :send_receipts]

if SettingsHelper.feature_off?("orders.import_always_fail_on_error")
attributes << :fail_on_error
end

params.require(:order_import).permit(*attributes)
end

def create_order_import!
Expand Down
5 changes: 4 additions & 1 deletion app/views/order_imports/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
= link_to text("download_link"), template_path, id: "bulk-import-template"
= f.file_field :upload_file
= html("upload_file_hint")
= f.input :fail_on_error, inline_label: text("fail_on_error"), label: false, hint: html("fail_on_error_hint")
- if SettingsHelper.feature_on?("orders.import_always_fail_on_error")
%p= text("always_fail_on_error_hint")
- else
= f.input :fail_on_error, inline_label: text("fail_on_error"), label: false, hint: html("fail_on_error_hint")
= f.input :send_receipts, inline_label: text("send_receipts"), label: false, hint: text("send_receipts_hint")
%label
= text("send_report_to")
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/admin/en.order_imports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ en:
fail_on_error_hint:
<p>When checked, an error on any row will halt the import process, allowing you to correct the file and try again.</p>
<p>Un-check to import valid entries and return any failed entries in a CSV file for review.</p>
always_fail_on_error_hint: An error on any row will halt the import process, allowing you to correct the file and try again.
send_receipts_hint:
<p>Check this box to send receipts. By default receipts are NOT sent to customers for bulk imported orders.</p>
history:
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ feature:
print_order_detail: false
# results_file_notifications requires my_files to be on as well
results_file_notifications: true
import_always_fail_on_error: false

reservations:
accessory_independent_order_status: false
Expand Down
32 changes: 23 additions & 9 deletions spec/controllers/order_imports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
require "rails_helper"
require "controller_spec_helper"

def fixture_file(filename)
Rack::Test::UploadedFile.new(
"#{Rails.root}/spec/files/order_imports/#{filename}",
"text/csv",
)
end

RSpec.describe OrderImportsController do
let(:facility) { create(:facility) }

Expand Down Expand Up @@ -55,7 +48,7 @@ def fixture_file(filename)
before { sign_in user }

context "on success" do
let(:upload_file) { fixture_file("blank.csv") }
let(:upload_file) { fixture_file_upload("order_imports/blank.csv", "text/csv") }

it "creates an order import" do
expect { do_request }.to(
Expand Down Expand Up @@ -97,7 +90,7 @@ def fixture_file(filename)
end

context "when the file is blank" do
let(:upload_file) { fixture_file("blank.csv") }
let(:upload_file) { fixture_file_upload("order_imports/blank.csv", "text/csv") }
let(:fail_on_error) { false }
let(:send_receipts) { false }

Expand All @@ -119,6 +112,27 @@ def fixture_file(filename)
end
end
end

context(
"when always_fail_on_error is true",
feature_setting: { "orders.import_always_fail_on_error" => true },
) do
let(:fail_on_error) { false }
let(:upload_file) do
fixture_file_upload("order_imports/blank.csv", "text/csv")
end
let(:send_receipts) { ["receipt@example.com"] }

before do
sign_in create(:user, :administrator)
end

it "ignores fail on error param and saves it to true" do
expect { do_request }.to(
change(OrderImport.where(fail_on_error: true), :count).by(1)
)
end
end
end

describe "downloading an error file" do
Expand Down
3 changes: 0 additions & 3 deletions spec/files/order_imports/first_od_error.csv

This file was deleted.

3 changes: 0 additions & 3 deletions spec/files/order_imports/second_od_error.csv

This file was deleted.

Loading