Tests shipping methods filtering

This commit is contained in:
filipefurtad0
2023-01-19 17:33:57 +00:00
parent f7d4d7595c
commit 336210b898
2 changed files with 50 additions and 28 deletions

View File

@@ -3577,6 +3577,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
server_error: "Server error"
shipping_method_names:
UPS Ground: "UPS Ground"
pick_up: "Pick-up at the farm"
delivery: "Signed, sealed, delivered"
start_date: "Start date"
successfully_removed: "Successfully Removed"
taxonomy_edit: "Taxonomy edit"

View File

@@ -11,22 +11,24 @@ describe '
let(:owner) { create(:user) }
let(:owner2) { create(:user) }
let(:billing_address) { create(:address, :randomized) }
let(:billing_address2) { create(:address, :randomized) }
let(:billing_address3) { create(:address, :randomized) }
let(:billing_address4) { create(:address, :randomized) }
let(:billing_address5) { create(:address, :randomized) }
let(:customer) { create(:user) }
let(:customer2) { create(:user) }
let(:customer3) { create(:user) }
let(:customer4) { create(:user) }
let(:customer5) { create(:user) }
let(:billing_address) { create(:address, :randomized) }
let(:billing_address2) { create(:address, :randomized) }
let(:billing_address3) { create(:address, :randomized) }
let(:billing_address4) { create(:address, :randomized) }
let(:billing_address5) { create(:address, :randomized) }
let(:product) { create(:simple_product) }
let(:distributor) { create(:distributor_enterprise, owner: owner, charges_sales_tax: true) }
let(:distributor2) { create(:distributor_enterprise, owner: owner, charges_sales_tax: true) }
let(:distributor3) { create(:distributor_enterprise, owner: owner, charges_sales_tax: true) }
let(:distributor4) { create(:distributor_enterprise, owner: owner, charges_sales_tax: true) }
let(:distributor) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor2) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor3) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor4) { create(:distributor_enterprise, owner: owner, with_payment_and_shipping: true, charges_sales_tax: true) }
let(:distributor5) { create(:distributor_enterprise, owner: owner2, charges_sales_tax: true) }
let!(:shipping_method) { create(:shipping_method_with, :pickup, name: "pick_up", distributors: [distributor, distributor2, distributor3]) }
let!(:shipping_method2) { create(:shipping_method_with, :pickup, name: "delivery", distributors: [distributor4, distributor5]) }
let(:order_cycle) do
create(:simple_order_cycle, name: 'One', distributors: [distributor, distributor2, distributor3, distributor4],
variants: [product.variants.first])
@@ -34,11 +36,10 @@ describe '
context "with a complete order" do
let(:order) do
create(:order_with_totals_and_distribution, user: customer, distributor: distributor,
create(:order_with_totals_and_distribution, user: owner, user: customer, distributor: distributor,
order_cycle: order_cycle,
state: 'complete', payment_state: 'balance_due',
bill_address_id: billing_address.id
)
bill_address_id: billing_address.id)
end
let!(:order_cycle2) {
@@ -51,12 +52,12 @@ describe '
create(:simple_order_cycle, name: 'Four', orders_close_at: 4.weeks.from_now)
}
let!(:order_cycle5) do
create(:simple_order_cycle, name: 'Five', distributors: [distributor5],
create(:simple_order_cycle, name: 'Five', coordinator: distributor5, distributors: [distributor5],
variants: [product.variants.first])
end
let!(:order2) {
create(:order_with_credit_payment, user: customer2, distributor: distributor2,
create(:order_with_credit_payment, user: customer2,distributor: distributor2,
order_cycle: order_cycle2, completed_at: 2.days.ago,
bill_address_id: billing_address2.id)
}
@@ -66,18 +67,20 @@ describe '
bill_address_id: billing_address3.id)
}
let!(:order4) {
create(:order_with_credit_payment, user: customer4, distributor: distributor4,
create(:order_with_credit_payment, user: customer4,distributor: distributor4,
order_cycle: order_cycle4,
bill_address_id: billing_address4.id)
}
let!(:order5) {
create(:order_with_credit_payment, user: customer5, distributor: distributor5,
create(:order_with_credit_payment, user: customer5,distributor: distributor5,
order_cycle: order_cycle5,
bill_address_id: billing_address5.id)
)
}
context "logging as superadmin and visiting the orders page" do
before do
order2.select_shipping_method(shipping_method.id)
order4.select_shipping_method(shipping_method2.id)
login_as_admin_and_visit 'admin/orders'
end
@@ -150,7 +153,25 @@ describe '
fill_in "Last name begins with", with: billing_address4.lastname
page.find('.filter-actions .button.icon-search').click
# Order 3 should show, but not 2 and 4
# Order 4 should show, but not 2 and 3
expect(page).to_not have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
end
it "filter by shipping methods" do
select2_select "Pick-up at the farm", from: 'q_shipping_method_id'
page.find('.filter-actions .button.icon-search').click
# Order 2 should show, but not 3 and 5
expect(page).to have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to_not have_content order4.number
find("a#clear_filters_button").click
select2_select "Signed, sealed, delivered", from: 'q_shipping_method_id'
page.find('.filter-actions .button.icon-search').click
# Order 4 should show, but not 2 and 3
expect(page).to_not have_content order2.number
expect(page).to_not have_content order3.number
expect(page).to have_content order4.number
@@ -201,29 +222,28 @@ describe '
expect(page).to have_content "Confirmation emails sent for 2 orders."
end
context "for a hub manager" do
before do
login_to_admin_as owner
login_to_admin_as owner2
visit spree.admin_orders_path
end
it "displays the orders for the respective distributor" do
expect(page).not_to have_content order.number # does not display incomplete orders by default
expect(page).to have_content order2.number
expect(page).to have_content order3.number
expect(page).to have_content order4.number
expect(page).not_to have_content order5.number # does not display orders from other distributors
expect(page).to have_content order5.number # displays the only order for distributor5
expect(page).not_to have_content order.number
expect(page).not_to have_content order2.number
expect(page).not_to have_content order3.number
expect(page).not_to have_content order4.number
end
it "cannot send emails to orders if permission have been revoked in the meantime" do
page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click
# Find the clicked order
order = Spree::Order.find_by(id: page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").value)
# Revoke permission for the current user on that specific order by changing its owners
order.update_attribute(:created_by, create(:user))
order.update_attribute(:distributor, create(:distributor_enterprise))
order.update_attribute(:distributor, distributor)
order.update_attribute(:order_cycle, order_cycle)
page.find("span.icon-reorder", text: "ACTIONS").click
within ".ofn-drop-down-with-prepend .menu" do