Skip to content

Commit

Permalink
creating an order should activate promotions
Browse files Browse the repository at this point in the history
  • Loading branch information
loicginoux authored and jhawthorn committed Feb 14, 2018
1 parent 2924904 commit 3f73689
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/app/controllers/spree/api/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create
respond_with(@order, default_template: :show, status: 201)
else
@order = Spree::Order.create!(user: current_api_user, store: current_store)
if OrderUpdateAttributes.new(@order, order_params).apply
if @order.contents.update_cart order_params
respond_with(@order, default_template: :show, status: 201)
else
invalid_resource!(@order)
Expand Down
14 changes: 14 additions & 0 deletions api/spec/requests/spree/api/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ module Spree
end
end
end

context "with existing promotion" do
let(:discount) { 2 }
before do
create(:promotion, :with_line_item_adjustment, apply_automatically: true, adjustment_rate: discount )
end

it "activates the promotion" do
post spree.api_orders_path, params: { order: { line_items: { "0" => { variant_id: variant.to_param, quantity: 1 } } } }
order = Order.last
line_item = order.line_items.first
expect(order.total).to eq(line_item.price - discount)
end
end
end

context "when the current user can administrate the order" do
Expand Down

0 comments on commit 3f73689

Please sign in to comment.