mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Merge pull request #11619 from ccozkan/issue-11611
Add ability to customers report to filter with open ended boundaries
This commit is contained in:
@@ -50,10 +50,10 @@ module Reporting
|
||||
private
|
||||
|
||||
def filter_to_completed_at(orders)
|
||||
min = params.dig(:q, :completed_at_gt)
|
||||
max = params.dig(:q, :completed_at_lt)
|
||||
min = params.dig(:q, :completed_at_gt).presence
|
||||
max = params.dig(:q, :completed_at_lt).presence
|
||||
|
||||
return orders if min.blank? || max.blank?
|
||||
return orders if min.nil? && max.nil?
|
||||
|
||||
orders.where(completed_at: [min..max])
|
||||
end
|
||||
|
||||
@@ -244,18 +244,40 @@ module Reporting
|
||||
expect(subject.filter(orders)).to eq(orders)
|
||||
end
|
||||
|
||||
it "filters to a specific completed_at date" do
|
||||
o1 = create(:order, completed_at: 1.day.ago)
|
||||
o2 = create(:order, completed_at: 3.days.ago)
|
||||
o3 = create(:order, completed_at: 5.days.ago)
|
||||
describe "filters to a specific completed_at date range" do
|
||||
let!(:o1) { create(:order, completed_at: 1.day.ago) }
|
||||
let!(:o2) { create(:order, completed_at: 3.days.ago) }
|
||||
let!(:o3) { create(:order, completed_at: 5.days.ago) }
|
||||
|
||||
allow(subject).to receive(:params).and_return(
|
||||
q: {
|
||||
completed_at_gt: 1.day.before(o2.completed_at),
|
||||
completed_at_lt: 1.day.after(o2.completed_at)
|
||||
}
|
||||
)
|
||||
expect(subject.filter(orders)).to eq([o2])
|
||||
it do
|
||||
allow(subject).to receive(:params).and_return(
|
||||
q: {
|
||||
completed_at_gt: 1.day.before(o2.completed_at),
|
||||
completed_at_lt: 1.day.after(o2.completed_at)
|
||||
}
|
||||
)
|
||||
expect(subject.filter(orders)).to eq([o2])
|
||||
end
|
||||
|
||||
it "when completed_at_gt param is missing" do
|
||||
allow(subject).to receive(:params).and_return(
|
||||
q: {
|
||||
completed_at_gt: "",
|
||||
completed_at_lt: 1.day.after(o2.completed_at)
|
||||
}
|
||||
)
|
||||
expect(subject.filter(orders)).to eq([o2, o3])
|
||||
end
|
||||
|
||||
it "when completed_at_lt param is missing" do
|
||||
allow(subject).to receive(:params).and_return(
|
||||
q: {
|
||||
completed_at_gt: 1.day.before(o2.completed_at),
|
||||
completed_at_lt: ""
|
||||
}
|
||||
)
|
||||
expect(subject.filter(orders)).to eq([o1, o2])
|
||||
end
|
||||
end
|
||||
|
||||
it "filters to a specific distributor" do
|
||||
|
||||
Reference in New Issue
Block a user