|
232 | 232 | order.complete
|
233 | 233 | }.to change{ promo_adjustment.reload.eligible }.to(false)
|
234 | 234 | end
|
| 235 | + end |
235 | 236 |
|
236 |
| - it "adjusts the promo_total" do |
237 |
| - expect{ |
238 |
| - order.complete |
239 |
| - }.to change(order, :promo_total).by(10) |
| 237 | + describe "checking whether a promotion code is still eligible after one use" do |
| 238 | + let(:promotion) do |
| 239 | + FactoryBot.create( |
| 240 | + :promotion, |
| 241 | + :with_order_adjustment, |
| 242 | + code: "discount", |
| 243 | + per_code_usage_limit: 1, |
| 244 | + weighted_order_adjustment_amount: 10 |
| 245 | + ) |
| 246 | + end |
| 247 | + let(:code) { promotion.codes.first } |
| 248 | + let(:order) do |
| 249 | + FactoryBot.create(:order_with_line_items, line_items_price: 40, shipment_cost: 0).tap do |order| |
| 250 | + FactoryBot.create(:payment, amount: 30, order:) |
| 251 | + promotion.activate(order:, promotion_code: code) |
| 252 | + end |
240 | 253 | end
|
| 254 | + let(:promo_adjustment) { order.adjustments.promotion.first } |
241 | 255 |
|
242 |
| - it "increases the total to remove the promo" do |
243 |
| - expect{ |
244 |
| - order.complete |
245 |
| - }.to change(order, :total).from(30).to(40) |
| 256 | + before do |
| 257 | + order.next! until order.can_complete? |
| 258 | + |
| 259 | + FactoryBot.create(:order_with_line_items, line_items_price: 40, shipment_cost: 0).tap do |order| |
| 260 | + FactoryBot.create(:payment, amount: 30, order:) |
| 261 | + promotion.activate(order:, promotion_code: code) |
| 262 | + order.next! until order.can_complete? |
| 263 | + order.complete! |
| 264 | + end |
246 | 265 | end
|
247 | 266 |
|
248 |
| - it "resets the state of the order" do |
249 |
| - expect{ |
250 |
| - order.complete |
251 |
| - }.to change{ order.reload.state }.from("confirm").to("address") |
| 267 | + context 'with the in-memory order updater' do |
| 268 | + subject { order.recalculate(persist: false) } |
| 269 | + |
| 270 | + around do |example| |
| 271 | + default_order_recalculator = Spree::Config.order_recalculator_class.to_s |
| 272 | + |
| 273 | + Spree::Config.order_recalculator_class = 'Spree::InMemoryOrderUpdater' |
| 274 | + |
| 275 | + example.run |
| 276 | + |
| 277 | + Spree::Config.order_recalculator_class = default_order_recalculator |
| 278 | + end |
| 279 | + |
| 280 | + it "makes the promotion ineligible" do |
| 281 | + expect { subject } |
| 282 | + .to change { order.adjustments.first.eligible } |
| 283 | + .from(true) |
| 284 | + .to(false) |
| 285 | + |
| 286 | + expect(promo_adjustment.reload.eligible).to eq true |
| 287 | + end |
| 288 | + |
| 289 | + it "adjusts the promo_total" do |
| 290 | + expect { subject }.to change { order.promo_total }.from(-10).to(0) |
| 291 | + |
| 292 | + expect(order.reload.promo_total).to eq -10 |
| 293 | + end |
| 294 | + |
| 295 | + it "increases the total to remove the promo", |
| 296 | + pending: "This failure points to a real issue we have with the in-memory order updater" do |
| 297 | + expect { subject }.to change { order.total }.from(30).to(40) |
| 298 | + |
| 299 | + expect(order.reload.total).to eq 40 |
| 300 | + end |
252 | 301 | end
|
253 | 302 | end
|
254 | 303 |
|
|
0 commit comments