From 9757ab2a6c7ed00a402452097bba43b89e4ab00c Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 16 Jan 2023 12:25:35 +0000 Subject: [PATCH 1/9] Creates customers and enterprise owners (users) Fixes typo and removes unecessary js: true line --- spec/system/admin/orders_spec.rb | 45 +++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index ce4795b9ae..29c05ab686 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -9,12 +9,19 @@ describe ' include AuthenticationHelper include WebHelper - let(:user) { create(:user) } + let(:owner) { create(:user) } + let(:owner2) { create(:user) } + let(:customer) { create(:user) } + let(:customer2) { create(:user) } + let(:customer3) { create(:user) } + let(:customer4) { create(:user) } + let(:customer5) { create(:user) } let(:product) { create(:simple_product) } - let(:distributor) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) } - let(:distributor2) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) } - let(:distributor3) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) } - let(:distributor4) { create(:distributor_enterprise, owner: user, charges_sales_tax: true) } + 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(:distributor5) { create(:distributor_enterprise, owner: owner2, charges_sales_tax: true) } let(:order_cycle) do create(:simple_order_cycle, name: 'One', distributors: [distributor, distributor2, distributor3, distributor4], variants: [product.variants.first]) @@ -22,7 +29,7 @@ describe ' context "with a complete order" do let(:order) do - create(:order_with_totals_and_distribution, user: user, distributor: distributor, + create(:order_with_totals_and_distribution, user: customer, distributor: distributor, order_cycle: order_cycle, state: 'complete', payment_state: 'balance_due') end @@ -36,19 +43,27 @@ describe ' let!(:order_cycle4) { 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], + variants: [product.variants.first]) + end let!(:order2) { - create(:order_with_credit_payment, user: user, distributor: distributor2, + create(:order_with_credit_payment, user: customer2, distributor: distributor2, order_cycle: order_cycle2, completed_at: 2.days.ago) } let!(:order3) { - create(:order_with_credit_payment, user: user, distributor: distributor3, + create(:order_with_credit_payment, user: customer3, distributor: distributor3, order_cycle: order_cycle3) } let!(:order4) { - create(:order_with_credit_payment, user: user, distributor: distributor4, + create(:order_with_credit_payment, user: customer4, distributor: distributor4, order_cycle: order_cycle4) } + let!(:order5) { + create(:order_with_credit_payment, user: customer5, distributor: distributor5, + order_cycle: order_cycle5) + } it "order cycles appear in descending order by close date on orders page" do login_as_admin_and_visit 'admin/orders' @@ -56,7 +71,7 @@ describe ' open_select2('#s2id_q_order_cycle_id_in') expect(find('#q_order_cycle_id_in', - visible: :all)[:innerHTML]).to have_content(/.*Four.*Three.*Two/m) + visible: :all)[:innerHTML]).to have_content(/.*Four.*Three.*Two.*Five/m) end it "filter by multiple order cycles" do @@ -148,11 +163,11 @@ describe ' context "for a hub manager" do before do - login_to_admin_as user + login_to_admin_as owner visit spree.admin_orders_path end - it "cannnot send emails to orders if permission have been revoked in the meantime" do + 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 @@ -237,7 +252,7 @@ describe ' :order_with_line_items, distributor: distributor, order_cycle: order_cycle, - user: user, + user: customer, state: 'complete', payment_state: 'balance_due', completed_at: 1.day.ago, @@ -248,7 +263,7 @@ describe ' :order_with_line_items, distributor: distributor, order_cycle: order_cycle, - user: user, + user: customer, state: 'complete', payment_state: 'balance_due', completed_at: 1.day.ago, @@ -272,7 +287,7 @@ describe ' end end - context "save the filter params", js: true do + context "save the filter params" do let!(:shipping_method) { create(:shipping_method, name: "UPS Ground") } let!(:user) { create(:user, email: 'an@email.com') } let!(:order) do From 6f35b38fa8bedca36239ffb9b95310844b641ff3 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 16 Jan 2023 14:13:53 +0000 Subject: [PATCH 2/9] Asserts on the correct display of orders (for a given distributor) --- spec/system/admin/orders_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 29c05ab686..0f002cc6a7 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -167,6 +167,14 @@ describe ' 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 + 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 From 28782775ad017f1a4ee39217226f08930446be4f Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 16 Jan 2023 14:38:41 +0000 Subject: [PATCH 3/9] adds filter by Email assertion --- spec/system/admin/orders_spec.rb | 81 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 0f002cc6a7..7ac5c1c73b 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -65,60 +65,69 @@ describe ' order_cycle: order_cycle5) } - it "order cycles appear in descending order by close date on orders page" do - login_as_admin_and_visit 'admin/orders' + context "logging as superadmin and visiting the orders page" do + before do + login_as_admin_and_visit 'admin/orders' + end - open_select2('#s2id_q_order_cycle_id_in') + it "order cycles appear in descending order by close date on orders page" do + open_select2('#s2id_q_order_cycle_id_in') - expect(find('#q_order_cycle_id_in', - visible: :all)[:innerHTML]).to have_content(/.*Four.*Three.*Two.*Five/m) - end + expect(find('#q_order_cycle_id_in', + visible: :all)[:innerHTML]).to have_content(/.*Four.*Three.*Two.*Five/m) + end - it "filter by multiple order cycles" do - login_as_admin_and_visit 'admin/orders' + it "filter by multiple order cycles" do + select2_select 'Two', from: 'q_order_cycle_id_in' + select2_select 'Three', from: 'q_order_cycle_id_in' - select2_select 'Two', from: 'q_order_cycle_id_in' - select2_select 'Three', from: 'q_order_cycle_id_in' + page.find('.filter-actions .button.icon-search').click - page.find('.filter-actions .button.icon-search').click + # Order 2 and 3 should show, but not 4 + expect(page).to have_content order2.number + expect(page).to have_content order3.number + expect(page).to_not have_content order4.number + end - # Order 2 and 3 should show, but not 4 - expect(page).to have_content order2.number - expect(page).to have_content order3.number - expect(page).to_not have_content order4.number - end + it "filter by distributors" do + select2_select distributor2.name.to_s, from: 'q_distributor_id_in' + select2_select distributor4.name.to_s, from: 'q_distributor_id_in' - it "filter by distributors" do - login_as_admin_and_visit 'admin/orders' + page.find('.filter-actions .button.icon-search').click - select2_select distributor2.name.to_s, from: 'q_distributor_id_in' - select2_select distributor4.name.to_s, from: 'q_distributor_id_in' + # Order 2 and 4 should show, but not 3 + expect(page).to have_content order2.number + expect(page).to_not have_content order3.number + expect(page).to have_content order4.number + end - page.find('.filter-actions .button.icon-search').click + it "filter by complete date" do + find("input.datepicker").click + select_dates_from_daterangepicker(order3.completed_at.yesterday, order4.completed_at.tomorrow) - # Order 2 and 4 should show, but not 3 - expect(page).to have_content order2.number - expect(page).to_not have_content order3.number - expect(page).to have_content order4.number - end + page.find('.filter-actions .button.icon-search').click - it "filter by complete date" do - login_as_admin_and_visit 'admin/orders' + # Order 3 and 4 should show, but not 2 + expect(page).to_not have_content order2.number + expect(page).to have_content order3.number + expect(page).to have_content order4.number + end - find("input.datepicker").click - select_dates_from_daterangepicker(order3.completed_at.yesterday, order4.completed_at.tomorrow) + it "filter by email" do + fill_in "Email", with: customer3.email - page.find('.filter-actions .button.icon-search').click + page.find('.filter-actions .button.icon-search').click - # Order 3 and 4 should show, but not 2 - expect(page).to_not have_content order2.number - expect(page).to have_content order3.number - expect(page).to have_content order4.number + # Order 3 should show, but not 2 and 4 + expect(page).to_not have_content order2.number + expect(page).to have_content order3.number + expect(page).to_not have_content order4.number + end end context "select/unselect all orders" do before do - login_as_admin_and_visit spree.admin_orders_path + login_as_admin_and_visit 'admin/orders' end it "by clicking on the checkbox in the table header" do From f7d4d7595c4e9fe63ad073f82788f77c9b95b53b Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 19 Jan 2023 16:20:34 +0000 Subject: [PATCH 4/9] Filters by customer/billing address first and last names --- spec/system/admin/orders_spec.rb | 42 ++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 7ac5c1c73b..71e9e306f9 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -11,6 +11,11 @@ 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) } @@ -31,7 +36,9 @@ describe ' let(:order) do create(:order_with_totals_and_distribution, user: customer, distributor: distributor, order_cycle: order_cycle, - state: 'complete', payment_state: 'balance_due') + state: 'complete', payment_state: 'balance_due', + bill_address_id: billing_address.id + ) end let!(:order_cycle2) { @@ -50,19 +57,23 @@ describe ' let!(:order2) { create(:order_with_credit_payment, user: customer2, distributor: distributor2, - order_cycle: order_cycle2, completed_at: 2.days.ago) + order_cycle: order_cycle2, completed_at: 2.days.ago, + bill_address_id: billing_address2.id) } let!(:order3) { create(:order_with_credit_payment, user: customer3, distributor: distributor3, - order_cycle: order_cycle3) + order_cycle: order_cycle3, + bill_address_id: billing_address3.id) } let!(:order4) { create(:order_with_credit_payment, user: customer4, distributor: distributor4, - order_cycle: order_cycle4) + order_cycle: order_cycle4, + bill_address_id: billing_address4.id) } let!(:order5) { create(:order_with_credit_payment, user: customer5, distributor: distributor5, - order_cycle: order_cycle5) + order_cycle: order_cycle5, + bill_address_id: billing_address5.id) } context "logging as superadmin and visiting the orders page" do @@ -123,6 +134,27 @@ describe ' expect(page).to have_content order3.number expect(page).to_not have_content order4.number end + + it "filter by customer first and last names" do + # NOTE: this field refers to the name given in billing addresses and not to customer name + # filtering by first name + fill_in "First name begins with", with: billing_address2.firstname + page.find('.filter-actions .button.icon-search').click + # Order 3 should show, but not 2 and 4 + 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 + # filtering by last name + + 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 + expect(page).to_not have_content order2.number + expect(page).to_not have_content order3.number + expect(page).to have_content order4.number + end end context "select/unselect all orders" do From 336210b898f7fac44dee4edd734c68921db90897 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 19 Jan 2023 17:33:57 +0000 Subject: [PATCH 5/9] Tests shipping methods filtering --- config/locales/en.yml | 2 + spec/system/admin/orders_spec.rb | 76 ++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 28 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index 493ae5ad51..c4fdf1cd8d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 71e9e306f9..6e5542b43b 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -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 From f984cd89c2629169ede4a9c5dd7f36804c2d7ac1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 20 Jan 2023 13:14:23 +0000 Subject: [PATCH 6/9] Filters by invoice number --- spec/system/admin/orders_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 6e5542b43b..c7ab5fcf08 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -176,6 +176,17 @@ describe ' expect(page).to_not have_content order3.number expect(page).to have_content order4.number end + + it "filter by invoice number" do + fill_in "Invoice number:", with: order2.number + + page.find('.filter-actions .button.icon-search').click + + # Order 2 should show, but not 3 and 4 + expect(page).to have_content order2.number + expect(page).to_not have_content order3.number + expect(page).to_not have_content order4.number + end end context "select/unselect all orders" do From 8bfb17144cd8f2ea2dfe934ab726cc672830983b Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 20 Jan 2023 13:28:23 +0000 Subject: [PATCH 7/9] Filters by order state --- spec/system/admin/orders_spec.rb | 37 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index c7ab5fcf08..7cea44cae0 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -36,7 +36,7 @@ describe ' context "with a complete order" do let(:order) do - create(:order_with_totals_and_distribution, user: owner, user: customer, distributor: distributor, + create(:order_with_totals_and_distribution, user: customer, distributor: distributor, order_cycle: order_cycle, state: 'complete', payment_state: 'balance_due', bill_address_id: billing_address.id) @@ -57,7 +57,7 @@ describe ' 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) } @@ -67,14 +67,13 @@ 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, - order_cycle: order_cycle5, - ) + create(:order_with_credit_payment, user: customer5, distributor: distributor5, + order_cycle: order_cycle5,) } context "logging as superadmin and visiting the orders page" do @@ -187,6 +186,30 @@ describe ' expect(page).to_not have_content order3.number expect(page).to_not have_content order4.number end + + it "filter by order state" do + order.update(state: "payment") + + uncheck 'Only show complete orders' + page.find('.filter-actions .button.icon-search').click + + expect(page).to have_content order.number + expect(page).to have_content order2.number + expect(page).to have_content order3.number + expect(page).to have_content order4.number + expect(page).to have_content order5.number + + select2_select "payment", from: 'q_state_eq' + + page.find('.filter-actions .button.icon-search').click + + # Order 2 should show, but not 3 and 4 + expect(page).to have_content order.number + expect(page).to_not have_content order2.number + expect(page).to_not have_content order3.number + expect(page).to_not have_content order4.number + expect(page).to_not have_content order5.number + end end context "select/unselect all orders" do @@ -233,7 +256,7 @@ 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 owner2 From 7dc14cc35a6fce0b1e5aa0b86104a8ab245f4818 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Fri, 20 Jan 2023 18:19:38 +0000 Subject: [PATCH 8/9] Adds coverage for bulk pdf generation and order cancelling --- spec/factories/enterprise_factory.rb | 2 + spec/system/admin/orders_spec.rb | 62 +++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/spec/factories/enterprise_factory.rb b/spec/factories/enterprise_factory.rb index 73a4657dc1..d8259ecd15 100644 --- a/spec/factories/enterprise_factory.rb +++ b/spec/factories/enterprise_factory.rb @@ -61,5 +61,7 @@ FactoryBot.define do factory :distributor_enterprise_with_tax, parent: :distributor_enterprise do charges_sales_tax { true } allow_order_changes { true } + abn { "222333444" } + acn { "555666777" } end end diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 7cea44cae0..0681f5ac98 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -23,7 +23,7 @@ describe ' let(:billing_address5) { create(:address, :randomized) } let(:product) { create(:simple_product) } 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(:distributor2) { create(:distributor_enterprise_with_tax, owner: owner) } 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) } @@ -57,9 +57,9 @@ describe ' end let!(:order2) { - create(:order_with_credit_payment, user: customer2, distributor: distributor2, - order_cycle: order_cycle2, completed_at: 2.days.ago, - bill_address_id: billing_address2.id) + create(:order_ready_to_ship, user: customer2, distributor: distributor2, + order_cycle: order_cycle2, completed_at: 2.days.ago, + bill_address_id: billing_address2.id) } let!(:order3) { create(:order_with_credit_payment, user: customer3, distributor: distributor3, @@ -72,8 +72,8 @@ describe ' bill_address_id: billing_address4.id) } let!(:order5) { - create(:order_with_credit_payment, user: customer5, distributor: distributor5, - order_cycle: order_cycle5,) + create(:order_ready_to_ship, user: customer5, distributor: distributor5, + order_cycle: order_cycle5,) } context "logging as superadmin and visiting the orders page" do @@ -257,6 +257,56 @@ describe ' expect(page).to have_content "Confirmation emails sent for 2 orders." end + it "can bulk print invoices from 2 orders" do + login_as_admin_and_visit spree.admin_orders_path + + page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click + page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click + + page.find("span.icon-reorder", text: "ACTIONS").click + within ".ofn-drop-down-with-prepend .menu" do + page.find("span", text: "Print Invoices").click + end + + expect(page).to have_content "Compiling Invoices" + expect(page).to have_content "Please wait until the PDF is ready before closing this modal." + # an error 422 is generated in the console + end + + it "can bulk cancel 2 orders" do + login_as_admin_and_visit spree.admin_orders_path + + page.find("#listing_orders tbody tr:nth-child(1) input[name='order_ids[]']").click + page.find("#listing_orders tbody tr:nth-child(2) input[name='order_ids[]']").click + + page.find("span.icon-reorder", text: "ACTIONS").click + within ".ofn-drop-down-with-prepend .menu" do + page.find("span", text: "Cancel Orders").click + end + + expect(page).to have_content "Are you sure you want to proceed?" + expect(page).to have_content "This will cancel the current order." + + within "#custom-confirm.modal" do + expect { + find_button("Cancel").click # Cancels the cancel action + }.to_not enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice) + end + + page.find("span.icon-reorder", text: "ACTIONS").click + within ".ofn-drop-down-with-prepend .menu" do + page.find("span", text: "Cancel Orders").click + end + + within "#custom-confirm.modal" do + expect { + find_button("OK").click # Confirms the cancel action + }.to_not enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice) + end + + expect(page).to have_content("CANCELLED", count: 2) + end + context "for a hub manager" do before do login_to_admin_as owner2 From fa96f7339d7f5c467ad2160862c9879dd2d8da12 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 23 Jan 2023 11:35:53 +0000 Subject: [PATCH 9/9] Replaces URL with routing syntax --- spec/system/admin/orders_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/system/admin/orders_spec.rb b/spec/system/admin/orders_spec.rb index 0681f5ac98..782cf20cc0 100644 --- a/spec/system/admin/orders_spec.rb +++ b/spec/system/admin/orders_spec.rb @@ -80,7 +80,7 @@ describe ' before do order2.select_shipping_method(shipping_method.id) order4.select_shipping_method(shipping_method2.id) - login_as_admin_and_visit 'admin/orders' + login_as_admin_and_visit spree.admin_orders_path end it "order cycles appear in descending order by close date on orders page" do @@ -214,7 +214,7 @@ describe ' context "select/unselect all orders" do before do - login_as_admin_and_visit 'admin/orders' + login_as_admin_and_visit spree.admin_orders_path end it "by clicking on the checkbox in the table header" do