solidus_api 2.1.1 → 2.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_api might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1de6bd3074f0732a5a2981a9357923fdafeed688
4
- data.tar.gz: f9c892017071238dd6677d65850650e104d179e8
3
+ metadata.gz: b950a6d9f7c428116e5210e27a72d5fb07df830a
4
+ data.tar.gz: 2ce2d4e97ae5f016c16adc9769a70f1cd52e5317
5
5
  SHA512:
6
- metadata.gz: c019fe80b3975012c74245da544d6ff96c13644ba271cd9ecfb34bdf993c09250d897a6ab255ade2a816cce55951ef21f8eb1c244991df9f95e2a8ef12f7a5dc
7
- data.tar.gz: 663ae49c937ad78351ba05979a49504fa02d1925eb185b8c794ba7ae1fd76ec67f122f3e974639efb51d8780d1a10f43db9e5fb642f8a7fc333fbde1ba2922d0
6
+ metadata.gz: 2685ca4dcbc794549d239d4c3129f76d9b1acf56903a5d4cf2ecab8d64e2778deac7dee07bbd923b42f405778db49c7164f4a32f22747100dddb6c6409e8ada6
7
+ data.tar.gz: 74a05940e48b28abd813beaa2fc56902b1f59657128dd312fe77016c22e2abf79887311dca22e7417d21b9064d039728dae9776254a96c8c4677bb62220335d9
@@ -116,13 +116,13 @@ module Spree
116
116
 
117
117
  def product_scope
118
118
  if can?(:admin, Spree::Product)
119
- scope = Product.with_deleted.accessible_by(current_ability, :read).includes(*product_includes)
119
+ scope = Spree::Product.with_deleted.accessible_by(current_ability, :read).includes(*product_includes)
120
120
 
121
121
  unless params[:show_deleted]
122
122
  scope = scope.not_deleted
123
123
  end
124
124
  else
125
- scope = Product.accessible_by(current_ability, :read).available.includes(*product_includes)
125
+ scope = Spree::Product.accessible_by(current_ability, :read).available.includes(*product_includes)
126
126
  end
127
127
 
128
128
  scope
@@ -4,13 +4,13 @@ module Spree
4
4
  skip_before_action :authenticate_user
5
5
 
6
6
  def index
7
- @countries = Country.
7
+ @countries = Spree::Country.
8
8
  accessible_by(current_ability, :read).
9
9
  ransack(params[:q]).
10
10
  result.
11
11
  order('name ASC')
12
12
 
13
- country = Country.order("updated_at ASC").last
13
+ country = Spree::Country.order("updated_at ASC").last
14
14
 
15
15
  if stale?(country)
16
16
  @countries = paginate(@countries)
@@ -19,7 +19,7 @@ module Spree
19
19
  end
20
20
 
21
21
  def show
22
- @country = Country.accessible_by(current_ability, :read).find(params[:id])
22
+ @country = Spree::Country.accessible_by(current_ability, :read).find(params[:id])
23
23
  respond_with(@country)
24
24
  end
25
25
  end
@@ -7,7 +7,7 @@ module Spree
7
7
  end
8
8
 
9
9
  def show
10
- @image = Image.accessible_by(current_ability, :read).find(params[:id])
10
+ @image = Spree::Image.accessible_by(current_ability, :read).find(params[:id])
11
11
  respond_with(@image)
12
12
  end
13
13
 
@@ -24,7 +24,7 @@ module Spree
24
24
  private
25
25
 
26
26
  def inventory_unit
27
- @inventory_unit ||= InventoryUnit.accessible_by(current_ability, :read).find(params[:id])
27
+ @inventory_unit ||= Spree::InventoryUnit.accessible_by(current_ability, :read).find(params[:id])
28
28
  end
29
29
 
30
30
  def prepare_event
@@ -13,7 +13,7 @@ module Spree
13
13
  around_action :lock_order, except: [:create, :mine, :current, :index]
