mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-10 03:30:22 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
159bbe18e6 | ||
|
|
53fb00ce0c |
@@ -198,8 +198,13 @@ module OpenFoodNetwork
|
|||||||
private
|
private
|
||||||
|
|
||||||
def shipping_method(line_items)
|
def shipping_method(line_items)
|
||||||
line_items.first.order.shipments.first.
|
shipping_rates = line_items.first.order.shipments.first.
|
||||||
andand.shipping_rates.andand.first.andand.shipping_method
|
andand.shipping_rates
|
||||||
|
|
||||||
|
return unless shipping_rates
|
||||||
|
|
||||||
|
shipping_rate = shipping_rates.find(&:selected) || shipping_rates.first
|
||||||
|
shipping_rate.try(:shipping_method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,14 +2,7 @@ require "spec_helper"
|
|||||||
|
|
||||||
RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsReport do
|
RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsReport do
|
||||||
let!(:distributor) { create(:distributor_enterprise) }
|
let!(:distributor) { create(:distributor_enterprise) }
|
||||||
|
|
||||||
let!(:customer) { create(:customer, enterprise: distributor) }
|
let!(:customer) { create(:customer, enterprise: distributor) }
|
||||||
|
|
||||||
let!(:order) do
|
|
||||||
create(:completed_order_with_totals, line_items_count: 1, user: customer.user,
|
|
||||||
customer: customer, distributor: distributor)
|
|
||||||
end
|
|
||||||
|
|
||||||
let(:current_user) { distributor.owner }
|
let(:current_user) { distributor.owner }
|
||||||
let(:permissions) { OpenFoodNetwork::Permissions.new(current_user) }
|
let(:permissions) { OpenFoodNetwork::Permissions.new(current_user) }
|
||||||
|
|
||||||
@@ -22,18 +15,51 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsRepor
|
|||||||
OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items)
|
OpenFoodNetwork::OrderGrouper.new(report.rules, report.columns).table(report.table_items)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates the report" do
|
context "viewing the report" do
|
||||||
expect(report_table.length).to eq(2)
|
let!(:order) do
|
||||||
|
create(:completed_order_with_totals, line_items_count: 1, user: customer.user,
|
||||||
|
customer: customer, distributor: distributor)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates the report" do
|
||||||
|
expect(report_table.length).to eq(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a line item row" do
|
||||||
|
distributor_name_field = report_table.first[0]
|
||||||
|
expect(distributor_name_field).to eq distributor.name
|
||||||
|
|
||||||
|
customer_name_field = report_table.first[1]
|
||||||
|
expect(customer_name_field).to eq order.bill_address.full_name
|
||||||
|
|
||||||
|
total_field = report_table.last[5]
|
||||||
|
expect(total_field).to eq I18n.t("admin.reports.total")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has a line item row" do
|
context "loading shipping methods" do
|
||||||
distributor_name_field = report_table.first[0]
|
let!(:shipping_method1) {
|
||||||
expect(distributor_name_field).to eq distributor.name
|
create(:shipping_method, distributors: [distributor], name: "First")
|
||||||
|
}
|
||||||
|
let!(:shipping_method2) {
|
||||||
|
create(:shipping_method, distributors: [distributor], name: "Second")
|
||||||
|
}
|
||||||
|
let!(:shipping_method3) {
|
||||||
|
create(:shipping_method, distributors: [distributor], name: "Third")
|
||||||
|
}
|
||||||
|
let!(:order) do
|
||||||
|
create(:completed_order_with_totals, line_items_count: 1, user: customer.user,
|
||||||
|
customer: customer, distributor: distributor)
|
||||||
|
end
|
||||||
|
|
||||||
customer_name_field = report_table.first[1]
|
before do
|
||||||
expect(customer_name_field).to eq order.bill_address.full_name
|
order.shipments.each(&:refresh_rates)
|
||||||
|
order.select_shipping_method(shipping_method2.id)
|
||||||
|
end
|
||||||
|
|
||||||
total_field = report_table.last[5]
|
it "displays the correct shipping_method" do
|
||||||
expect(total_field).to eq I18n.t("admin.reports.total")
|
shipping_method_name_field = report_table.first[15]
|
||||||
|
expect(shipping_method_name_field).to eq shipping_method2.name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user