From 8b0c4ee0acacb3cc0c86f197acaa332f312c06b3 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 15 Feb 2023 14:26:35 +1100 Subject: [PATCH 1/3] Add unit test for failing Enterprise Fee Summary I observed this data but I'm unsure about the root cause. It could be that the SQL query fetching this data needs tweaking to return the fee name in this case or it could be that it's not available (deleted). In any case, I thought I document what's happening and make this summarizer more robust before looking into the query. --- .../enterprise_fee_summary/summarizer_spec.rb | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb diff --git a/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb b/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb new file mode 100644 index 0000000000..ec041c2717 --- /dev/null +++ b/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe Reporting::Reports::EnterpriseFeeSummary::Summarizer do + let(:row) { + { + "total_amount" => 1, "payment_method_name" => nil, + "shipping_method_name" => nil, "hub_name" => "Kimchi Hub", + "enterprise_name" => nil, "fee_type" => nil, + "customer_name" => "Fermented Greens", + "customer_email" => "kimchi@example.com", "fee_name" => nil, + "tax_category_name" => nil, + "enterprise_fee_inherits_tax_category" => nil, + "product_tax_category_name" => nil, + "placement_enterprise_role" => nil, + "adjustment_adjustable_type" => nil, + "adjustment_source_distributor_name" => nil, + "incoming_exchange_enterprise_name" => nil, + "outgoing_exchange_enterprise_name" => nil, + "id" => nil + } + } + + it "represents a transaction fee" do + data = row.merge( + "payment_method_name" => "cash", + "adjustment_adjustable_type" => "Spree::Payment", + ) + summarizer = described_class.new(data) + expect(summarizer.fee_type).to eq "Payment Transaction" + end + + it "represents an enterprise fee without name" do + pending "Enterprise Fee Summary report fails #10395" + + data = row.merge( + "fee_name" => nil, + "placement_enterprise_role" => "coordinator", + "adjustment_adjustable_type" => "Spree::LineItem", + ) + summarizer = described_class.new(data) + expect(summarizer.fee_type).to eq nil + end +end From 8c7b4f73f7ce13648249b4a5f1a430cf4da00637 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 15 Feb 2023 14:32:01 +1100 Subject: [PATCH 2/3] Detect transaction fee even if fee name is missing The Enterprise Fee Summary report is not always providing a fee name. While that may be a bug on its own, we handle that gracefully now. --- lib/reporting/reports/enterprise_fee_summary/summarizer.rb | 2 +- spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/summarizer.rb b/lib/reporting/reports/enterprise_fee_summary/summarizer.rb index dd223b72dd..b66acb7e73 100644 --- a/lib/reporting/reports/enterprise_fee_summary/summarizer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/summarizer.rb @@ -31,7 +31,7 @@ module Reporting return DataRepresentations::PaymentMethodFee if for_payment_method? return DataRepresentations::ShippingMethodFee if for_shipping_method? - enterprise_fee_adjustment_presentation_klass if for_enterprise_fee? + enterprise_fee_adjustment_presentation_klass end def enterprise_fee_adjustment_presentation_klass diff --git a/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb b/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb index ec041c2717..9070089609 100644 --- a/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb +++ b/spec/lib/reports/enterprise_fee_summary/summarizer_spec.rb @@ -32,8 +32,6 @@ describe Reporting::Reports::EnterpriseFeeSummary::Summarizer do end it "represents an enterprise fee without name" do - pending "Enterprise Fee Summary report fails #10395" - data = row.merge( "fee_name" => nil, "placement_enterprise_role" => "coordinator", From 800ccf503734ea21e0cbaf4a079a9b56ba487c95 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 24 Feb 2023 10:39:53 +1100 Subject: [PATCH 3/3] Remove unused method --- lib/reporting/reports/enterprise_fee_summary/summarizer.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/summarizer.rb b/lib/reporting/reports/enterprise_fee_summary/summarizer.rb index b66acb7e73..d7651f69d4 100644 --- a/lib/reporting/reports/enterprise_fee_summary/summarizer.rb +++ b/lib/reporting/reports/enterprise_fee_summary/summarizer.rb @@ -50,10 +50,6 @@ module Reporting data["shipping_method_name"].present? end - def for_enterprise_fee? - data["fee_name"].present? - end - def for_coordinator_fee? data["placement_enterprise_role"] == "coordinator" end