14
14
 
15
15
  # Dynamically defines our stores checkout steps to ensure we check authorization on each step.
16
- Order.checkout_steps.keys.each do |step|
16
+ Spree::Order.checkout_steps.keys.each do |step|
17
17
  define_method step do
18
18
  authorize! :update, @order, params[:token]
19
19
  end
@@ -27,18 +27,8 @@ module Spree
27
27
 
28
28
  def create
29
29
  authorize! :create, Order
30
-
31
- if can?(:admin, Order)
32
- @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
33
- respond_with(@order, default_template: :show, status: 201)
34
- else
35
- @order = Spree::Order.create!(user: current_api_user, store: current_store)
36
- if OrderUpdateAttributes.new(@order, order_params).apply
37
- respond_with(@order, default_template: :show, status: 201)
38
- else
39
- invalid_resource!(@order)
40
- end
41
- end
30
+ @order = Spree::Core::Importer::Order.import(determine_order_user, order_params)
31
+ respond_with(@order, default_template: :show, status: 201)
42
32
  end
43
33
 
44
34
  def empty
@@ -49,7 +39,7 @@ module Spree
49
39
 
50
40
  def index
51
41
  authorize! :index, Order
52
- @orders = paginate(Order.ransack(params[:q]).result)
42
+ @orders = paginate(Spree::Order.ransack(params[:q]).result)
53
43
  respond_with(@orders)
54
44
  end
55
45
 
@@ -16,7 +16,6 @@ module Spree
16
16
  end
17
17
 
18
18
  def create
19
- @order.validate_payments_attributes(payment_params)
20
19
  @payment = PaymentCreate.new(@order, payment_params).build
21
20
  if @payment.save
22
21
  respond_with(@payment, status: 201, default_template: :show)
@@ -123,7 +123,7 @@ module Spree
123
123
 
124
124
  def set_up_shipping_category
125
125
  if shipping_category = params[:product].delete(:shipping_category)
126
- id = ShippingCategory.find_or_create_by(name: shipping_category).id
126
+ id = Spree::ShippingCategory.find_or_create_by(name: shipping_category).id
127
127
  params[:product][:shipping_category_id] = id
128
128
  end
129
129
  end
@@ -95,11 +95,11 @@ module Spree
95
95
  private
96
96
 
97
97
  def load_transfer_params
98
- @original_shipment = Spree::Shipment.where(number: params[:original_shipment_number]).first
98
+ @original_shipment = Spree::Shipment.find_by!(number: params[:original_shipment_number])
99
99
  @order = @original_shipment.order
100
100
  @variant = Spree::Variant.find(params[:variant_id])
101
101
  @quantity = params[:quantity].to_i
102
- authorize! :read, @original_shipment
102
+ authorize! [:update, :destroy], @original_shipment
103
103
  authorize! :create, Shipment
104
104
  end
105
105
 
@@ -23,10 +23,10 @@ module Spree
23
23
 
24
24
  def scope
25
25
  if params[:country_id]
26
- @country = Country.accessible_by(current_ability, :read).find(params[:country_id])
26
+ @country = Spree::Country.accessible_by(current_ability, :read).find(params[:country_id])
27
27
  return @country.states.accessible_by(current_ability, :read)
28
28
  else
29
- return State.accessible_by(current_ability, :read)
29
+ return Spree::State.accessible_by(current_ability, :read)
30
30
  end
31
31
  end
32
32
  end
@@ -28,7 +28,7 @@ module Spree
28
28
  end
29
29
 
30
30
  def update
31
- @stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
31
+ @stock_item = Spree::StockItem.accessible_by(current_ability, :update).find(params[:id])
32
32
  @stock_location = @stock_item.stock_location
33
33
 
34
34
  adjustment = count_on_hand_adjustment
@@ -46,7 +46,7 @@ module Spree
46
46
  end
47
47
 
48
48
  def destroy
