diff --git a/spec/fixtures/reports/orders_and_fulfillment/order_cycle_customer_totals_report.csv b/spec/fixtures/reports/orders_and_fulfillment/order_cycle_customer_totals_report.csv new file mode 100644 index 0000000000..1fffddd882 --- /dev/null +++ b/spec/fixtures/reports/orders_and_fulfillment/order_cycle_customer_totals_report.csv @@ -0,0 +1,3 @@ +Hub,Customer,Email,Phone,Producer,Product,Variant,Quantity,Item ($),Item + Fees ($),Admin & Handling ($),Ship ($),Pay fee ($),Total ($),Paid?,Shipping,Delivery?,Ship Street,Ship Street 2,Ship City,Ship Postcode,Ship State,Comments,SKU,Order Cycle,Payment Method,Customer Code,Tags,Billing Street,Billing Street 2,Billing City,Billing Postcode,Billing State,Order number,Date +Apple Market,John Doe,john@example.net,123-456-7890,Apple Farmer,Apples,"1g, S",1,10.0,10.0,"","","","",No,UPS Ground,Yes,10 Lovely Street,Northwest,Herndon,20170,Victoria,"",APP,"","",JHN,"",10 Lovely Street,Northwest,Herndon,20170,Victoria,R644360121,2022-05-26 00:00:00 +Apple Market,John Doe,"","","","","",TOTAL,10.0,10.0,0,0.0,0,10.0,No,"","","","","","","","","","","","","","","","","","",R644360121,2022-05-26 00:00:00 diff --git a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb index f825264982..8472a8ae28 100644 --- a/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/order_cycle_customer_totals_report_spec.rb @@ -6,8 +6,9 @@ module Reporting module Reports module OrdersAndFulfillment describe OrderCycleCustomerTotals do - let!(:distributor) { create(:distributor_enterprise) } - let!(:customer) { create(:customer, enterprise: distributor) } + let!(:distributor) { create(:distributor_enterprise, name: "Apple Market") } + let!(:customer) { create(:customer, enterprise: distributor, user: user, code: "JHN") } + let(:user) { create(:user, email: "john@example.net") } let(:current_user) { distributor.owner } let(:params) { { display_summary_row: true } } let(:report) { OrderCycleCustomerTotals.new(current_user, params) } @@ -18,12 +19,31 @@ module Reporting context "viewing the report" do let!(:order) do - create(:completed_order_with_totals, line_items_count: 1, user: customer.user, - customer: customer, distributor: distributor) + create( + :completed_order_with_totals, + number: "R644360121", + line_items_count: 1, + user: customer.user, + customer: customer, + distributor: distributor, + completed_at: Date.parse("2022-05-26"), + ).tap do |order| + order.line_items[0].product.supplier.update(name: "Apple Farmer") + order.line_items[0].product.update(name: "Apples") + order.line_items[0].variant.update(sku: "APP") + end + end + let(:comparison_report) do + File.read(Rails.root.join(report_file_name)) + end + let(:report_file_name) do + "spec/fixtures/reports/orders_and_fulfillment/order_cycle_customer_totals_report.csv" end it "generates the report" do expect(report_table.length).to eq(2) + + expect(report.render_as(:csv)).to eq comparison_report end it "has a line item row" do