Skip to content

Commit

Permalink
[#162225] Multi-Facility - Duplicates being created (#4189)
Browse files Browse the repository at this point in the history
* Fix bug and add spe

* Solve one accessibility problem

* Improve code

* Fix bug

* Use elsif
  • Loading branch information
LeticiaErrandonea authored and diebas committed Dec 5, 2024
1 parent 50ff2d0 commit cbb1557
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
14 changes: 6 additions & 8 deletions app/forms/add_to_order_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ def save

if @original_order.facility.id == @facility_id
add_to_order!
end

return true unless SettingsHelper.feature_on?(:cross_core_projects)

if order_for_selected_facility.nil?
create_cross_core_project_and_add_order!
else
add_to_order!
elsif SettingsHelper.feature_on?(:cross_core_projects)
if order_for_selected_facility.nil?
create_cross_core_project_and_add_order!
else
add_to_order!
end
end

true
Expand Down
4 changes: 2 additions & 2 deletions app/views/facility_orders/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
- if project_id
%dl.span2
%dt= t("views.facility_orders.show.cross_core_project_id")
= link_to facility_project_path(current_facility, project_id) do
%dd= project_id
%dd
= link_to project_id, facility_project_path(current_facility, project_id)
%dl.span2
%dt= t("views.facility_orders.show.cross_core_project_total")
- gross_order_value = @order.total + @cross_core_orders_by_facility.values.sum(&:total)
Expand Down
31 changes: 31 additions & 0 deletions spec/system/admin/adding_to_an_order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,37 @@
end
end

describe "from same facility (with feature flag on)", :js, feature_setting: { cross_core_projects: true } do
let(:product) { create(:setup_item, :with_facility_account) }
let!(:instrument) { create(:setup_instrument, facility: facility) }
let(:user) { create(:user, :facility_administrator, facility:) }

before do
visit facility_order_path(facility, order)
fill_in "add_to_order_form[quantity]", with: "1"
select_from_chosen instrument.name, from: "add_to_order_form[product_id]"
click_button "Add To Order"
end

it "requires a reservation to be set up before adding to the order" do
expect(page).to have_content("The following order details need your attention.")

click_link "Make a Reservation"
click_button "Create"

expect(order.reload.order_details.count).to be(2)
expect(order.order_details.last.product).to eq(instrument)
end

it "brings you back to the facility order path on 'Cancel'" do
click_link "Make a Reservation"
click_link "Cancel"

expect(current_path).to eq(facility_order_path(facility, order))
expect(page).to have_link("Make a Reservation")
end
end

describe "from another facility", :js, feature_setting: { cross_core_projects: true } do
let(:facility2) { create(:setup_facility) }
let(:product) { create(:setup_item, :with_facility_account) }
Expand Down

0 comments on commit cbb1557

Please sign in to comment.