Update totals for empty order before sending email

This commit is contained in:
Rob Harrington
2018-04-11 13:40:42 +10:00
committed by Maikel Linke
parent f5e77cdcec
commit 6a71aafce1
2 changed files with 7 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ class SubscriptionPlacementJob
changes = cap_quantity_and_store_changes(order)
if order.line_items.where('quantity > 0').empty?
order.reload.adjustments.destroy_all
order.update!
return send_empty_email(order, changes)
end

View File

@@ -120,7 +120,12 @@ describe SubscriptionPlacementJob do
describe "processing a subscription order" do
let(:subscription) { create(:subscription, with_items: true) }
let(:shop) { subscription.shop }
let(:proxy_order) { create(:proxy_order, subscription: subscription) }
let(:oc) { proxy_order.order_cycle }
let(:ex) { oc.exchanges.outgoing.find_by_sender_id_and_receiver_id(shop.id, shop.id) }
let(:fee) { create(:enterprise_fee, enterprise: shop, fee_type: 'sales', amount: 10) }
let!(:exchange_fee) { ExchangeFee.create!(exchange: ex, enterprise_fee: fee) }
let!(:order) { proxy_order.initialise_order! }
before do
@@ -151,6 +156,7 @@ describe SubscriptionPlacementJob do
expect{ job.send(:process, order) }.to_not change{ order.reload.completed_at }.from(nil)
expect(order.adjustments).to be_empty
expect(order.total).to eq 0
expect(order.adjustment_total).to eq 0
expect(job).to_not have_received(:send_placement_email)
expect(job).to have_received(:send_empty_email)
end