forked from spree/spree
-
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.
[api] Add assurances that line item prices cannot be set while creati…
…ng or updating orders
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ module Spree | |
response.status.should == 201 | ||
end | ||
|
||
it "sets line items price" do | ||
it "cannot arbitrarily set the line items price" do | ||
api_post :create, :order => { | ||
:line_items => { | ||
"0" => { | ||
|
@@ -129,7 +129,7 @@ module Spree | |
} | ||
|
||
expect(response.status).to eq 201 | ||
expect(Order.last.line_items.first.price.to_f).to eq 33.0 | ||
expect(Order.last.line_items.first.price.to_f).to eq(variant.price) | ||
end | ||
|
||
# Regression test for #3404 | ||
|
@@ -195,6 +195,19 @@ def clean_address(address) | |
json_response['line_items'].first['quantity'].should == 10 | ||
end | ||
|
||
it "cannot change the price of an existing line item" do | ||
api_put :update, :id => order.to_param, :order => { | ||
:line_items => { | ||
line_item.id => { :price => 0 } | ||
} | ||
} | ||
|
||
response.status.should == 200 | ||
json_response['line_items'].count.should == 1 | ||
expect(json_response['line_items'].first['price'].to_f).to_not eq(0) | ||
expect(json_response['line_items'].first['price'].to_f).to eq(line_item.variant.price) | ||
end | ||
|
||
it "can add billing address" do | ||
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address } | ||
|
||
|
@@ -385,6 +398,21 @@ def clean_address(address) | |
end | ||
end | ||
|
||
context "creation" do | ||
it "can arbitrarily set the line items price" do | ||
api_post :create, :order => { | ||
:line_items => { | ||
"0" => { | ||
:price => 33.0, :variant_id => variant.to_param, :quantity => 5 | ||
} | ||
} | ||
} | ||
|
||
expect(response.status).to eq 201 | ||
expect(Order.last.line_items.first.price.to_f).to eq(33.0) | ||
end | ||
end | ||
|
||
context "can cancel an order" do | ||
before do | ||
Spree::Config[:mails_from] = "[email protected]" | ||
|