|
206 | 206 | end |
207 | 207 | end |
208 | 208 |
|
| 209 | + describe "#state" do |
| 210 | + subject(:proxy_order) { build(:proxy_order, subscription:, order:, order_cycle:) } |
| 211 | + |
| 212 | + let(:order) { build(:order) } |
| 213 | + let(:subscription) { build(:subscription) } |
| 214 | + let(:order_cycle) { build(:simple_order_cycle) } |
| 215 | + |
| 216 | + context "when the proxy order is canceled" do |
| 217 | + it "returns 'canceled'" do |
| 218 | + proxy_order.canceled_at = Time.zone.now |
| 219 | + expect(proxy_order.state).to eq('canceled') |
| 220 | + end |
| 221 | + end |
| 222 | + |
| 223 | + context "when the order is not present" do |
| 224 | + let(:order) { nil } |
| 225 | + |
| 226 | + it "returns 'pending'" do |
| 227 | + expect(proxy_order.state).to eq('pending') |
| 228 | + end |
| 229 | + |
| 230 | + context "when the subscription is paused" do |
| 231 | + it "returns 'paused'" do |
| 232 | + subscription.paused_at = Time.zone.now |
| 233 | + expect(proxy_order.state).to eq('paused') |
| 234 | + end |
| 235 | + end |
| 236 | + end |
| 237 | + |
| 238 | + context "when the order cycle is not yet open" do |
| 239 | + let(:order_cycle) { build(:order_cycle, orders_open_at: 2.days.from_now) } |
| 240 | + |
| 241 | + it "returns 'pending'" do |
| 242 | + expect(proxy_order.state).to eq('pending') |
| 243 | + end |
| 244 | + end |
| 245 | + |
| 246 | + context "when the order is complete" do |
| 247 | + let(:order) { build(:completed_order_with_totals) } |
| 248 | + |
| 249 | + context "when the order cycle is already closed" do |
| 250 | + it "returns 'complete'" do |
| 251 | + order_cycle.orders_close_at = 2.days.ago |
| 252 | + expect(proxy_order.state).to eq('complete') |
| 253 | + end |
| 254 | + end |
| 255 | + |
| 256 | + context "when the order cycle is still open" do |
| 257 | + it "returns 'cart'" do |
| 258 | + order_cycle.orders_close_at = 2.days.from_now |
| 259 | + expect(proxy_order.state).to eq('cart') |
| 260 | + end |
| 261 | + end |
| 262 | + |
| 263 | + context "when the order cycle does not have a closing date" do |
| 264 | + it "returns 'complete'" do |
| 265 | + order_cycle.orders_close_at = nil |
| 266 | + expect(proxy_order.state).to eq('complete') |
| 267 | + end |
| 268 | + end |
| 269 | + end |
| 270 | + end |
| 271 | + |
209 | 272 | private |
210 | 273 |
|
211 | 274 | def expect_cancelled_now(subject) |
|
0 commit comments