49
- @stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
49
+ @stock_item = Spree::StockItem.accessible_by(current_ability, :destroy).find(params[:id])
50
50
  @stock_item.destroy
51
51
  respond_with(@stock_item, status: 204)
52
52
  end
@@ -54,7 +54,7 @@ module Spree
54
54
  private
55
55
 
56
56
  def load_stock_location
57
- @stock_location ||= StockLocation.accessible_by(current_ability).find(params.fetch(:stock_location_id))
57
+ @stock_location ||= Spree::StockLocation.accessible_by(current_ability).find(params.fetch(:stock_location_id))
58
58
  end
59
59
 
60
60
  def scope
@@ -21,7 +21,7 @@ module Spree
21
21
 
22
22
  def create
23
23
  authorize! :create, StockLocation
24
- @stock_location = StockLocation.new(stock_location_params)
24
+ @stock_location = Spree::StockLocation.new(stock_location_params)
25
25
  if @stock_location.save
26
26
  respond_with(@stock_location, status: 201, default_template: :show)
27
27
  else
@@ -47,7 +47,7 @@ module Spree
47
47
  private
48
48
 
49
49
  def stock_location
50
- @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:id])
50
+ @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:id])
51
51
  end
52
52
 
53
53
  def stock_location_params
@@ -27,7 +27,7 @@ module Spree
27
27
  private
28
28
 
29
29
  def stock_location
30
- @stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
30
+ @stock_location ||= Spree::StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
31
31
  end
32
32
 
33
33
  def scope
@@ -5,13 +5,13 @@ module Spree
5
5
 
6
6
  def index
7
7
  authorize! :read, Store
8
- @stores = Store.accessible_by(current_ability, :read).all
8
+ @stores = Spree::Store.accessible_by(current_ability, :read).all
9
9
  respond_with(@stores)
10
10
  end
11
11
 
12
12
  def create
13
13
  authorize! :create, Store
14
- @store = Store.new(store_params)
14
+ @store = Spree::Store.new(store_params)
15
15
  @store.code = params[:store][:code]
16
16
  if @store.save
17
17
  respond_with(@store, status: 201, default_template: :show)
@@ -43,7 +43,7 @@ module Spree
43
43
  private
44
44
 
45
45
  def get_store
46
- @store = Store.find(params[:id])
46
+ @store = Spree::Store.find(params[:id])
47
47
  end
48
48
 
49
49
  def store_params
@@ -20,7 +20,7 @@ module Spree
20
20
 
21
21
  def create
22
22
  authorize! :create, Taxonomy
23
- @taxonomy = Taxonomy.new(taxonomy_params)
23
+ @taxonomy = Spree::Taxonomy.new(taxonomy_params)
24
24
  if @taxonomy.save
25
25
  respond_with(@taxonomy, status: 201, default_template: :show)
26
26
  else
@@ -55,7 +55,7 @@ module Spree
55
55
  end
56
56
 
57
57
  def taxonomy
58
- @taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
58
+ @taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:id])
59
59
  end
60
60
 
61
61
  def taxonomy_params
@@ -3,7 +3,7 @@ module Spree
3
3
  class TransferItemsController < Spree::Api::BaseController
4
4
  def create
5
5
  authorize! :create, TransferItem
6
- stock_transfer = StockTransfer.accessible_by(current_ability, :update).find_by(number: params[:stock_transfer_id])
6
+ stock_transfer = Spree::StockTransfer.accessible_by(current_ability, :update).find_by(number: params[:stock_transfer_id])
7
7
  @transfer_item = stock_transfer.transfer_items.build(transfer_item_params)
8
8
  if @transfer_item.save
9
9
  respond_with(@transfer_item, status: 201, default_template: :show)
@@ -14,7 +14,7 @@ module Spree
14
14
 
15
15
  def update
16
16
  authorize! :update, TransferItem
