forked from solidusio/solidus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
App configuration: Use SimpleOrderContents by default
With the null promotion configuration in place, we can't use the legacy Spree::OrderContents class, as that makes references to the legacy promotion system. See solidusio#5755
- Loading branch information
Showing
6 changed files
with
91 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'API Orders', type: :request do | ||
let!(:order) { create(:order) } | ||
let(:variant) { create(:variant) } | ||
let(:line_item) { create(:line_item) } | ||
|
||
let(:attributes) { | ||
[:number, :item_total, :display_total, :total, | ||
:state, :adjustment_total, | ||
:user_id, :created_at, :updated_at, | ||
:completed_at, :payment_total, :shipment_state, | ||
:payment_state, :email, :special_instructions, | ||
:total_quantity, :display_item_total, :currency] | ||
} | ||
|
||
let(:address_params) { { country_id: Country.first.id, state_id: State.first.id } } | ||
|
||
let(:current_api_user) do | ||
user = Spree.user_class.new(email: "[email protected]") | ||
user.generate_spree_api_key! | ||
user | ||
end | ||
|
||
before do | ||
stub_authentication! | ||
end | ||
|
||
describe "POST create" do | ||
let(:target_user) { create :user } | ||
let(:date_override) { Time.parse('2015-01-01') } | ||
let(:attributes) { { user_id: target_user.id, created_at: date_override, email: target_user.email } } | ||
|
||
subject do | ||
post spree.api_orders_path, params: { order: attributes } | ||
response | ||
end | ||
|
||
context "when the current user cannot administrate the order" do | ||
custom_authorization! do |_| | ||
can :create, Spree::Order | ||
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 = Spree::Order.last | ||
line_item = order.line_items.first | ||
expect(order.total).to eq(line_item.price - discount) | ||
end | ||
end | ||
end | ||
end | ||
end |