spree_api 2.3.13 → 2.4.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -43
- data/Gemfile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +1 -1
- data/app/controllers/spree/api/base_controller.rb +22 -9
- data/app/controllers/spree/api/checkouts_controller.rb +2 -2
- data/app/controllers/spree/api/countries_controller.rb +2 -2
- data/app/controllers/spree/api/credit_cards_controller.rb +1 -1
- data/app/controllers/spree/api/images_controller.rb +5 -0
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/line_items_controller.rb +7 -7
- data/app/controllers/spree/api/option_types_controller.rb +2 -2
- data/app/controllers/spree/api/orders_controller.rb +17 -6
- data/app/controllers/spree/api/payments_controller.rb +3 -11
- data/app/controllers/spree/api/product_properties_controller.rb +2 -2
- data/app/controllers/spree/api/promotions_controller.rb +26 -0
- data/app/controllers/spree/api/properties_controller.rb +1 -1
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -10
- data/app/controllers/spree/api/shipments_controller.rb +71 -4
- data/app/controllers/spree/api/states_controller.rb +3 -3
- data/app/controllers/spree/api/stock_items_controller.rb +1 -1
- data/app/controllers/spree/api/stock_movements_controller.rb +1 -1
- data/app/controllers/spree/api/taxons_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +1 -2
- data/app/helpers/spree/api/api_helpers.rb +19 -5
- data/app/views/spree/api/images/index.v1.rabl +4 -0
- data/app/views/spree/api/products/show.v1.rabl +4 -1
- data/app/views/spree/api/promotions/handler.v1.rabl +2 -1
- data/app/views/spree/api/promotions/show.v1.rabl +2 -0
- data/app/views/spree/api/shipments/big.v1.rabl +48 -0
- data/app/views/spree/api/shipments/mine.v1.rabl +9 -0
- data/app/views/spree/api/shipments/small.v1.rabl +1 -5
- data/app/views/spree/api/shipping_rates/show.v1.rabl +2 -2
- data/app/views/spree/api/taxonomies/show.v1.rabl +2 -2
- data/app/views/spree/api/variants/big.v1.rabl +6 -1
- data/app/views/spree/api/variants/show.v1.rabl +1 -1
- data/app/views/spree/api/variants/small.v1.rabl +2 -3
- data/config/routes.rb +9 -0
- data/lib/spree/api/responders/rabl_template.rb +1 -1
- 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 +7 -7
- data/spec/controllers/spree/api/base_controller_spec.rb +66 -19
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +54 -54
- 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 +37 -11
- data/spec/controllers/spree/api/inventory_units_controller_spec.rb +6 -6
- data/spec/controllers/spree/api/line_items_controller_spec.rb +34 -35
- data/spec/controllers/spree/api/option_types_controller_spec.rb +18 -18
- data/spec/controllers/spree/api/option_values_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/orders_controller_spec.rb +177 -161
- data/spec/controllers/spree/api/payments_controller_spec.rb +52 -89
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +21 -21
- data/spec/controllers/spree/api/products_controller_spec.rb +103 -60
- data/spec/controllers/spree/api/promotion_application_spec.rb +14 -12
- data/spec/controllers/spree/api/promotions_controller_spec.rb +64 -0
- data/spec/controllers/spree/api/properties_controller_spec.rb +25 -25
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +42 -66
- data/spec/controllers/spree/api/shipments_controller_spec.rb +69 -21
- 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 +5 -5
- data/spec/controllers/spree/api/users_controller_spec.rb +41 -41
- data/spec/controllers/spree/api/variants_controller_spec.rb +47 -37
- data/spec/controllers/spree/api/zones_controller_spec.rb +40 -18
- data/spec/models/spree/legacy_user_spec.rb +5 -5
- data/spec/requests/rabl_cache_spec.rb +9 -9
- data/spec/spec_helper.rb +1 -0
- metadata +14 -9
- data/spec/requests/ransackable_attributes_spec.rb +0 -79
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Spree
|
4
|
-
describe Spree::Api::PaymentsController
|
4
|
+
describe Spree::Api::PaymentsController do
|
5
5
|
render_views
|
6
6
|
let!(:order) { create(:order) }
|
7
7
|
let!(:payment) { create(:payment, :order => order) }
|
8
8
|
let!(:attributes) { [:id, :source_type, :source_id, :amount, :display_amount,
|
9
|
-
:payment_method_id, :state, :avs_response,
|
9
|
+
:payment_method_id, :response_code, :state, :avs_response,
|
10
10
|
:created_at, :updated_at] }
|
11
11
|
|
12
12
|
let(:resource_scoping) { { :order_id => order.to_param } }
|
@@ -18,30 +18,30 @@ module Spree
|
|
18
18
|
context "as a user" do
|
19
19
|
context "when the order belongs to the user" do
|
20
20
|
before do
|
21
|
-
|
21
|
+
Order.any_instance.stub :user => current_api_user
|
22
22
|
end
|
23
23
|
|
24
24
|
it "can view the payments for their order" do
|
25
25
|
api_get :index
|
26
|
-
|
26
|
+
json_response["payments"].first.should have_attributes(attributes)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "can learn how to create a new payment" do
|
30
30
|
api_get :new
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
json_response["attributes"].should == attributes.map(&:to_s)
|
32
|
+
json_response["payment_methods"].should_not be_empty
|
33
|
+
json_response["payment_methods"].first.should have_attributes([:id, :name, :description])
|
34
34
|
end
|
35
35
|
|
36
36
|
it "can create a new payment" do
|
37
37
|
api_post :create, :payment => { :payment_method_id => PaymentMethod.first.id, :amount => 50 }
|
38
|
-
|
39
|
-
|
38
|
+
response.status.should == 201
|
39
|
+
json_response.should have_attributes(attributes)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "can view a pre-existing payment's details" do
|
43
43
|
api_get :show, :id => payment.to_param
|
44
|
-
|
44
|
+
json_response.should have_attributes(attributes)
|
45
45
|
end
|
46
46
|
|
47
47
|
it "cannot update a payment" do
|
@@ -57,7 +57,7 @@ module Spree
|
|
57
57
|
|
58
58
|
context "when the order does not belong to the user" do
|
59
59
|
before do
|
60
|
-
|
60
|
+
Order.any_instance.stub :user => stub_model(LegacyUser)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "cannot view payments for somebody else's order" do
|
@@ -67,7 +67,7 @@ module Spree
|
|
67
67
|
|
68
68
|
it "can view the payments for an order given the order token" do
|
69
69
|
api_get :index, :order_id => order.to_param, :order_token => order.guest_token
|
70
|
-
|
70
|
+
json_response["payments"].first.should have_attributes(attributes)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
@@ -77,59 +77,54 @@ module Spree
|
|
77
77
|
|
78
78
|
it "can view the payments on any order" do
|
79
79
|
api_get :index
|
80
|
-
|
81
|
-
|
80
|
+
response.status.should == 200
|
81
|
+
json_response["payments"].first.should have_attributes(attributes)
|
82
82
|
end
|
83
83
|
|
84
84
|
context "multiple payments" do
|
85
|
-
before { @payment = create(:payment, :order => order) }
|
85
|
+
before { @payment = create(:payment, :order => order, :response_code => '99999') }
|
86
86
|
|
87
87
|
it "can view all payments on an order" do
|
88
88
|
api_get :index
|
89
|
-
|
89
|
+
json_response["count"].should == 2
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'can control the page size through a parameter' do
|
93
93
|
api_get :index, :per_page => 1
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
json_response['count'].should == 1
|
95
|
+
json_response['current_page'].should == 1
|
96
|
+
json_response['pages'].should == 2
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'can query the results through a paramter' do
|
100
|
+
api_get :index, :q => { :response_code_cont => '999' }
|
101
|
+
json_response['count'].should == 1
|
102
|
+
json_response['payments'].first['response_code'].should eq @payment.response_code
|
97
103
|
end
|
98
104
|
end
|
99
105
|
|
100
106
|
context "for a given payment" do
|
101
107
|
context "updating" do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
expect(payment.reload.amount).to eq(2.01)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
context "when the state is pending" do
|
112
|
-
it "can update" do
|
113
|
-
payment.update_attributes(state: 'pending')
|
114
|
-
api_put(:update, id: payment.to_param, payment: { amount: 2.01 })
|
115
|
-
expect(response.status).to be(200)
|
116
|
-
expect(payment.reload.amount).to eq(2.01)
|
117
|
-
end
|
108
|
+
it "can update" do
|
109
|
+
payment.update_attributes(:state => 'pending')
|
110
|
+
api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
|
111
|
+
response.status.should == 200
|
112
|
+
payment.reload.amount.should == 2.01
|
118
113
|
end
|
119
114
|
|
120
115
|
context "update fails" do
|
121
116
|
it "returns a 422 status when the amount is invalid" do
|
122
|
-
payment.update_attributes(state
|
123
|
-
api_put
|
124
|
-
|
125
|
-
|
117
|
+
payment.update_attributes(:state => 'pending')
|
118
|
+
api_put :update, :id => payment.to_param, :payment => { :amount => 'invalid' }
|
119
|
+
response.status.should == 422
|
120
|
+
json_response["error"].should == "Invalid resource. Please fix errors and try again."
|
126
121
|
end
|
127
122
|
|
128
123
|
it "returns a 403 status when the payment is not pending" do
|
129
|
-
payment.update_attributes(state
|
130
|
-
api_put
|
131
|
-
|
132
|
-
|
124
|
+
payment.update_attributes(:state => 'completed')
|
125
|
+
api_put :update, :id => payment.to_param, :payment => { :amount => 2.01 }
|
126
|
+
response.status.should == 403
|
127
|
+
json_response["error"].should == "This payment cannot be updated because it is completed."
|
133
128
|
end
|
134
129
|
end
|
135
130
|
end
|
@@ -137,26 +132,26 @@ module Spree
|
|
137
132
|
context "authorizing" do
|
138
133
|
it "can authorize" do
|
139
134
|
api_put :authorize, :id => payment.to_param
|
140
|
-
|
141
|
-
|
135
|
+
response.status.should == 200
|
136
|
+
payment.reload.state.should == "pending"
|
142
137
|
end
|
143
138
|
|
144
139
|
context "authorization fails" do
|
145
140
|
before do
|
146
141
|
fake_response = double(:success? => false, :to_s => "Could not authorize card")
|
147
|
-
|
142
|
+
Spree::Gateway::Bogus.any_instance.should_receive(:authorize).and_return(fake_response)
|
148
143
|
api_put :authorize, :id => payment.to_param
|
149
144
|
end
|
150
145
|
|
151
146
|
it "returns a 422 status" do
|
152
|
-
|
147
|
+
response.status.should == 422
|
153
148
|
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
154
149
|
expect(json_response["errors"]["base"][0]).to eq "Could not authorize card"
|
155
150
|
end
|
156
151
|
|
157
152
|
it "does not raise a stack level error" do
|
158
153
|
skip "Investigate why a payment.reload after the request raises 'stack level too deep'"
|
159
|
-
|
154
|
+
payment.reload.state.should == "failed"
|
160
155
|
end
|
161
156
|
end
|
162
157
|
end
|
@@ -164,19 +159,19 @@ module Spree
|
|
164
159
|
context "capturing" do
|
165
160
|
it "can capture" do
|
166
161
|
api_put :capture, :id => payment.to_param
|
167
|
-
|
168
|
-
|
162
|
+
response.status.should == 200
|
163
|
+
payment.reload.state.should == "completed"
|
169
164
|
end
|
170
165
|
|
171
166
|
context "capturing fails" do
|
172
167
|
before do
|
173
168
|
fake_response = double(:success? => false, :to_s => "Insufficient funds")
|
174
|
-
|
169
|
+
Spree::Gateway::Bogus.any_instance.should_receive(:capture).and_return(fake_response)
|
175
170
|
end
|
176
171
|
|
177
172
|
it "returns a 422 status" do
|
178
173
|
api_put :capture, :id => payment.to_param
|
179
|
-
|
174
|
+
response.status.should == 422
|
180
175
|
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
181
176
|
expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
|
182
177
|
end
|
@@ -186,19 +181,19 @@ module Spree
|
|
186
181
|
context "purchasing" do
|
187
182
|
it "can purchase" do
|
188
183
|
api_put :purchase, :id => payment.to_param
|
189
|
-
|
190
|
-
|
184
|
+
response.status.should == 200
|
185
|
+
payment.reload.state.should == "completed"
|
191
186
|
end
|
192
187
|
|
193
188
|
context "purchasing fails" do
|
194
189
|
before do
|
195
190
|
fake_response = double(:success? => false, :to_s => "Insufficient funds")
|
196
|
-
|
191
|
+
Spree::Gateway::Bogus.any_instance.should_receive(:purchase).and_return(fake_response)
|
197
192
|
end
|
198
193
|
|
199
194
|
it "returns a 422 status" do
|
200
195
|
api_put :purchase, :id => payment.to_param
|
201
|
-
|
196
|
+
response.status.should == 422
|
202
197
|
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
203
198
|
expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
|
204
199
|
end
|
@@ -215,7 +210,7 @@ module Spree
|
|
215
210
|
context "voiding fails" do
|
216
211
|
before do
|
217
212
|
fake_response = double(success?: false, to_s: "NO REFUNDS")
|
218
|
-
|
213
|
+
Spree::Gateway::Bogus.any_instance.should_receive(:void).and_return(fake_response)
|
219
214
|
end
|
220
215
|
|
221
216
|
it "returns a 422 status" do
|
@@ -228,38 +223,6 @@ module Spree
|
|
228
223
|
end
|
229
224
|
end
|
230
225
|
|
231
|
-
context "crediting" do
|
232
|
-
before do
|
233
|
-
payment.purchase!
|
234
|
-
end
|
235
|
-
|
236
|
-
it "can credit" do
|
237
|
-
api_put :credit, :id => payment.to_param
|
238
|
-
expect(response.status).to eq(200)
|
239
|
-
expect(payment.reload.state).to eq("completed")
|
240
|
-
|
241
|
-
# Ensure that a credit payment was created, and it has correct credit amount
|
242
|
-
credit_payment = Payment.where(:source_type => 'Spree::Payment', :source_id => payment.id).last
|
243
|
-
expect(credit_payment.amount.to_f).to eq(-45.75)
|
244
|
-
end
|
245
|
-
|
246
|
-
context "crediting fails" do
|
247
|
-
it "returns a 422 status" do
|
248
|
-
fake_response = double(:success? => false, :to_s => "NO CREDIT FOR YOU")
|
249
|
-
expect_any_instance_of(Spree::Gateway::Bogus).to receive(:credit).and_return(fake_response)
|
250
|
-
api_put :credit, :id => payment.to_param
|
251
|
-
expect(response.status).to eq(422)
|
252
|
-
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
|
253
|
-
expect(json_response["errors"]["base"][0]).to eq "NO CREDIT FOR YOU"
|
254
|
-
end
|
255
|
-
|
256
|
-
it "cannot credit over credit_allowed limit" do
|
257
|
-
api_put :credit, :id => payment.to_param, :amount => 1000000
|
258
|
-
expect(response.status).to eq(422)
|
259
|
-
expect(json_response["error"]).to eq("This payment can only be credited up to 45.75. Please specify an amount less than or equal to this number.")
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
226
|
end
|
264
227
|
end
|
265
228
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'shared_examples/protect_product_actions'
|
3
3
|
|
4
4
|
module Spree
|
5
|
-
describe Spree::Api::ProductPropertiesController
|
5
|
+
describe Spree::Api::ProductPropertiesController do
|
6
6
|
render_views
|
7
7
|
|
8
8
|
let!(:product) { create(:product) }
|
@@ -23,40 +23,40 @@ module Spree
|
|
23
23
|
|
24
24
|
it "can not see a list of product properties" do
|
25
25
|
api_get :index
|
26
|
-
|
26
|
+
response.status.should == 404
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
it "can see a list of all product properties" do
|
31
31
|
api_get :index
|
32
|
-
|
33
|
-
|
32
|
+
json_response["product_properties"].count.should eq 2
|
33
|
+
json_response["product_properties"].first.should have_attributes(attributes)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "can control the page size through a parameter" do
|
37
37
|
api_get :index, :per_page => 1
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
json_response['product_properties'].count.should == 1
|
39
|
+
json_response['current_page'].should == 1
|
40
|
+
json_response['pages'].should == 2
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'can query the results through a parameter' do
|
44
44
|
Spree::ProductProperty.last.update_attribute(:value, 'loose')
|
45
45
|
property = Spree::ProductProperty.last
|
46
46
|
api_get :index, :q => { :value_cont => 'loose' }
|
47
|
-
|
48
|
-
|
47
|
+
json_response['count'].should == 1
|
48
|
+
json_response['product_properties'].first['value'].should eq property.value
|
49
49
|
end
|
50
50
|
|
51
51
|
it "can see a single product_property" do
|
52
52
|
api_get :show, :id => property_1.property_name
|
53
|
-
|
53
|
+
json_response.should have_attributes(attributes)
|
54
54
|
end
|
55
55
|
|
56
56
|
it "can learn how to create a new product property" do
|
57
57
|
api_get :new
|
58
|
-
|
59
|
-
|
58
|
+
json_response["attributes"].should == attributes.map(&:to_s)
|
59
|
+
json_response["required_attributes"].should be_empty
|
60
60
|
end
|
61
61
|
|
62
62
|
it "cannot create a new product property if not an admin" do
|
@@ -72,7 +72,7 @@ module Spree
|
|
72
72
|
it "cannot delete a product property" do
|
73
73
|
api_delete :destroy, :property_name => property_1.property_name
|
74
74
|
assert_unauthorized!
|
75
|
-
|
75
|
+
lambda { property_1.reload }.should_not raise_error
|
76
76
|
end
|
77
77
|
|
78
78
|
context "as an admin" do
|
@@ -82,19 +82,19 @@ module Spree
|
|
82
82
|
expect do
|
83
83
|
api_post :create, :product_property => { :property_name => "My Property 3", :value => "my value 3" }
|
84
84
|
end.to change(product.product_properties, :count).by(1)
|
85
|
-
|
86
|
-
|
85
|
+
json_response.should have_attributes(attributes)
|
86
|
+
response.status.should == 201
|
87
87
|
end
|
88
88
|
|
89
89
|
it "can update a product property" do
|
90
90
|
api_put :update, :id => property_1.property_name, :product_property => { :value => "my value 456" }
|
91
|
-
|
91
|
+
response.status.should == 200
|
92
92
|
end
|
93
93
|
|
94
94
|
it "can delete a product property" do
|
95
95
|
api_delete :destroy, :id => property_1.property_name
|
96
|
-
|
97
|
-
|
96
|
+
response.status.should == 204
|
97
|
+
lambda { property_1.reload }.should raise_error(ActiveRecord::RecordNotFound)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -102,13 +102,13 @@ module Spree
|
|
102
102
|
let(:resource_scoping) { { :product_id => product.id } }
|
103
103
|
it "can see a list of all product properties" do
|
104
104
|
api_get :index
|
105
|
-
|
106
|
-
|
105
|
+
json_response["product_properties"].count.should eq 2
|
106
|
+
json_response["product_properties"].first.should have_attributes(attributes)
|
107
107
|
end
|
108
108
|
|
109
109
|
it "can see a single product_property by id" do
|
110
110
|
api_get :show, :id => property_1.id
|
111
|
-
|
111
|
+
json_response.should have_attributes(attributes)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|