17
- @transfer_item = TransferItem.accessible_by(current_ability, :update).find(params[:id])
17
+ @transfer_item = Spree::TransferItem.accessible_by(current_ability, :update).find(params[:id])
18
18
  if @transfer_item.update_attributes(transfer_item_params)
19
19
  respond_with(@transfer_item, status: 200, default_template: :show)
20
20
  else
@@ -24,7 +24,7 @@ module Spree
24
24
 
25
25
  def destroy
26
26
  authorize! :destroy, TransferItem
27
- @transfer_item = TransferItem.accessible_by(current_ability, :destroy).find(params[:id])
27
+ @transfer_item = Spree::TransferItem.accessible_by(current_ability, :destroy).find(params[:id])
28
28
  if @transfer_item.destroy
29
29
  respond_with(@transfer_item, status: 200, default_template: :show)
30
30
  else
@@ -58,7 +58,7 @@ module Spree
58
58
  if @product
59
59
  variants = @product.variants_including_master
60
60
  else
61
- variants = Variant
61
+ variants = Spree::Variant
62
62
  end
63
63
 
64
64
  if current_ability.can?(:manage, Variant) && params[:show_deleted]
@@ -3,7 +3,7 @@ module Spree
3
3
  class ZonesController < Spree::Api::BaseController
4
4
  def create
5
5
  authorize! :create, Zone
6
- @zone = Zone.new(zone_params)
6
+ @zone = Spree::Zone.new(zone_params)
7
7
  if @zone.save
8
8
  respond_with(@zone, status: 201, default_template: :show)
9
9
  else
@@ -18,7 +18,7 @@ module Spree
18
18
  end
19
19
 
20
20
  def index
21
- @zones = Zone.
21
+ @zones = Spree::Zone.
22
22
  accessible_by(current_ability, :read).
23
23
  order('name ASC').
24
24
  ransack(params[:q]).
@@ -163,19 +163,6 @@ module Spree
163
163
  expect(response.status).to eq(200)
164
164
  end
165
165
 
166
- context "with disallowed payment method" do
167
- it "returns not found" do
168
- order.update_column(:state, "payment")
169
- allow_any_instance_of(Spree::Gateway::Bogus).to receive(:source_required?).and_return(false)
170
- @payment_method.update!(available_to_users: false)
171
- expect {
172
- api_put :update, id: order.to_param, order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
173
- }.not_to change { Spree::Payment.count }
174
- expect(response.status).to eq(404)
175
- end
176
- end
177
-
178
-
179
166
  it "returns errors when source is required and missing" do
180
167
  order.update_column(:state, "payment")
181
168
  api_put :update, id: order.to_param, order_token: order.guest_token,
@@ -281,7 +268,7 @@ module Spree
281
268
  payments_attributes: [
282
269
  {
283
270
  source_attributes: {
284
- existing_card_id: credit_card.id.to_s,
271
+ wallet_payment_source_id: wallet_payment_source.id.to_param,
285
272
  verification_value: '456'
286
273
  }
287
274
  }
@@ -290,7 +277,11 @@ module Spree
290
277
  }
291
278
  end
292
279
 
293
- let!(:credit_card) do
280
+ let!(:wallet_payment_source) do
281
+ order.user.wallet.add(credit_card)
282
+ end
283
+
284
+ let(:credit_card) do
294
285
  create(:credit_card, user_id: order.user_id, payment_method_id: @payment_method.id)
295
286
  end
296
287
 
@@ -307,6 +298,34 @@ module Spree
307
298
  expect(response.status).to eq 200
308
299
  expect(order.credit_cards).to match_array [credit_card]
309
300
  end
