mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Repair ProxyOrder to support order cycle without closing time
This commit is contained in:
@@ -76,6 +76,7 @@ class ProxyOrder < ApplicationRecord
|
||||
|
||||
def cart?
|
||||
order&.state == 'complete' &&
|
||||
order_cycle.orders_close_at.present? &&
|
||||
order_cycle.orders_close_at > Time.zone.now
|
||||
end
|
||||
|
||||
|
||||
@@ -206,6 +206,75 @@ RSpec.describe ProxyOrder do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#state" do
|
||||
subject(:proxy_order) { build(:proxy_order, subscription:, order:, order_cycle:) }
|
||||
|
||||
let(:order) { build(:order) }
|
||||
let(:subscription) { build(:subscription) }
|
||||
let(:order_cycle) { build(:simple_order_cycle) }
|
||||
|
||||
context "when the proxy order is canceled" do
|
||||
it "returns 'canceled'" do
|
||||
proxy_order.canceled_at = Time.zone.now
|
||||
expect(proxy_order.state).to eq('canceled')
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order is not present" do
|
||||
let(:order) { nil }
|
||||
|
||||
it "returns 'canceled'" do
|
||||
expect(proxy_order.state).to eq('pending')
|
||||
end
|
||||
|
||||
context "when the subscription is paused" do
|
||||
it "returns 'paused'" do
|
||||
subscription.paused_at = Time.zone.now
|
||||
expect(proxy_order.state).to eq('paused')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order cycle is not yet open" do
|
||||
let(:order_cycle) { build(:order_cycle, orders_open_at: 2.days.from_now) }
|
||||
|
||||
it "returns 'cart'" do
|
||||
expect(proxy_order.state).to eq('pending')
|
||||
end
|
||||
|
||||
context "when the subscription is not paused" do
|
||||
it "returns 'pending'" do
|
||||
expect(proxy_order.state).to eq('pending')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order is complete" do
|
||||
let(:order) { build(:completed_order_with_totals) }
|
||||
|
||||
context "when the order cycle is already closed" do
|
||||
it "returns 'complete'" do
|
||||
order_cycle.orders_close_at = 2.days.ago
|
||||
expect(proxy_order.state).to eq('complete')
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order cycle is still open" do
|
||||
it "returns 'cart'" do
|
||||
order_cycle.orders_close_at = 2.days.from_now
|
||||
expect(proxy_order.state).to eq('cart')
|
||||
end
|
||||
end
|
||||
|
||||
context "when the order cycle does not have a closing date" do
|
||||
it "returns 'cart'" do
|
||||
order_cycle.orders_close_at = nil
|
||||
expect(proxy_order.state).to eq('complete')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def expect_cancelled_now(subject)
|
||||
|
||||
Reference in New Issue
Block a user