Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show errors on admin shipment line item destroy failure #2892

Merged
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
7 changes: 6 additions & 1 deletion backend/app/assets/javascripts/spree/backend/shipments.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ adjustShipmentItems = function(shipment_number, variant_id, quantity){
window.location.reload();
},
error: function(response) {
window.show_flash('error', response.responseJSON.message);
json = response.responseJSON;
message = json.error;
for (error in json.errors) {
message += '<br />' + json.errors[error].join();
}
window.show_flash('error', message);
}
});
}
Expand Down
28 changes: 28 additions & 0 deletions backend/spec/features/admin/orders/shipments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,34 @@ def ship_shipment
end
end

context "destroying a shipment", js: true do
before do
visit spree.admin_path
click_link "Orders"
within_row(1) do
click_link "R100"
end
end

context "when the line item cannot be found" do
it "shows the proper error message" do
expect(page).to have_selector '.delete-item'
order.shipments.first.line_items.each(&:destroy)
accept_alert { first('.delete-item').click }
expect(page).to have_content 'The resource you were looking for could not be found.'
end
end

context "when the shipment has already been shipped" do
it "shows the proper error message" do
expect(page).to have_selector '.delete-item'
order.shipments.first.ship!
accept_alert { first('.delete-item').click }
expect(page).to have_content 'Cannot remove items from a shipped shipment'
end
end
end

context "moving variants between shipments", js: true do
let!(:order) { create(:completed_order_with_pending_payment, number: "R100", state: "complete", line_items_count: 5) }
let!(:la) { create(:stock_location, name: "LA") }
Expand Down