301
+
302
+ context 'with deprecated existing_card_id param' do
303
+ let(:params) do
304
+ {
305
+ id: order.to_param,
306
+ order_token: order.guest_token,
307
+ order: {
308
+ payments_attributes: [
309
+ {
310
+ source_attributes: {
311
+ existing_card_id: credit_card.id.to_param,
312
+ verification_value: '456'
313
+ }
314
+ }
315
+ ]
316
+ }
317
+ }
318
+ end
319
+
320
+ it 'succeeds' do
321
+ Spree::Deprecation.silence do
322
+ api_put(:update, params)
323
+ end
324
+
325
+ expect(response.status).to eq 200
326
+ expect(order.credit_cards).to match_array [credit_card]
327
+ end
328
+ end
310
329
  end
311
330
 
312
331
  it "returns the order if the order is already complete" do
@@ -402,7 +421,7 @@ module Spree
402
421
  end
403
422
 
404
423
  it "returns a sensible error when no payment method is specified" do
405
- # api_put :complete, :id => order.to_param, :order_token => order.token, :order => {}
424
+ # api_put :complete, id: order.to_param, order_token: order.token, order: {}
406
425
  subject
407
426
  expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
408
427
  end
@@ -411,7 +430,7 @@ module Spree
411
430
  let(:params) { super().merge(expected_total: order.total + 1) }
412
431
 
413
432
  it "returns an error if expected_total is present and does not match actual total" do
414
- # api_put :complete, :id => order.to_param, :order_token => order.token, :expected_total => order.total + 1
433
+ # api_put :complete, id: order.to_param, order_token: order.token, expected_total: order.total + 1
415
434
  subject
416
435
  expect(response.status).to eq(400)
417
436
  expect(json_response['errors']['expected_total']).to include(Spree.t(:expected_total_mismatch, scope: 'api.order'))
@@ -32,9 +32,8 @@ module Spree
32
32
  describe "POST create" do
33
33
  let(:target_user) { create :user }
34
34
  let(:date_override) { Time.parse('2015-01-01') }
35
- let(:attributes) { { user_id: target_user.id, created_at: date_override, email: target_user.email } }
36
35
 
37
- subject { api_post :create, order: attributes }
36
+ subject { api_post :create, order: { user_id: target_user.id, created_at: date_override, email: target_user.email } }
38
37
 
39
38
  context "when the current user cannot administrate the order" do
40
39
  stub_authorization! do |_|
@@ -43,37 +42,12 @@ module Spree
43
42
 
44
43
  it "does not include unpermitted params, or allow overriding the user", focus: true do
45
44
  subject
46
- expect(response).to be_success
47
45
  order = Spree::Order.last
48
46
  expect(order.user).to eq current_api_user
49
47
  expect(order.email).to eq target_user.email
50
48
  end
51
49
 
52
50
  it { is_expected.to be_success }
53
-
54
- context 'creating payment' do
55
- let(:attributes) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
56
-
57
- context "with allowed payment method" do
58
- let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
59
- it { is_expected.to be_success }
60
- it "creates a payment" do
61
- expect {
62
- subject
63
- }.to change { Spree::Payment.count }.by(1)
64
- end
65
- end
66
-
67
- context "with disallowed payment method" do
68
- let!(:payment_method) { create(:check_payment_method, name: "forbidden", available_to_users: false) }
69
- it { is_expected.to be_not_found }
70
- it "creates no payments" do
71
- expect {
72
- subject
73
- }.not_to change { Spree::Payment.count }
74
- end
75
- end
76
- end
77
51
  end
78
52
 
79
53
  context "when the current user can administrate the order" do
@@ -123,30 +97,6 @@ module Spree
123
97
  subject
124
98
  }.to_not change{ order.reload.number }
125
99
  end
126
-
127
- context 'creating payment' do
128
- let(:order_params) { super().merge(payments_attributes: [{ payment_method_id: payment_method.id }]) }
129
-
130
- context "with allowed payment method" do
131
- let!(:payment_method) { create(:check_payment_method, name: "allowed" ) }
132
- it { is_expected.to be_success }
133
- it "creates a payment" do
134
- expect {
135
- subject
136
- }.to change { Spree::Payment.count }.by(1)
137
- end
138
- end
139
-
140
- context "with disallowed payment method" do
141
- let!(:payment_method) { create(:check_payment_method, name: "forbidden", available_to_users: false) }
142
- it { is_expected.to be_not_found }
143
- it "creates no payments" do
144
- expect {
145
- subject
146
- }.not_to change { Spree::Payment.count }
147
- end
148
- end
149
- end
150
100
  end
