From fe93e3ed974fc45212102d466e80f9140493c714 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 18 Jun 2024 19:32:44 -0600 Subject: [PATCH 1/4] Restructures spec Separating into different contexts, with and without invoices feature enabled --- spec/system/admin/orders/bulk_actions_spec.rb | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/spec/system/admin/orders/bulk_actions_spec.rb b/spec/system/admin/orders/bulk_actions_spec.rb index e93cfe4b5f..4df6040459 100644 --- a/spec/system/admin/orders/bulk_actions_spec.rb +++ b/spec/system/admin/orders/bulk_actions_spec.rb @@ -337,11 +337,6 @@ RSpec.describe ' end end context "the distributor of one of the order didn't set the ABN" do - before do - order4.distributor.update(abn: "123456789") - order5.distributor.update(abn: nil) - end - shared_examples "should not print the invoice" do it "should render a warning message" do page.find(order4_selector).click @@ -363,9 +358,20 @@ RSpec.describe ' } must have a valid ABN before invoices can be used." end end - it_behaves_like "should not print the invoice" - context "with legal invoices feature", feature: :invoices do - it_behaves_like "should not print the invoice" + + context "ABN is nil" do + before do + order4.distributor.update(abn: "123456789") + order5.distributor.update(abn: nil) + end + + context "with legal invoices feature disabled" do + it_behaves_like "should not print the invoice" + end + + context "with legal invoices feature", feature: :invoices do + it_behaves_like "should not print the invoice" + end end end end From 59b6cdaf01497153a8429a9b8bc23e6ae0172cf0 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 18 Jun 2024 19:46:36 -0600 Subject: [PATCH 2/4] Extends tests to cases where ABN is an empty string Removes pending and changes testcase As discussed on Slack we will not fix old invoice model, for ref. see: https://openfoodnetwork.slack.com/archives/CG7NJ966B/p1718781775612759?thread_ts=1718249609.127149&cid=CG7NJ966B --- spec/system/admin/orders/bulk_actions_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/system/admin/orders/bulk_actions_spec.rb b/spec/system/admin/orders/bulk_actions_spec.rb index 4df6040459..ef97e219bd 100644 --- a/spec/system/admin/orders/bulk_actions_spec.rb +++ b/spec/system/admin/orders/bulk_actions_spec.rb @@ -373,6 +373,22 @@ RSpec.describe ' it_behaves_like "should not print the invoice" end end + + context "ABN is an empty string" do + before do + order4.distributor.update(abn: "123456789") + order5.distributor.update(abn: "") + end + + context "with legal invoices feature disabled" do + it_behaves_like "can bulk print invoices from 2 orders" + end + + context "with legal invoices feature", feature: :invoices do + before { pending("#12373") } + it_behaves_like "should not print the invoice" + end + end end end end From 3380175c30ab537080a77e60c3a62d2aaba2d61a Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 19 Jun 2024 16:52:36 -0600 Subject: [PATCH 3/4] Restructures spec to accommodate shared example on bulk printing --- spec/system/admin/orders/bulk_actions_spec.rb | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/spec/system/admin/orders/bulk_actions_spec.rb b/spec/system/admin/orders/bulk_actions_spec.rb index ef97e219bd..4568374c17 100644 --- a/spec/system/admin/orders/bulk_actions_spec.rb +++ b/spec/system/admin/orders/bulk_actions_spec.rb @@ -140,25 +140,29 @@ RSpec.describe ' end end - it "can bulk send confirmation email from 2 orders" do - page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click - page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click + shared_examples "can bulk send confirmation email from 2 orders" do + it "bulk prints invoices in pdf format" do + page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click + page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click - page.find("span.icon-reorder", text: "ACTIONS").click - within ".ofn-drop-down .menu" do - page.find("span", text: "Resend Confirmation").click + page.find("span.icon-reorder", text: "ACTIONS").click + within ".ofn-drop-down .menu" do + page.find("span", text: "Resend Confirmation").click + end + + expect(page).to have_content "Are you sure you want to proceed?" + + within ".reveal-modal" do + expect { + find_button("Confirm").click + }.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice) + end + + expect(page).to have_content "Confirmation emails sent for 2 orders." end - - expect(page).to have_content "Are you sure you want to proceed?" - - within ".reveal-modal" do - expect { - find_button("Confirm").click - }.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice) - end - - expect(page).to have_content "Confirmation emails sent for 2 orders." end + + it_behaves_like "can bulk send confirmation email from 2 orders" end context "can bulk print invoices" do From d1560ce15e8056c05d6dbb66f99a12030382dae7 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 19 Jun 2024 17:42:30 -0600 Subject: [PATCH 4/4] Adds shared examples for bulk send invoices in PDF --- spec/system/admin/orders/bulk_actions_spec.rb | 79 +++++++++++++------ 1 file changed, 55 insertions(+), 24 deletions(-) diff --git a/spec/system/admin/orders/bulk_actions_spec.rb b/spec/system/admin/orders/bulk_actions_spec.rb index 4568374c17..17fdc62575 100644 --- a/spec/system/admin/orders/bulk_actions_spec.rb +++ b/spec/system/admin/orders/bulk_actions_spec.rb @@ -105,14 +105,7 @@ RSpec.describe ' Spree::Config[:enterprise_number_required_on_invoices?] = false end - context "with multiple orders with differents states" do - before do - order2.update(state: "complete") - order3.update(state: "resumed") - order4.update(state: "canceled") - order5.update(state: "payment") - end - + shared_examples "can bulk send confirmation email from 2 orders" do it "can bulk send invoices per email, but only for the 'complete' or 'resumed' ones" do within "#listing_orders" do page.find("input[name='bulk_ids[]'][value='#{order2.id}']").click @@ -122,6 +115,7 @@ RSpec.describe ' end page.find("span.icon-reorder", text: "ACTIONS").click + within ".ofn-drop-down .menu" do page.find("span", text: "Send Invoices").click end @@ -140,29 +134,66 @@ RSpec.describe ' end end - shared_examples "can bulk send confirmation email from 2 orders" do - it "bulk prints invoices in pdf format" do - page.find("#listing_orders tbody tr:nth-child(1) input[name='bulk_ids[]']").click - page.find("#listing_orders tbody tr:nth-child(2) input[name='bulk_ids[]']").click + context "with multiple orders with differents states" do + before do + order2.update(state: "canceled") + order3.update(state: "payment") + order4.update(state: "complete") + order5.update(state: "resumed") + end - page.find("span.icon-reorder", text: "ACTIONS").click - within ".ofn-drop-down .menu" do - page.find("span", text: "Resend Confirmation").click + it_behaves_like "can bulk send confirmation email from 2 orders" + + describe "ABN" do + context "ABN is not required" do + before do + allow(Spree::Config).to receive(:enterprise_number_required_on_invoices?) + .and_return false + end + it_behaves_like "can bulk send confirmation email from 2 orders" end + context "ABN is required" do + before do + allow(Spree::Config).to receive(:enterprise_number_required_on_invoices?) + .and_return true + end + context "All the distributors setup the ABN" do + before do + order4.distributor.update(abn: "123456789") + order5.distributor.update(abn: "987654321") + end + context "all the orders are invoiceable (completed/resumed)" do + it_behaves_like "can bulk send confirmation email from 2 orders" + end + end + context "the distributor of one of the order didn't set the ABN" do + context "ABN is nil" do + before do + order4.distributor.update(abn: "123456789") + order5.distributor.update(abn: nil) + end - expect(page).to have_content "Are you sure you want to proceed?" + context "with legal invoices feature disabled" do + before { pending("Emails are not sent in this case") } + it_behaves_like "can bulk send confirmation email from 2 orders" + end + end - within ".reveal-modal" do - expect { - find_button("Confirm").click - }.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice) + context "ABN is an empty string" do + before do + order4.distributor.update(abn: "123456789") + order5.distributor.update(abn: "") + end + + context "with legal invoices feature disabled" do + before { pending("Emails are not sent in this case") } + it_behaves_like "can bulk send confirmation email from 2 orders" + end + end + end end - - expect(page).to have_content "Confirmation emails sent for 2 orders." end end - - it_behaves_like "can bulk send confirmation email from 2 orders" end context "can bulk print invoices" do