spree_api 2.4.0.rc2 → 2.4.0.rc3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +4 -6
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +9 -1
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -9
- data/app/controllers/spree/api/taxons_controller.rb +3 -3
- data/app/helpers/spree/api/api_helpers.rb +0 -2
- data/app/views/spree/api/orders/show.v1.rabl +4 -0
- data/app/views/spree/api/products/show.v1.rabl +4 -0
- data/app/views/spree/api/shipments/small.v1.rabl +4 -0
- data/lib/spree/api/testing_support/helpers.rb +6 -6
- data/lib/spree/api/testing_support/setup.rb +2 -2
- data/spec/controllers/spree/api/addresses_controller_spec.rb +8 -8
- data/spec/controllers/spree/api/base_controller_spec.rb +22 -22
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +53 -53
- data/spec/controllers/spree/api/classifications_controller_spec.rb +5 -5
- data/spec/controllers/spree/api/config_controller_spec.rb +9 -9
- data/spec/controllers/spree/api/countries_controller_spec.rb +11 -11
- data/spec/controllers/spree/api/credit_cards_controller_spec.rb +16 -16
- data/spec/controllers/spree/api/images_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +33 -33
- data/spec/controllers/spree/api/option_types_controller_spec.rb +19 -19
- data/spec/controllers/spree/api/option_values_controller_spec.rb +23 -23
- data/spec/controllers/spree/api/orders_controller_spec.rb +186 -143
- data/spec/controllers/spree/api/payments_controller_spec.rb +39 -39
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +71 -66
- data/spec/controllers/spree/api/promotion_application_spec.rb +13 -13
- data/spec/controllers/spree/api/promotions_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +27 -36
- data/spec/controllers/spree/api/shipments_controller_spec.rb +22 -22
- data/spec/controllers/spree/api/states_controller_spec.rb +18 -18
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +26 -26
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +22 -22
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +16 -16
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +24 -24
- data/spec/controllers/spree/api/taxons_controller_spec.rb +39 -39
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/users_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/variants_controller_spec.rb +36 -36
- data/spec/controllers/spree/api/zones_controller_spec.rb +20 -20
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +0 -1
- data/spec/support/controller_hacks.rb +4 -0
- metadata +4 -4
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::OptionTypesController do
|
4
|
+
describe Api::OptionTypesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:attributes) { [:id, :name, :position, :presentation] }
|
@@ -13,15 +13,15 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_option_values(option_values)
|
16
|
-
option_values.count.
|
17
|
-
option_values.first.
|
16
|
+
expect(option_values.count).to eq(1)
|
17
|
+
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
18
18
|
:option_type_name, :option_type_id])
|
19
19
|
end
|
20
20
|
|
21
21
|
it "can list all option types" do
|
22
22
|
api_get :index
|
23
|
-
json_response.count.
|
24
|
-
json_response.first.
|
23
|
+
expect(json_response.count).to eq(1)
|
24
|
+
expect(json_response.first).to have_attributes(attributes)
|
25
25
|
|
26
26
|
check_option_values(json_response.first["option_values"])
|
27
27
|
end
|
@@ -29,22 +29,22 @@ module Spree
|
|
29
29
|
it "can search for an option type" do
|
30
30
|
create(:option_type, :name => "buzz")
|
31
31
|
api_get :index, :q => { :name_cont => option_type.name }
|
32
|
-
json_response.count.
|
33
|
-
json_response.first.
|
32
|
+
expect(json_response.count).to eq(1)
|
33
|
+
expect(json_response.first).to have_attributes(attributes)
|
34
34
|
end
|
35
35
|
|
36
|
-
it "can
|
36
|
+
it "can retrieve a list of specific option types" do
|
37
37
|
option_type_1 = create(:option_type)
|
38
38
|
option_type_2 = create(:option_type)
|
39
39
|
api_get :index, :ids => "#{option_type.id},#{option_type_1.id}"
|
40
|
-
json_response.count.
|
40
|
+
expect(json_response.count).to eq(2)
|
41
41
|
|
42
42
|
check_option_values(json_response.first["option_values"])
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can list a single option type" do
|
46
46
|
api_get :show, :id => option_type.id
|
47
|
-
json_response.
|
47
|
+
expect(json_response).to have_attributes(attributes)
|
48
48
|
check_option_values(json_response["option_values"])
|
49
49
|
end
|
50
50
|
|
@@ -63,13 +63,13 @@ module Spree
|
|
63
63
|
:name => "Option Type"
|
64
64
|
}
|
65
65
|
assert_not_found!
|
66
|
-
option_type.reload.name.
|
66
|
+
expect(option_type.reload.name).to eq(original_name)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "cannot delete an option type" do
|
70
70
|
api_delete :destroy, :id => option_type.id
|
71
71
|
assert_not_found!
|
72
|
-
|
72
|
+
expect { option_type.reload }.not_to raise_error
|
73
73
|
end
|
74
74
|
|
75
75
|
context "as an admin" do
|
@@ -80,13 +80,13 @@ module Spree
|
|
80
80
|
:name => "Option Type",
|
81
81
|
:presentation => "Option Type"
|
82
82
|
}
|
83
|
-
json_response.
|
84
|
-
response.status.
|
83
|
+
expect(json_response).to have_attributes(attributes)
|
84
|
+
expect(response.status).to eq(201)
|
85
85
|
end
|
86
86
|
|
87
87
|
it "cannot create an option type with invalid attributes" do
|
88
88
|
api_post :create, :option_type => {}
|
89
|
-
response.status.
|
89
|
+
expect(response.status).to eq(422)
|
90
90
|
end
|
91
91
|
|
92
92
|
it "can update an option type" do
|
@@ -94,22 +94,22 @@ module Spree
|
|
94
94
|
api_put :update, :id => option_type.id, :option_type => {
|
95
95
|
:name => "Option Type",
|
96
96
|
}
|
97
|
-
response.status.
|
97
|
+
expect(response.status).to eq(200)
|
98
98
|
|
99
99
|
option_type.reload
|
100
|
-
option_type.name.
|
100
|
+
expect(option_type.name).to eq("Option Type")
|
101
101
|
end
|
102
102
|
|
103
103
|
it "cannot update an option type with invalid attributes" do
|
104
104
|
api_put :update, :id => option_type.id, :option_type => {
|
105
105
|
:name => ""
|
106
106
|
}
|
107
|
-
response.status.
|
107
|
+
expect(response.status).to eq(422)
|
108
108
|
end
|
109
109
|
|
110
110
|
it "can delete an option type" do
|
111
111
|
api_delete :destroy, :id => option_type.id
|
112
|
-
response.status.
|
112
|
+
expect(response.status).to eq(204)
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Api::OptionValuesController do
|
4
|
+
describe Api::OptionValuesController, :type => :controller do
|
5
5
|
render_views
|
6
6
|
|
7
7
|
let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_name] }
|
@@ -13,8 +13,8 @@ module Spree
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def check_option_values(option_values)
|
16
|
-
option_values.count.
|
17
|
-
option_values.first.
|
16
|
+
expect(option_values.count).to eq(1)
|
17
|
+
expect(option_values.first).to have_attributes([:id, :name, :presentation,
|
18
18
|
:option_type_name, :option_type_id])
|
19
19
|
end
|
20
20
|
|
@@ -24,10 +24,10 @@ module Spree
|
|
24
24
|
create(:option_value, :option_type => create(:option_type))
|
25
25
|
end
|
26
26
|
|
27
|
-
it "can
|
27
|
+
it "can retrieve a list of all option values" do
|
28
28
|
api_get :index
|
29
|
-
json_response.count.
|
30
|
-
json_response.first.
|
29
|
+
expect(json_response.count).to eq(2)
|
30
|
+
expect(json_response.first).to have_attributes(attributes)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -36,27 +36,27 @@ module Spree
|
|
36
36
|
|
37
37
|
it "can list all option values" do
|
38
38
|
api_get :index
|
39
|
-
json_response.count.
|
40
|
-
json_response.first.
|
39
|
+
expect(json_response.count).to eq(1)
|
40
|
+
expect(json_response.first).to have_attributes(attributes)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "can search for an option type" do
|
44
44
|
create(:option_value, :name => "buzz")
|
45
45
|
api_get :index, :q => { :name_cont => option_value.name }
|
46
|
-
json_response.count.
|
47
|
-
json_response.first.
|
46
|
+
expect(json_response.count).to eq(1)
|
47
|
+
expect(json_response.first).to have_attributes(attributes)
|
48
48
|
end
|
49
49
|
|
50
|
-
it "can
|
50
|
+
it "can retrieve a list of option types" do
|
51
51
|
option_value_1 = create(:option_value, :option_type => option_type)
|
52
52
|
option_value_2 = create(:option_value, :option_type => option_type)
|
53
53
|
api_get :index, :ids => [option_value.id, option_value_1.id]
|
54
|
-
json_response.count.
|
54
|
+
expect(json_response.count).to eq(2)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can list a single option value" do
|
58
58
|
api_get :show, :id => option_value.id
|
59
|
-
json_response.
|
59
|
+
expect(json_response).to have_attributes(attributes)
|
60
60
|
end
|
61
61
|
|
62
62
|
it "cannot create a new option value" do
|
@@ -74,13 +74,13 @@ module Spree
|
|
74
74
|
:name => "Option Value"
|
75
75
|
}
|
76
76
|
assert_not_found!
|
77
|
-
option_type.reload.name.
|
77
|
+
expect(option_type.reload.name).to eq(original_name)
|
78
78
|
end
|
79
79
|
|
80
80
|
it "cannot delete an option value" do
|
81
81
|
api_delete :destroy, :id => option_type.id
|
82
82
|
assert_not_found!
|
83
|
-
|
83
|
+
expect { option_type.reload }.not_to raise_error
|
84
84
|
end
|
85
85
|
|
86
86
|
context "as an admin" do
|
@@ -91,13 +91,13 @@ module Spree
|
|
91
91
|
:name => "Option Value",
|
92
92
|
:presentation => "Option Value"
|
93
93
|
}
|
94
|
-
json_response.
|
95
|
-
response.status.
|
94
|
+
expect(json_response).to have_attributes(attributes)
|
95
|
+
expect(response.status).to eq(201)
|
96
96
|
end
|
97
97
|
|
98
98
|
it "cannot create an option type with invalid attributes" do
|
99
99
|
api_post :create, :option_value => {}
|
100
|
-
response.status.
|
100
|
+
expect(response.status).to eq(422)
|
101
101
|
end
|
102
102
|
|
103
103
|
it "can update an option value" do
|
@@ -105,14 +105,14 @@ module Spree
|
|
105
105
|
api_put :update, :id => option_value.id, :option_value => {
|
106
106
|
:name => "Option Value",
|
107
107
|
}
|
108
|
-
response.status.
|
108
|
+
expect(response.status).to eq(200)
|
109
109
|
|
110
110
|
option_value.reload
|
111
|
-
option_value.name.
|
111
|
+
expect(option_value.name).to eq("Option Value")
|
112
112
|
end
|
113
113
|
|
114
114
|
it "permits the correct attributes" do
|
115
|
-
controller.
|
115
|
+
expect(controller).to receive(:permitted_option_value_attributes)
|
116
116
|
api_put :update, :id => option_value.id, :option_value => {
|
117
117
|
:name => ""
|
118
118
|
}
|
@@ -122,12 +122,12 @@ module Spree
|
|
122
122
|
api_put :update, :id => option_value.id, :option_value => {
|
123
123
|
:name => ""
|
124
124
|
}
|
125
|
-
response.status.
|
125
|
+
expect(response.status).to eq(422)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can delete an option value" do
|
129
129
|
api_delete :destroy, :id => option_value.id
|
130
|
-
response.status.
|
130
|
+
expect(response.status).to eq(204)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'spree/testing_support/bar_ability'
|
3
3
|
|
4
4
|
module Spree
|
5
|
-
describe Api::OrdersController do
|
5
|
+
describe Api::OrdersController, :type => :controller do
|
6
6
|
render_views
|
7
7
|
|
8
8
|
let!(:order) { create(:order) }
|
@@ -19,11 +19,11 @@ module Spree
|
|
19
19
|
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } }
|
20
20
|
|
21
21
|
let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
22
|
-
:city => "Sao Paulo", :zipcode => "
|
22
|
+
:city => "Sao Paulo", :zipcode => "35762", :phone => "12345678",
|
23
23
|
:country_id => Country.first.id, :state_id => State.first.id} }
|
24
24
|
|
25
25
|
let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
26
|
-
:city => "Sao Paulo", :zipcode => "
|
26
|
+
:city => "Sao Paulo", :zipcode => "35762", :phone => "12345678",
|
27
27
|
:country_id => Country.first.id, :state_id => State.first.id} }
|
28
28
|
|
29
29
|
let(:current_api_user) do
|
@@ -36,6 +36,28 @@ module Spree
|
|
36
36
|
stub_authentication!
|
37
37
|
end
|
38
38
|
|
39
|
+
describe 'PATCH #update' do
|
40
|
+
subject { api_patch :update, id: order.to_param, order: { email: "foo@bar.com" } }
|
41
|
+
|
42
|
+
before do
|
43
|
+
allow_any_instance_of(Spree::Order).to receive_messages :user => current_api_user
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should be ok' do
|
47
|
+
expect(subject).to be_ok
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should not invoke OrderContents#update_cart' do
|
51
|
+
expect_any_instance_of(Spree::OrderContents).to_not receive(:update_cart)
|
52
|
+
subject
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should update the email' do
|
56
|
+
subject
|
57
|
+
expect(order.reload.email).to eq('foo@bar.com')
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
39
61
|
it "cannot view all orders" do
|
40
62
|
api_get :index
|
41
63
|
assert_unauthorized!
|
@@ -46,7 +68,7 @@ module Spree
|
|
46
68
|
|
47
69
|
it "returns a 401" do
|
48
70
|
api_get :mine
|
49
|
-
response.status.
|
71
|
+
expect(response.status).to eq(401)
|
50
72
|
end
|
51
73
|
end
|
52
74
|
|
@@ -57,40 +79,40 @@ module Spree
|
|
57
79
|
it "can view all of their own orders" do
|
58
80
|
api_get :mine
|
59
81
|
|
60
|
-
response.status.
|
61
|
-
json_response["pages"].
|
62
|
-
json_response["current_page"].
|
63
|
-
json_response["orders"].length.
|
64
|
-
json_response["orders"].first["number"].
|
65
|
-
json_response["orders"].first["line_items"].length.
|
66
|
-
json_response["orders"].first["line_items"].first["id"].
|
82
|
+
expect(response.status).to eq(200)
|
83
|
+
expect(json_response["pages"]).to eq(1)
|
84
|
+
expect(json_response["current_page"]).to eq(1)
|
85
|
+
expect(json_response["orders"].length).to eq(1)
|
86
|
+
expect(json_response["orders"].first["number"]).to eq(order.number)
|
87
|
+
expect(json_response["orders"].first["line_items"].length).to eq(1)
|
88
|
+
expect(json_response["orders"].first["line_items"].first["id"]).to eq(line_item.id)
|
67
89
|
end
|
68
90
|
|
69
91
|
it "can filter the returned results" do
|
70
92
|
api_get :mine, q: {completed_at_not_null: 1}
|
71
93
|
|
72
|
-
response.status.
|
73
|
-
json_response["orders"].length.
|
94
|
+
expect(response.status).to eq(200)
|
95
|
+
expect(json_response["orders"].length).to eq(0)
|
74
96
|
end
|
75
97
|
|
76
98
|
it "returns orders in reverse chronological order by completed_at" do
|
77
99
|
order.update_columns completed_at: Time.now
|
78
100
|
|
79
101
|
order2 = Order.create user: order.user, completed_at: Time.now - 1.day
|
80
|
-
order2.created_at.
|
102
|
+
expect(order2.created_at).to be > order.created_at
|
81
103
|
order3 = Order.create user: order.user, completed_at: nil
|
82
|
-
order3.created_at.
|
104
|
+
expect(order3.created_at).to be > order2.created_at
|
83
105
|
order4 = Order.create user: order.user, completed_at: nil
|
84
|
-
order4.created_at.
|
106
|
+
expect(order4.created_at).to be > order3.created_at
|
85
107
|
|
86
108
|
api_get :mine
|
87
|
-
response.status.
|
88
|
-
json_response["pages"].
|
89
|
-
json_response["orders"].length.
|
90
|
-
json_response["orders"][0]["number"].
|
91
|
-
json_response["orders"][1]["number"].
|
92
|
-
json_response["orders"][2]["number"].
|
93
|
-
json_response["orders"][3]["number"].
|
109
|
+
expect(response.status).to eq(200)
|
110
|
+
expect(json_response["pages"]).to eq(1)
|
111
|
+
expect(json_response["orders"].length).to eq(4)
|
112
|
+
expect(json_response["orders"][0]["number"]).to eq(order.number)
|
113
|
+
expect(json_response["orders"][1]["number"]).to eq(order2.number)
|
114
|
+
expect(json_response["orders"][2]["number"]).to eq(order4.number)
|
115
|
+
expect(json_response["orders"][3]["number"]).to eq(order3.number)
|
94
116
|
end
|
95
117
|
end
|
96
118
|
|
@@ -138,42 +160,63 @@ module Spree
|
|
138
160
|
end
|
139
161
|
|
140
162
|
it "can view their own order" do
|
141
|
-
Order.
|
163
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
142
164
|
api_get :show, :id => order.to_param
|
143
|
-
response.status.
|
144
|
-
json_response.
|
145
|
-
json_response["adjustments"].
|
165
|
+
expect(response.status).to eq(200)
|
166
|
+
expect(json_response).to have_attributes(attributes)
|
167
|
+
expect(json_response["adjustments"]).to be_empty
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when shipment adjustments are present' do
|
171
|
+
let(:adjustment) { FactoryGirl.create(:adjustment, order: order) }
|
172
|
+
|
173
|
+
before do
|
174
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
175
|
+
shipment = FactoryGirl.create(:shipment, order: order)
|
176
|
+
shipment.adjustments << adjustment
|
177
|
+
end
|
178
|
+
|
179
|
+
subject { api_get :show, :id => order.to_param }
|
180
|
+
|
181
|
+
it 'contains adjustments in JSON' do
|
182
|
+
subject
|
183
|
+
# Test to insure shipment has adjustments
|
184
|
+
shipment = json_response['shipments'][0]
|
185
|
+
expect(shipment).to_not be_nil
|
186
|
+
expect(shipment['adjustments'][0]).not_to be_empty
|
187
|
+
expect(shipment['adjustments'][0]['label']).to eq(adjustment.label)
|
188
|
+
end
|
146
189
|
end
|
147
190
|
|
148
191
|
it "orders contain the basic checkout steps" do
|
149
|
-
Order.
|
192
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
150
193
|
api_get :show, :id => order.to_param
|
151
|
-
response.status.
|
152
|
-
json_response["checkout_steps"].
|
194
|
+
expect(response.status).to eq(200)
|
195
|
+
expect(json_response["checkout_steps"]).to eq(["address", "delivery", "complete"])
|
153
196
|
end
|
154
197
|
|
155
198
|
# Regression test for #1992
|
156
199
|
it "can view an order not in a standard state" do
|
157
|
-
Order.
|
200
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
158
201
|
order.update_column(:state, 'shipped')
|
159
202
|
api_get :show, :id => order.to_param
|
160
203
|
end
|
161
204
|
|
162
205
|
it "can not view someone else's order" do
|
163
|
-
Order.
|
206
|
+
allow_any_instance_of(Order).to receive_messages :user => stub_model(Spree::LegacyUser)
|
164
207
|
api_get :show, :id => order.to_param
|
165
208
|
assert_unauthorized!
|
166
209
|
end
|
167
210
|
|
168
211
|
it "can view an order if the token is known" do
|
169
212
|
api_get :show, :id => order.to_param, :order_token => order.guest_token
|
170
|
-
response.status.
|
213
|
+
expect(response.status).to eq(200)
|
171
214
|
end
|
172
215
|
|
173
216
|
it "can view an order if the token is passed in header" do
|
174
217
|
request.headers["X-Spree-Order-Token"] = order.guest_token
|
175
218
|
api_get :show, :id => order.to_param
|
176
|
-
response.status.
|
219
|
+
expect(response.status).to eq(200)
|
177
220
|
end
|
178
221
|
|
179
222
|
context "with BarAbility registered" do
|
@@ -182,12 +225,12 @@ module Spree
|
|
182
225
|
|
183
226
|
it "can view an order" do
|
184
227
|
user = mock_model(Spree::LegacyUser)
|
185
|
-
user.
|
186
|
-
user.
|
187
|
-
user.
|
188
|
-
controller.
|
228
|
+
allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(["bar"])
|
229
|
+
allow(user).to receive(:has_spree_role?).with('bar').and_return(true)
|
230
|
+
allow(user).to receive(:has_spree_role?).with('admin').and_return(false)
|
231
|
+
allow(controller).to receive_messages try_spree_current_user: user
|
189
232
|
api_get :show, :id => order.to_param
|
190
|
-
response.status.
|
233
|
+
expect(response.status).to eq(200)
|
191
234
|
end
|
192
235
|
end
|
193
236
|
|
@@ -205,19 +248,19 @@ module Spree
|
|
205
248
|
|
206
249
|
it "can create an order" do
|
207
250
|
api_post :create, :order => { :line_items => { "0" => { :variant_id => variant.to_param, :quantity => 5 } } }
|
208
|
-
response.status.
|
251
|
+
expect(response.status).to eq(201)
|
209
252
|
|
210
253
|
order = Order.last
|
211
|
-
order.line_items.count.
|
212
|
-
order.line_items.first.variant.
|
213
|
-
order.line_items.first.quantity.
|
214
|
-
|
215
|
-
json_response['number'].
|
216
|
-
json_response["token"].
|
217
|
-
json_response["state"].
|
218
|
-
order.user.
|
219
|
-
order.email.
|
220
|
-
json_response["user_id"].
|
254
|
+
expect(order.line_items.count).to eq(1)
|
255
|
+
expect(order.line_items.first.variant).to eq(variant)
|
256
|
+
expect(order.line_items.first.quantity).to eq(5)
|
257
|
+
|
258
|
+
expect(json_response['number']).to be_present
|
259
|
+
expect(json_response["token"]).not_to be_blank
|
260
|
+
expect(json_response["state"]).to eq("cart")
|
261
|
+
expect(order.user).to eq(current_api_user)
|
262
|
+
expect(order.email).to eq(current_api_user.email)
|
263
|
+
expect(json_response["user_id"]).to eq(current_api_user.id)
|
221
264
|
end
|
222
265
|
|
223
266
|
it "assigns email when creating a new order" do
|
@@ -228,12 +271,12 @@ module Spree
|
|
228
271
|
|
229
272
|
# Regression test for #3404
|
230
273
|
it "can specify additional parameters for a line item" do
|
231
|
-
Order.
|
232
|
-
order.
|
233
|
-
order.
|
234
|
-
line_item.
|
274
|
+
expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
|
275
|
+
allow(order).to receive(:associate_user!)
|
276
|
+
allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
277
|
+
expect(line_item).to receive(:update_attributes!).with("special" => true)
|
235
278
|
|
236
|
-
controller.
|
279
|
+
allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
|
237
280
|
api_post :create, :order => {
|
238
281
|
:line_items => {
|
239
282
|
"0" => {
|
@@ -241,7 +284,7 @@ module Spree
|
|
241
284
|
}
|
242
285
|
}
|
243
286
|
}
|
244
|
-
response.status.
|
287
|
+
expect(response.status).to eq(201)
|
245
288
|
end
|
246
289
|
|
247
290
|
it "cannot arbitrarily set the line items price" do
|
@@ -259,8 +302,8 @@ module Spree
|
|
259
302
|
|
260
303
|
context "admin user imports order" do
|
261
304
|
before do
|
262
|
-
current_api_user.
|
263
|
-
current_api_user.
|
305
|
+
allow(current_api_user).to receive_messages has_spree_role?: true
|
306
|
+
allow(current_api_user).to receive_message_chain :spree_roles, pluck: ["admin"]
|
264
307
|
end
|
265
308
|
|
266
309
|
it "is able to set any default unpermitted attribute" do
|
@@ -272,10 +315,10 @@ module Spree
|
|
272
315
|
|
273
316
|
# Regression test for #3404
|
274
317
|
it "does not update line item needlessly" do
|
275
|
-
Order.
|
276
|
-
order.
|
277
|
-
order.
|
278
|
-
line_item.
|
318
|
+
expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
|
319
|
+
allow(order).to receive(:associate_user!)
|
320
|
+
allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
|
321
|
+
expect(line_item).not_to receive(:update_attributes)
|
279
322
|
api_post :create, :order => {
|
280
323
|
:line_items => {
|
281
324
|
"0" => {
|
@@ -286,10 +329,10 @@ module Spree
|
|
286
329
|
end
|
287
330
|
|
288
331
|
it "can create an order without any parameters" do
|
289
|
-
|
290
|
-
response.status.
|
332
|
+
expect { api_post :create }.not_to raise_error
|
333
|
+
expect(response.status).to eq(201)
|
291
334
|
order = Order.last
|
292
|
-
json_response["state"].
|
335
|
+
expect(json_response["state"]).to eq("cart")
|
293
336
|
end
|
294
337
|
|
295
338
|
context "working with an order" do
|
@@ -300,20 +343,20 @@ module Spree
|
|
300
343
|
|
301
344
|
let(:address_params) { { :country_id => Country.first.id, :state_id => State.first.id } }
|
302
345
|
let(:billing_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
303
|
-
:city => "Sao Paulo", :zipcode => "
|
346
|
+
:city => "Sao Paulo", :zipcode => "35762", :phone => "12345678",
|
304
347
|
:country_id => Country.first.id, :state_id => State.first.id} }
|
305
348
|
let(:shipping_address) { { :firstname => "Tiago", :lastname => "Motta", :address1 => "Av Paulista",
|
306
|
-
:city => "Sao Paulo", :zipcode => "
|
349
|
+
:city => "Sao Paulo", :zipcode => "35762", :phone => "12345678",
|
307
350
|
:country_id => Country.first.id, :state_id => State.first.id} }
|
308
351
|
|
309
352
|
before do
|
310
|
-
Spree::LineItem.
|
311
|
-
Order.
|
353
|
+
allow(Spree::LineItem).to receive(:find_by_id).and_return(Spree::LineItem.new)
|
354
|
+
allow_any_instance_of(Order).to receive_messages :user => current_api_user
|
312
355
|
order.next # Switch from cart to address
|
313
356
|
order.bill_address = nil
|
314
357
|
order.ship_address = nil
|
315
358
|
order.save
|
316
|
-
order.state.
|
359
|
+
expect(order.state).to eq("address")
|
317
360
|
end
|
318
361
|
|
319
362
|
def clean_address(address)
|
@@ -339,9 +382,9 @@ module Spree
|
|
339
382
|
}
|
340
383
|
}
|
341
384
|
|
342
|
-
response.status.
|
343
|
-
json_response['line_items'].count.
|
344
|
-
json_response['line_items'].first['quantity'].
|
385
|
+
expect(response.status).to eq(200)
|
386
|
+
expect(json_response['line_items'].count).to eq(1)
|
387
|
+
expect(json_response['line_items'].first['quantity']).to eq(10)
|
345
388
|
end
|
346
389
|
|
347
390
|
it "adds an extra line item" do
|
@@ -353,11 +396,11 @@ module Spree
|
|
353
396
|
}
|
354
397
|
}
|
355
398
|
|
356
|
-
response.status.
|
357
|
-
json_response['line_items'].count.
|
358
|
-
json_response['line_items'][0]['quantity'].
|
359
|
-
json_response['line_items'][1]['variant_id'].
|
360
|
-
json_response['line_items'][1]['quantity'].
|
399
|
+
expect(response.status).to eq(200)
|
400
|
+
expect(json_response['line_items'].count).to eq(2)
|
401
|
+
expect(json_response['line_items'][0]['quantity']).to eq(10)
|
402
|
+
expect(json_response['line_items'][1]['variant_id']).to eq(variant2.id)
|
403
|
+
expect(json_response['line_items'][1]['quantity']).to eq(1)
|
361
404
|
end
|
362
405
|
|
363
406
|
it "cannot change the price of an existing line item" do
|
@@ -367,8 +410,8 @@ module Spree
|
|
367
410
|
}
|
368
411
|
}
|
369
412
|
|
370
|
-
response.status.
|
371
|
-
json_response['line_items'].count.
|
413
|
+
expect(response.status).to eq(200)
|
414
|
+
expect(json_response['line_items'].count).to eq(1)
|
372
415
|
expect(json_response['line_items'].first['price'].to_f).to_not eq(0)
|
373
416
|
expect(json_response['line_items'].first['price'].to_f).to eq(line_item.variant.price)
|
374
417
|
end
|
@@ -376,7 +419,7 @@ module Spree
|
|
376
419
|
it "can add billing address" do
|
377
420
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
378
421
|
|
379
|
-
order.reload.bill_address.
|
422
|
+
expect(order.reload.bill_address).to_not be_nil
|
380
423
|
end
|
381
424
|
|
382
425
|
it "receives error message if trying to add billing address with errors" do
|
@@ -384,28 +427,28 @@ module Spree
|
|
384
427
|
|
385
428
|
api_put :update, :id => order.to_param, :order => { :bill_address_attributes => billing_address }
|
386
429
|
|
387
|
-
json_response['error'].
|
388
|
-
json_response['errors'].
|
389
|
-
json_response['errors']['bill_address.firstname'].first.
|
430
|
+
expect(json_response['error']).not_to be_nil
|
431
|
+
expect(json_response['errors']).not_to be_nil
|
432
|
+
expect(json_response['errors']['bill_address.firstname'].first).to eq "can't be blank"
|
390
433
|
end
|
391
434
|
|
392
435
|
it "can add shipping address" do
|
393
|
-
order.ship_address.
|
436
|
+
expect(order.ship_address).to be_nil
|
394
437
|
|
395
438
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
396
439
|
|
397
|
-
order.reload.ship_address.
|
440
|
+
expect(order.reload.ship_address).not_to be_nil
|
398
441
|
end
|
399
442
|
|
400
443
|
it "receives error message if trying to add shipping address with errors" do
|
401
|
-
order.ship_address.
|
444
|
+
expect(order.ship_address).to be_nil
|
402
445
|
shipping_address[:firstname] = ""
|
403
446
|
|
404
447
|
api_put :update, :id => order.to_param, :order => { :ship_address_attributes => shipping_address }
|
405
448
|
|
406
|
-
json_response['error'].
|
407
|
-
json_response['errors'].
|
408
|
-
json_response['errors']['ship_address.firstname'].first.
|
449
|
+
expect(json_response['error']).not_to be_nil
|
450
|
+
expect(json_response['errors']).not_to be_nil
|
451
|
+
expect(json_response['errors']['ship_address.firstname'].first).to eq "can't be blank"
|
409
452
|
end
|
410
453
|
|
411
454
|
it "cannot set the user_id for the order" do
|
@@ -413,7 +456,7 @@ module Spree
|
|
413
456
|
original_id = order.user_id
|
414
457
|
api_post :update, :id => order.to_param, :order => { user_id: user.id }
|
415
458
|
expect(response.status).to eq 200
|
416
|
-
json_response["user_id"].
|
459
|
+
expect(json_response["user_id"]).to eq(original_id)
|
417
460
|
end
|
418
461
|
|
419
462
|
context "order has shipments" do
|
@@ -433,17 +476,17 @@ module Spree
|
|
433
476
|
context "with a line item" do
|
434
477
|
let(:order_with_line_items) do
|
435
478
|
order = create(:order_with_line_items)
|
436
|
-
create(:adjustment, :adjustable
|
479
|
+
create(:adjustment, order: order, adjustable: order)
|
437
480
|
order
|
438
481
|
end
|
439
482
|
|
440
483
|
it "can empty an order" do
|
441
|
-
order_with_line_items.adjustments.count.
|
484
|
+
expect(order_with_line_items.adjustments.count).to eq(1)
|
442
485
|
api_put :empty, :id => order_with_line_items.to_param
|
443
|
-
response.status.
|
486
|
+
expect(response.status).to eq(204)
|
444
487
|
order_with_line_items.reload
|
445
|
-
order_with_line_items.line_items.
|
446
|
-
order_with_line_items.adjustments.
|
488
|
+
expect(order_with_line_items.line_items).to be_empty
|
489
|
+
expect(order_with_line_items.adjustments).to be_empty
|
447
490
|
end
|
448
491
|
|
449
492
|
it "can list its line items with images" do
|
@@ -451,22 +494,22 @@ module Spree
|
|
451
494
|
|
452
495
|
api_get :show, :id => order.to_param
|
453
496
|
|
454
|
-
json_response['line_items'].first['variant'].
|
497
|
+
expect(json_response['line_items'].first['variant']).to have_attributes([:images])
|
455
498
|
end
|
456
499
|
|
457
500
|
it "lists variants product id" do
|
458
501
|
api_get :show, :id => order.to_param
|
459
502
|
|
460
|
-
json_response['line_items'].first['variant'].
|
503
|
+
expect(json_response['line_items'].first['variant']).to have_attributes([:product_id])
|
461
504
|
end
|
462
505
|
|
463
506
|
it "includes the tax_total in the response" do
|
464
507
|
api_get :show, :id => order.to_param
|
465
508
|
|
466
|
-
json_response['included_tax_total'].
|
467
|
-
json_response['additional_tax_total'].
|
468
|
-
json_response['display_included_tax_total'].
|
469
|
-
json_response['display_additional_tax_total'].
|
509
|
+
expect(json_response['included_tax_total']).to eq('0.0')
|
510
|
+
expect(json_response['additional_tax_total']).to eq('0.0')
|
511
|
+
expect(json_response['display_included_tax_total']).to eq('$0.00')
|
512
|
+
expect(json_response['display_additional_tax_total']).to eq('$0.00')
|
470
513
|
end
|
471
514
|
|
472
515
|
it "lists line item adjustments" do
|
@@ -478,8 +521,8 @@ module Spree
|
|
478
521
|
api_get :show, :id => order.to_param
|
479
522
|
|
480
523
|
adjustment = json_response['line_items'].first['adjustments'].first
|
481
|
-
adjustment['label'].
|
482
|
-
adjustment['amount'].
|
524
|
+
expect(adjustment['label']).to eq("10% off!")
|
525
|
+
expect(adjustment['amount']).to eq("5.0")
|
483
526
|
end
|
484
527
|
|
485
528
|
it "lists payments source without gateway info" do
|
@@ -520,33 +563,33 @@ module Spree
|
|
520
563
|
|
521
564
|
it "returns available shipments for an order" do
|
522
565
|
api_get :show, :id => order.to_param
|
523
|
-
response.status.
|
524
|
-
json_response["shipments"].
|
566
|
+
expect(response.status).to eq(200)
|
567
|
+
expect(json_response["shipments"]).not_to be_empty
|
525
568
|
shipment = json_response["shipments"][0]
|
526
569
|
# Test for correct shipping method attributes
|
527
570
|
# Regression test for #3206
|
528
|
-
shipment["shipping_methods"].
|
571
|
+
expect(shipment["shipping_methods"]).not_to be_nil
|
529
572
|
json_shipping_method = shipment["shipping_methods"][0]
|
530
|
-
json_shipping_method["id"].
|
531
|
-
json_shipping_method["name"].
|
532
|
-
json_shipping_method["code"].
|
533
|
-
json_shipping_method["zones"].
|
534
|
-
json_shipping_method["shipping_categories"].
|
573
|
+
expect(json_shipping_method["id"]).to eq(shipping_method.id)
|
574
|
+
expect(json_shipping_method["name"]).to eq(shipping_method.name)
|
575
|
+
expect(json_shipping_method["code"]).to eq(shipping_method.code)
|
576
|
+
expect(json_shipping_method["zones"]).not_to be_empty
|
577
|
+
expect(json_shipping_method["shipping_categories"]).not_to be_empty
|
535
578
|
|
536
579
|
# Test for correct shipping rates attributes
|
537
580
|
# Regression test for #3206
|
538
|
-
shipment["shipping_rates"].
|
581
|
+
expect(shipment["shipping_rates"]).not_to be_nil
|
539
582
|
shipping_rate = shipment["shipping_rates"][0]
|
540
|
-
shipping_rate["name"].
|
541
|
-
shipping_rate["cost"].
|
542
|
-
shipping_rate["selected"].
|
543
|
-
shipping_rate["display_cost"].
|
544
|
-
shipping_rate["shipping_method_code"].
|
583
|
+
expect(shipping_rate["name"]).to eq(json_shipping_method["name"])
|
584
|
+
expect(shipping_rate["cost"]).to eq("10.0")
|
585
|
+
expect(shipping_rate["selected"]).to be true
|
586
|
+
expect(shipping_rate["display_cost"]).to eq("$10.00")
|
587
|
+
expect(shipping_rate["shipping_method_code"]).to eq(json_shipping_method["code"])
|
545
588
|
|
546
|
-
shipment["stock_location_name"].
|
589
|
+
expect(shipment["stock_location_name"]).not_to be_blank
|
547
590
|
manifest_item = shipment["manifest"][0]
|
548
|
-
manifest_item["quantity"].
|
549
|
-
manifest_item["variant_id"].
|
591
|
+
expect(manifest_item["quantity"]).to eq(1)
|
592
|
+
expect(manifest_item["variant_id"]).to eq(order.line_items.first.variant_id)
|
550
593
|
end
|
551
594
|
end
|
552
595
|
end
|
@@ -559,7 +602,7 @@ module Spree
|
|
559
602
|
before { Spree::Order.delete_all }
|
560
603
|
it "still returns a root :orders key" do
|
561
604
|
api_get :index
|
562
|
-
json_response["orders"].
|
605
|
+
expect(json_response["orders"]).to eq([])
|
563
606
|
end
|
564
607
|
end
|
565
608
|
|
@@ -612,20 +655,20 @@ module Spree
|
|
612
655
|
|
613
656
|
it "can view all orders" do
|
614
657
|
api_get :index
|
615
|
-
json_response["orders"].first.
|
616
|
-
json_response["count"].
|
617
|
-
json_response["current_page"].
|
618
|
-
json_response["pages"].
|
658
|
+
expect(json_response["orders"].first).to have_attributes(attributes)
|
659
|
+
expect(json_response["count"]).to eq(2)
|
660
|
+
expect(json_response["current_page"]).to eq(1)
|
661
|
+
expect(json_response["pages"]).to eq(1)
|
619
662
|
end
|
620
663
|
|
621
664
|
# Test for #1763
|
622
665
|
it "can control the page size through a parameter" do
|
623
666
|
api_get :index, :per_page => 1
|
624
|
-
json_response["orders"].count.
|
625
|
-
json_response["orders"].first.
|
626
|
-
json_response["count"].
|
627
|
-
json_response["current_page"].
|
628
|
-
json_response["pages"].
|
667
|
+
expect(json_response["orders"].count).to eq(1)
|
668
|
+
expect(json_response["orders"].first).to have_attributes(attributes)
|
669
|
+
expect(json_response["count"]).to eq(1)
|
670
|
+
expect(json_response["current_page"]).to eq(1)
|
671
|
+
expect(json_response["pages"]).to eq(2)
|
629
672
|
end
|
630
673
|
end
|
631
674
|
|
@@ -639,21 +682,21 @@ module Spree
|
|
639
682
|
|
640
683
|
it "can query the results through a parameter" do
|
641
684
|
api_get :index, :q => { :email_cont => 'spree' }
|
642
|
-
json_response["orders"].count.
|
643
|
-
json_response["orders"].first.
|
644
|
-
json_response["orders"].first["email"].
|
645
|
-
json_response["count"].
|
646
|
-
json_response["current_page"].
|
647
|
-
json_response["pages"].
|
685
|
+
expect(json_response["orders"].count).to eq(1)
|
686
|
+
expect(json_response["orders"].first).to have_attributes(attributes)
|
687
|
+
expect(json_response["orders"].first["email"]).to eq(expected_result.email)
|
688
|
+
expect(json_response["count"]).to eq(1)
|
689
|
+
expect(json_response["current_page"]).to eq(1)
|
690
|
+
expect(json_response["pages"]).to eq(1)
|
648
691
|
end
|
649
692
|
end
|
650
693
|
|
651
694
|
context "creation" do
|
652
695
|
it "can create an order without any parameters" do
|
653
|
-
|
654
|
-
response.status.
|
696
|
+
expect { api_post :create }.not_to raise_error
|
697
|
+
expect(response.status).to eq(201)
|
655
698
|
order = Order.last
|
656
|
-
json_response["state"].
|
699
|
+
expect(json_response["state"]).to eq("cart")
|
657
700
|
end
|
658
701
|
|
659
702
|
it "can arbitrarily set the line items price" do
|
@@ -672,7 +715,7 @@ module Spree
|
|
672
715
|
user = Spree.user_class.create
|
673
716
|
api_post :create, :order => { user_id: user.id }
|
674
717
|
expect(response.status).to eq 201
|
675
|
-
json_response["user_id"].
|
718
|
+
expect(json_response["user_id"]).to eq(user.id)
|
676
719
|
end
|
677
720
|
end
|
678
721
|
|
@@ -681,7 +724,7 @@ module Spree
|
|
681
724
|
user = Spree.user_class.create
|
682
725
|
api_post :update, :id => order.number, :order => { user_id: user.id }
|
683
726
|
expect(response.status).to eq 200
|
684
|
-
json_response["user_id"].
|
727
|
+
expect(json_response["user_id"]).to eq(user.id)
|
685
728
|
end
|
686
729
|
end
|
687
730
|
|
@@ -697,7 +740,7 @@ module Spree
|
|
697
740
|
|
698
741
|
specify do
|
699
742
|
api_put :cancel, :id => order.to_param
|
700
|
-
json_response["state"].
|
743
|
+
expect(json_response["state"]).to eq("canceled")
|
701
744
|
end
|
702
745
|
end
|
703
746
|
end
|