151
101
 
152
102
  context "when the user can administer the order" do
@@ -383,7 +333,10 @@ module Spree
383
333
 
384
334
  # Regression test for https://github.com/spree/spree/issues/3404
385
335
  it "can specify additional parameters for a line item" do
386
- expect_any_instance_of(Spree::LineItem).to receive(:special=).with("foo")
336
+ expect(Order).to receive(:create!).and_return(order = Spree::Order.new)
337
+ allow(order).to receive(:associate_user!)
338
+ allow(order).to receive_message_chain(:contents, :add).and_return(line_item = double('LineItem'))
339
+ expect(line_item).to receive(:update_attributes!).with(hash_including("special" => "foo"))
387
340
 
388
341
  allow(controller).to receive_messages(permitted_line_item_attributes: [:id, :variant_id, :quantity, :special])
389
342
  api_post :create, order: {
@@ -45,17 +45,6 @@ module Spree
45
45
  expect(response.status).to eq(201)
46
46
  expect(json_response).to have_attributes(attributes)
47
47
  end
48
-
49
- context "disallowed payment method" do
50
- it "does not create a new payment" do
51
- PaymentMethod.first.update!(available_to_users: false)
52
-
53
- expect {
54
- api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }
55
- }.not_to change { Spree::Payment.count }
56
- expect(response.status).to eq(404)
57
- end
58
- end
59
48
  end
60
49
 
