Let people choose which payment methods are available to customers on order cycles

This commit is contained in:
Cillian O'Ruanaidh
2022-10-07 17:14:11 +01:00
parent 5718f9f00c
commit 4e6d64c0a1
18 changed files with 789 additions and 340 deletions

View File

@@ -22,6 +22,8 @@ describe '
let!(:distributor) {
create(:distributor_enterprise, name: 'My distributor', with_payment_and_shipping: true)
}
let!(:payment_method_i) { distributor.payment_methods.first }
let!(:payment_method_ii) { create(:payment_method, distributors: [distributor]) }
let!(:shipping_method_i) { distributor.shipping_methods.first }
let!(:shipping_method_ii) { create(:shipping_method, distributors: [distributor]) }
let(:oc) { OrderCycle.last }
@@ -44,6 +46,7 @@ describe '
shipping_method_i.update!(name: "Pickup - always available")
shipping_method_ii.update!(name: "Delivery - sometimes available")
payment_method_ii.update!(name: "Cash")
end
it "creating an order cycle with full interface", js: true do
@@ -68,6 +71,8 @@ describe '
add_supplier_with_fees
add_distributor_with_fees
select_distributor_shipping_methods
select_distributor_payment_methods
click_button 'Save and Back to List'
expect_all_data_saved
end
@@ -161,22 +166,50 @@ describe '
click_button 'Save and Next'
end
def select_distributor_payment_methods
within("tr.distributor-#{distributor.id}-payment-methods") do
expect(page).to have_checked_field "Select all"
expect(page).to have_checked_field "Check"
expect(page).to have_checked_field "Cash"
uncheck "Cash"
expect(page).to have_unchecked_field "Select all"
expect_checking_select_all_payment_methods_works
expect_unchecking_select_all_payment_methods_works
# Our final selection:
check "Check"
end
end
def select_distributor_shipping_methods
expect(page).to have_checked_field "Select all"
within("tr.distributor-#{distributor.id}-shipping-methods") do
expect(page).to have_checked_field "Select all"
expect(page).to have_checked_field "Pickup - always available"
expect(page).to have_checked_field "Delivery - sometimes available"
expect(page).to have_checked_field "Pickup - always available"
expect(page).to have_checked_field "Delivery - sometimes available"
uncheck "Delivery - sometimes available"
uncheck "Delivery - sometimes available"
expect(page).to have_unchecked_field "Select all"
expect(page).to have_unchecked_field "Select all"
expect_checking_select_all_shipping_methods_works
expect_unchecking_select_all_shipping_methods_works
expect_checking_select_all_shipping_methods_works
expect_unchecking_select_all_shipping_methods_works
# Our final selection:
check "Pickup - always available"
click_button 'Save and Back to List'
# Our final selection:
check "Pickup - always available"
end
end
def expect_checking_select_all_payment_methods_works
# Now test that the "Select all" input is doing what it's supposed to:
check "Select all"
expect(page).to have_checked_field "Check"
expect(page).to have_checked_field "Cash"
end
def expect_checking_select_all_shipping_methods_works
@@ -187,6 +220,13 @@ describe '
expect(page).to have_checked_field "Delivery - sometimes available"
end
def expect_unchecking_select_all_payment_methods_works
uncheck "Select all"
expect(page).to have_unchecked_field "Check"
expect(page).to have_unchecked_field "Cash"
end
def expect_unchecking_select_all_shipping_methods_works
uncheck "Select all"
@@ -208,6 +248,7 @@ describe '
expect_receival_instructions_saved
expect_pickup_time_and_instructions_saved
expect_distributor_shipping_methods_saved
expect_distributor_payment_methods_saved
end
def expect_opening_and_closing_times_saved
@@ -240,6 +281,10 @@ describe '
expect(exchange.tag_list).to eq(['wholesale'])
end
def expect_distributor_payment_methods_saved
expect(oc.distributor_payment_methods).to eq(payment_method_i.distributor_payment_methods)
end
def expect_distributor_shipping_methods_saved
expect(oc.distributor_shipping_methods).to eq(shipping_method_i.distributor_shipping_methods)
end

View File

@@ -272,6 +272,8 @@ describe '
expect_shipping_methods_to_be_checked_for(distributor_managed)
expect_shipping_methods_to_be_checked_for(distributor_permitted)
expect_payment_methods_to_be_checked_for(distributor_managed)
expect_payment_methods_to_be_checked_for(distributor_permitted)
click_button 'Save and Back to List'
order_cycle = OrderCycle.find_by(name: 'My order cycle')
@@ -286,6 +288,9 @@ describe '
expect(order_cycle.distributor_shipping_methods).to match_array(
order_cycle.attachable_distributor_shipping_methods
)
expect(order_cycle.distributor_payment_methods).to match_array(
order_cycle.attachable_distributor_payment_methods
)
end
context "editing an order cycle" do
@@ -724,6 +729,14 @@ describe '
private
def expect_payment_methods_to_be_checked_for(distributor)
distributor.distributor_payment_method_ids.each do |distributor_payment_method_id|
expect(page).to have_checked_field(
"order_cycle_selected_distributor_payment_method_ids_#{distributor_payment_method_id}"
)
end
end
def expect_shipping_methods_to_be_checked_for(distributor)
distributor.distributor_shipping_method_ids.each do |distributor_shipping_method_id|
expect(page).to have_checked_field(