61
50
  context "payment source is required" do
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Spree::Api::ShipmentsController, type: :request do
4
+ let(:user) { create(:admin_user, spree_api_key: 'abc123') }
5
+ let(:stock_item) { create(:stock_item, backorderable: false) }
6
+ let(:variant) { stock_item.variant }
7
+
8
+ let(:order) do
9
+ create(
10
+ :completed_order_with_totals,
11
+ user: user,
12
+ line_items_attributes: [
13
+ {
14
+ variant: variant
15
+ }
16
+ ]
17
+ )
18
+ end
19
+
20
+ let(:shipment) { order.shipments.first }
21
+
22
+ describe "POST /api/shipments/transfer_to_location" do
23
+ let(:stock_location) { create(:stock_location) }
24
+ let(:source_shipment) { order.shipments.first }
25
+ let(:parsed_response) { JSON.parse(response.body) }
26
+ let(:stock_location_id) { stock_location.id }
27
+
28
+ subject do
29
+ post "/api/shipments/transfer_to_location.json",
30
+ params: {
31
+ original_shipment_number: source_shipment.number,
32
+ stock_location_id: stock_location_id,
33
+ quantity: 1,
34
+ variant_id: variant.id,
35
+ token: user.spree_api_key
36
+ }
37
+ end
38
+
39
+ context "for a successful transfer" do
40
+ before do
41
+ stock_location.restock(variant, 1)
42
+ end
43
+
44
+ it "returns the correct message" do
45
+ subject
46
+ expect(response).to be_success
47
+ expect(parsed_response["success"]).to be true
48
+ expect(parsed_response["message"]).to eq("Variants successfully transferred")
49
+ end
50
+ end
51
+
52
+ context "if the source shipment can not be found" do
53
+ let(:stock_location_id) { 9999 }
54
+
55
+ it "returns a 404" do
56
+ subject
57
+ expect(response).to be_not_found
58
+ expect(parsed_response["error"]).to eq("The resource you were looking for could not be found.")
59
+ end
60
+ end
61
+
62
+ context "if the user can not update shipments" do
63
+ let(:user) { create(:user, spree_api_key: 'abc123') }
64
+
65
+ custom_authorization! do |_|
66
+ can :read, Spree::Shipment
67
+ cannot :update, Spree::Shipment
68
+ can :create, Spree::Shipment
69
+ can :destroy, Spree::Shipment
70
+ end
71
+
72
+ it "is not authorized" do
73
+ subject
74
+ expect(response).to be_unauthorized
75
+ end
76
+ end
77
+
78
+ context "if the user can not destroy shipments" do
79
+ let(:user) { create(:user, spree_api_key: 'abc123') }
80
+
81
+ custom_authorization! do |_|
82
+ can :read, Spree::Shipment
83
+ can :update, Spree::Shipment
84
+ cannot :destroy, Spree::Shipment
85
+ can :create, Spree::Shipment
86
+ end
87
+
88
+ it "is not authorized" do
89
+ subject
90
+ expect(response).to be_unauthorized
91
+ end
92
+ end
93
+ end
94
+
95
+ describe "POST /api/shipments/transfer_to_shipment" do
96
+ let(:stock_location) { create(:stock_location) }
97
+ let(:source_shipment) { order.shipments.first }
98
+ let(:target_shipment) { order.shipments.create(stock_location: stock_location) }
99
+ let(:parsed_response) { JSON.parse(response.body) }
100
+ let(:source_shipment_number) { source_shipment.number }
101
+
102
+ subject do
103
+ post "/api/shipments/transfer_to_shipment.json",
104
+ params: {
105
+ original_shipment_number: source_shipment_number,
106
+ target_shipment_number: target_shipment.number,
107
+ quantity: 1,
108
+ variant_id: variant.id,
109
+ token: user.spree_api_key
110
+ }
111
+ end
112
+
113
+ context "for a successful transfer" do
114
+ before do
115
+ stock_location.restock(variant, 1)
116
+ end
117
+
118
+ it "returns the correct message" do
119
+ subject
120
+ expect(response).to be_success
121
+ expect(parsed_response["success"]).to be true
122
+ expect(parsed_response["message"]).to eq("Variants successfully transferred")
123
+ end
124
+ end
125
+
126
+ context "if the source shipment can not be found" do
127
+ let(:source_shipment_number) { 9999 }
128
+
129
+ it "returns a 404" do
130
+ subject
131
+ expect(response).to be_not_found
132
+ expect(parsed_response["error"]).to eq("The resource you were looking for could not be found.")
133
+ end
134
+ end
135
+ end
136
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-12 00:00:00.000000000 Z
11
+ date: 2017-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.1
19
+ version: 2.2.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.1
26
+ version: 2.2.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rabl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -252,6 +252,7 @@ files:
252
252
  - spec/requests/api/address_books_spec.rb
253
253
  - spec/requests/rabl_cache_spec.rb
254
254
  - spec/requests/ransackable_attributes_spec.rb
255
+ - spec/requests/spree/api/shipments_controller_spec.rb
255
256
  - spec/shared_examples/protect_product_actions.rb
256
257
  - spec/spec_helper.rb
257
258
  - spec/support/controller_hacks.rb
@@ -280,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
280
281
  version: 1.8.23
281
282
  requirements: []
282
283
  rubyforge_project:
283
- rubygems_version: 2.6.11
284
+ rubygems_version: 2.6.10
284
285
  signing_key:
285
286
  specification_version: 4
286
287
  summary: REST API for the Solidus e-commerce framework.
@@ -327,6 +328,7 @@ test_files:
327
328
  - spec/requests/api/address_books_spec.rb
328
329
  - spec/requests/rabl_cache_spec.rb
329
330
  - spec/requests/ransackable_attributes_spec.rb
331
+ - spec/requests/spree/api/shipments_controller_spec.rb
330
332
  - spec/shared_examples/protect_product_actions.rb
331
333
  - spec/spec_helper.rb
332
334
  - spec/support/controller_hacks.rb