solidus_api 2.2.2 → 2.3.0.beta1
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.
Potentially problematic release.
This version of solidus_api might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/images_controller.rb +2 -2
- data/app/controllers/spree/api/line_items_controller.rb +2 -10
- data/app/controllers/spree/api/orders_controller.rb +2 -12
- data/app/controllers/spree/api/payments_controller.rb +0 -1
- data/app/controllers/spree/api/promotions_controller.rb +1 -1
- data/app/controllers/spree/api/variants_controller.rb +2 -1
- data/app/views/spree/api/orders/show.v1.rabl +2 -1
- data/lib/spree/api/testing_support/setup.rb +1 -1
- data/spec/controllers/spree/api/base_controller_spec.rb +7 -7
- data/spec/controllers/spree/api/resource_controller_spec.rb +16 -16
- data/spec/requests/api/address_books_spec.rb +1 -1
- data/spec/{controllers → requests}/spree/api/addresses_controller_spec.rb +6 -9
- data/spec/{controllers → requests}/spree/api/checkouts_controller_spec.rb +38 -69
- data/spec/{controllers → requests}/spree/api/classifications_controller_spec.rb +4 -4
- data/spec/{controllers → requests}/spree/api/config_controller_spec.rb +3 -4
- data/spec/{controllers → requests}/spree/api/countries_controller_spec.rb +6 -7
- data/spec/{controllers → requests}/spree/api/credit_cards_controller_spec.rb +8 -9
- data/spec/{controllers → requests}/spree/api/images_controller_spec.rb +19 -16
- data/spec/{controllers → requests}/spree/api/inventory_units_controller_spec.rb +17 -14
- data/spec/{controllers → requests}/spree/api/line_items_controller_spec.rb +32 -32
- data/spec/{controllers → requests}/spree/api/option_types_controller_spec.rb +27 -27
- data/spec/{controllers → requests}/spree/api/option_values_controller_spec.rb +32 -29
- data/spec/{controllers → requests}/spree/api/orders_controller_spec.rb +103 -133
- data/spec/{controllers → requests}/spree/api/payments_controller_spec.rb +30 -44
- data/spec/{controllers → requests}/spree/api/product_properties_controller_spec.rb +15 -17
- data/spec/{controllers → requests}/spree/api/products_controller_spec.rb +44 -43
- data/spec/{controllers → requests}/spree/api/promotion_application_spec.rb +3 -4
- data/spec/{controllers → requests}/spree/api/promotions_controller_spec.rb +8 -6
- data/spec/{controllers → requests}/spree/api/properties_controller_spec.rb +15 -16
- data/spec/{controllers → requests}/spree/api/return_authorizations_controller_spec.rb +19 -21
- data/spec/requests/spree/api/shipments_controller_spec.rb +394 -88
- data/spec/{controllers → requests}/spree/api/states_controller_spec.rb +8 -9
- data/spec/{controllers → requests}/spree/api/stock_items_controller_spec.rb +21 -21
- data/spec/{controllers → requests}/spree/api/stock_locations_controller_spec.rb +18 -20
- data/spec/{controllers → requests}/spree/api/stock_movements_controller_spec.rb +9 -12
- data/spec/{controllers → requests}/spree/api/stock_transfers_controller_spec.rb +2 -3
- data/spec/requests/spree/api/store_credit_events_controller_spec.rb +57 -0
- data/spec/{controllers → requests}/spree/api/stores_controller_spec.rb +19 -20
- data/spec/{controllers → requests}/spree/api/taxonomies_controller_spec.rb +14 -15
- data/spec/{controllers → requests}/spree/api/taxons_controller_spec.rb +17 -18
- data/spec/{controllers → requests}/spree/api/transfer_items_controller_spec.rb +7 -9
- data/spec/{controllers → requests}/spree/api/unauthenticated_products_controller_spec.rb +2 -3
- data/spec/{controllers → requests}/spree/api/users_controller_spec.rb +18 -19
- data/spec/{controllers → requests}/spree/api/variants_controller_spec.rb +70 -37
- data/spec/{controllers → requests}/spree/api/zones_controller_spec.rb +13 -14
- data/spec/shared_examples/protect_product_actions.rb +3 -3
- data/spec/spec_helper.rb +4 -1
- metadata +70 -72
- data/spec/controllers/spree/api/shipments_controller_spec.rb +0 -301
- data/spec/controllers/spree/api/store_credit_events_controller_spec.rb +0 -66
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 928c0cebd7463ee3e18cfc1908bf8ca8159bed63
         | 
| 4 | 
            +
              data.tar.gz: ce51986e249ddbdbba441aa0f2129fcb5d4d7566
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: cf5bce9111f255c90f026c5b5ea8197782be2376bf13196717f3cc499dc7c9a4ee70181d358391489463329afae41393887f4460ae60bf5bb619a833e49b4656
         | 
| 7 | 
            +
              data.tar.gz: a10878a8da640034946b6fc4c20933814022bd542aa6ad8b0973bb20cdf5810d512c9a1d659cd618f049cedf5134fec625cdbee27460c346f81898081e98b86b
         | 
| @@ -18,13 +18,13 @@ module Spree | |
| 18 18 | 
             
                  end
         | 
| 19 19 |  | 
| 20 20 | 
             
                  def update
         | 
| 21 | 
            -
                    @image =  | 
| 21 | 
            +
                    @image = Spree::Image.accessible_by(current_ability, :update).find(params[:id])
         | 
| 22 22 | 
             
                    @image.update_attributes(image_params)
         | 
| 23 23 | 
             
                    respond_with(@image, default_template: :show)
         | 
| 24 24 | 
             
                  end
         | 
| 25 25 |  | 
| 26 26 | 
             
                  def destroy
         | 
| 27 | 
            -
                    @image =  | 
| 27 | 
            +
                    @image = Spree::Image.accessible_by(current_ability, :destroy).find(params[:id])
         | 
| 28 28 | 
             
                    @image.destroy
         | 
| 29 29 | 
             
                    respond_with(@image, status: 204)
         | 
| 30 30 | 
             
                  end
         | 
| @@ -1,10 +1,6 @@ | |
| 1 1 | 
             
            module Spree
         | 
| 2 2 | 
             
              module Api
         | 
| 3 3 | 
             
                class LineItemsController < Spree::Api::BaseController
         | 
| 4 | 
            -
                  class_attribute :line_item_options
         | 
| 5 | 
            -
             | 
| 6 | 
            -
                  self.line_item_options = []
         | 
| 7 | 
            -
             | 
| 8 4 | 
             
                  before_action :load_order, only: [:create, :update, :destroy]
         | 
| 9 5 | 
             
                  around_action :lock_order, only: [:create, :update, :destroy]
         | 
| 10 6 |  | 
| @@ -18,7 +14,7 @@ module Spree | |
| 18 14 | 
             
                      params[:line_item][:quantity] || 1,
         | 
| 19 15 | 
             
                      {
         | 
| 20 16 | 
             
                        stock_location_quantities: params[:line_item][:stock_location_quantities]
         | 
| 21 | 
            -
                      }.merge(line_item_params[:options].to_h  | 
| 17 | 
            +
                      }.merge({ options: line_item_params[:options].to_h })
         | 
| 22 18 | 
             
                    )
         | 
| 23 19 |  | 
| 24 20 | 
             
                    if @line_item.errors.empty?
         | 
| @@ -66,11 +62,7 @@ module Spree | |
| 66 62 | 
             
                  end
         | 
| 67 63 |  | 
| 68 64 | 
             
                  def line_item_params
         | 
| 69 | 
            -
                    params.require(:line_item).permit(
         | 
| 70 | 
            -
                      :quantity,
         | 
| 71 | 
            -
                        :variant_id,
         | 
| 72 | 
            -
                        options: line_item_options
         | 
| 73 | 
            -
                    )
         | 
| 65 | 
            +
                    params.require(:line_item).permit(permitted_line_item_attributes)
         | 
| 74 66 | 
             
                  end
         | 
| 75 67 | 
             
                end
         | 
| 76 68 | 
             
              end
         | 
| @@ -27,18 +27,8 @@ module Spree | |
| 27 27 |  | 
| 28 28 | 
             
                  def create
         | 
| 29 29 | 
             
                    authorize! :create, Order
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                     | 
| 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
         | 
| @@ -20,7 +20,7 @@ module Spree | |
| 20 20 | 
             
                  end
         | 
| 21 21 |  | 
| 22 22 | 
             
                  def load_promotion
         | 
| 23 | 
            -
                    @promotion = Spree::Promotion. | 
| 23 | 
            +
                    @promotion = Spree::Promotion.find_by(id: params[:id]) || Spree::Promotion.with_coupon_code(params[:id])
         | 
| 24 24 | 
             
                  end
         | 
| 25 25 | 
             
                end
         | 
| 26 26 | 
             
              end
         | 
| @@ -65,8 +65,9 @@ module Spree | |
| 65 65 | 
             
                      variants = variants.with_deleted
         | 
| 66 66 | 
             
                    end
         | 
| 67 67 |  | 
| 68 | 
            +
                    in_stock_only = ActiveRecord::Type::Boolean.new.cast(params[:in_stock_only])
         | 
| 68 69 | 
             
                    variants = variants.accessible_by(current_ability, :read)
         | 
| 69 | 
            -
                    variants = variants.in_stock if  | 
| 70 | 
            +
                    variants = variants.in_stock if in_stock_only || cannot?(:view_out_of_stock, Spree::Variant)
         | 
| 70 71 | 
             
                    variants
         | 
| 71 72 | 
             
                  end
         | 
| 72 73 |  | 
| @@ -2,7 +2,8 @@ object @order | |
| 2 2 | 
             
            extends "spree/api/orders/order"
         | 
| 3 3 |  | 
| 4 4 | 
             
            child :available_payment_methods => :payment_methods do
         | 
| 5 | 
            -
              attributes :id, :name, : | 
| 5 | 
            +
              attributes :id, :name, :partial_name
         | 
| 6 | 
            +
              attributes :partial_name, as: :method_type
         | 
| 6 7 | 
             
            end
         | 
| 7 8 |  | 
| 8 9 | 
             
            child :billing_address => :bill_address do
         | 
| @@ -4,7 +4,7 @@ module Spree | |
| 4 4 | 
             
                  module Setup
         | 
| 5 5 | 
             
                    def sign_in_as_admin!
         | 
| 6 6 | 
             
                      let!(:current_api_user) do
         | 
| 7 | 
            -
                        stub_model(Spree::LegacyUser, spree_roles: [Spree::Role. | 
| 7 | 
            +
                        stub_model(Spree::LegacyUser, spree_roles: [Spree::Role.find_or_initialize_by(name: 'admin')])
         | 
| 8 8 | 
             
                      end
         | 
| 9 9 | 
             
                    end
         | 
| 10 10 | 
             
                  end
         | 
| @@ -24,19 +24,19 @@ describe Spree::Api::BaseController, type: :controller do | |
| 24 24 |  | 
| 25 25 | 
             
                context "with a correct order token" do
         | 
| 26 26 | 
             
                  it "succeeds" do
         | 
| 27 | 
            -
                     | 
| 27 | 
            +
                    get :index, params: { order_token: order.guest_token, order_id: order.number }
         | 
| 28 28 | 
             
                    expect(response.status).to eq(200)
         | 
| 29 29 | 
             
                  end
         | 
| 30 30 |  | 
| 31 31 | 
             
                  it "succeeds with an order_number parameter" do
         | 
| 32 | 
            -
                     | 
| 32 | 
            +
                    get :index, params: { order_token: order.guest_token, order_number: order.number }
         | 
| 33 33 | 
             
                    expect(response.status).to eq(200)
         | 
| 34 34 | 
             
                  end
         | 
| 35 35 | 
             
                end
         | 
| 36 36 |  | 
| 37 37 | 
             
                context "with an incorrect order token" do
         | 
| 38 38 | 
             
                  it "returns unauthorized" do
         | 
| 39 | 
            -
                     | 
| 39 | 
            +
                    get :index, params: { order_token: "NOT_A_TOKEN", order_id: order.number }
         | 
| 40 40 | 
             
                    expect(response.status).to eq(401)
         | 
| 41 41 | 
             
                  end
         | 
| 42 42 | 
             
                end
         | 
| @@ -44,7 +44,7 @@ describe Spree::Api::BaseController, type: :controller do | |
| 44 44 |  | 
| 45 45 | 
             
              context "cannot make a request to the API" do
         | 
| 46 46 | 
             
                it "without an API key" do
         | 
| 47 | 
            -
                   | 
| 47 | 
            +
                  get :index
         | 
| 48 48 | 
             
                  expect(json_response).to eq({ "error" => "You must specify an API key." })
         | 
| 49 49 | 
             
                  expect(response.status).to eq(401)
         | 
| 50 50 | 
             
                end
         | 
| @@ -117,7 +117,7 @@ describe Spree::Api::BaseController, type: :controller do | |
| 117 117 |  | 
| 118 118 | 
             
                it 'should notify notify_error_during_processing' do
         | 
| 119 119 | 
             
                  expect(MockHoneybadger).to receive(:notify_or_ignore).once.with(kind_of(Exception), rack_env: kind_of(Hash))
         | 
| 120 | 
            -
                   | 
| 120 | 
            +
                  get :foo, params: { token: 123 }
         | 
| 121 121 | 
             
                  expect(response.status).to eq(422)
         | 
| 122 122 | 
             
                end
         | 
| 123 123 | 
             
              end
         | 
| @@ -153,7 +153,7 @@ describe Spree::Api::BaseController, type: :controller do | |
| 153 153 |  | 
| 154 154 | 
             
                context 'without an existing lock' do
         | 
| 155 155 | 
             
                  it 'succeeds' do
         | 
| 156 | 
            -
                     | 
| 156 | 
            +
                    get :index, params: { order_token: order.guest_token, order_id: order.number }
         | 
| 157 157 | 
             
                    expect(response.status).to eq(200)
         | 
| 158 158 | 
             
                  end
         | 
| 159 159 | 
             
                end
         | 
| @@ -164,7 +164,7 @@ describe Spree::Api::BaseController, type: :controller do | |
| 164 164 | 
             
                  end
         | 
| 165 165 |  | 
| 166 166 | 
             
                  it 'returns a 409 conflict' do
         | 
| 167 | 
            -
                     | 
| 167 | 
            +
                    get :index, params: { order_token: order.guest_token, order_id: order.number }
         | 
| 168 168 | 
             
                    expect(response.status).to eq(409)
         | 
| 169 169 | 
             
                  end
         | 
| 170 170 | 
             
                end
         | 
| @@ -50,14 +50,14 @@ module Spree | |
| 50 50 | 
             
                  let!(:widget) { Widget.create!(name: "a widget") }
         | 
| 51 51 |  | 
| 52 52 | 
             
                  it "returns no widgets" do
         | 
| 53 | 
            -
                     | 
| 53 | 
            +
                    get :index, params: { token: user.spree_api_key }, as: :json
         | 
| 54 54 | 
             
                    expect(response).to be_success
         | 
| 55 55 | 
             
                    expect(json_response['widgets']).to be_blank
         | 
| 56 56 | 
             
                  end
         | 
| 57 57 |  | 
| 58 58 | 
             
                  context "it has authorization to read widgets" do
         | 
| 59 59 | 
             
                    it "returns widgets" do
         | 
| 60 | 
            -
                       | 
| 60 | 
            +
                      get :index, params: { token: admin_user.spree_api_key }, as: :json
         | 
| 61 61 | 
             
                      expect(response).to be_success
         | 
| 62 62 | 
             
                      expect(json_response['widgets']).to include(hash_including(
         | 
| 63 63 | 
             
                        'name' => 'a widget',
         | 
| @@ -69,26 +69,26 @@ module Spree | |
| 69 69 | 
             
                      let!(:widget2) { Widget.create!(name: "a widget") }
         | 
| 70 70 |  | 
| 71 71 | 
             
                      it "returns both widgets from comma separated string" do
         | 
| 72 | 
            -
                         | 
| 72 | 
            +
                        get :index, params: { ids: [widget.id, widget2.id].join(','), token: admin_user.spree_api_key }, as: :json
         | 
| 73 73 | 
             
                        expect(response).to be_success
         | 
| 74 74 | 
             
                        expect(json_response['widgets'].size).to eq 2
         | 
| 75 75 | 
             
                      end
         | 
| 76 76 |  | 
| 77 77 | 
             
                      it "returns both widgets from multiple arguments" do
         | 
| 78 | 
            -
                         | 
| 78 | 
            +
                        get :index, params: { ids: [widget.id, widget2.id], token: admin_user.spree_api_key }, as: :json
         | 
| 79 79 | 
             
                        expect(response).to be_success
         | 
| 80 80 | 
             
                        expect(json_response['widgets'].size).to eq 2
         | 
| 81 81 | 
             
                      end
         | 
| 82 82 |  | 
| 83 83 | 
             
                      it "returns one requested widgets" do
         | 
| 84 | 
            -
                         | 
| 84 | 
            +
                        get :index, params: { ids: widget2.id.to_s, token: admin_user.spree_api_key }, as: :json
         | 
| 85 85 | 
             
                        expect(response).to be_success
         | 
| 86 86 | 
             
                        expect(json_response['widgets'].size).to eq 1
         | 
| 87 87 | 
             
                        expect(json_response['widgets'][0]['id']).to eq widget2.id
         | 
| 88 88 | 
             
                      end
         | 
| 89 89 |  | 
| 90 90 | 
             
                      it "returns no widgets if empty" do
         | 
| 91 | 
            -
                         | 
| 91 | 
            +
                        get :index, params: { ids: '', token: admin_user.spree_api_key }, as: :json
         | 
| 92 92 | 
             
                        expect(response).to be_success
         | 
| 93 93 | 
             
                        expect(json_response['widgets']).to be_empty
         | 
| 94 94 | 
             
                      end
         | 
| @@ -100,13 +100,13 @@ module Spree | |
| 100 100 | 
             
                  let(:widget) { Widget.create!(name: "a widget") }
         | 
| 101 101 |  | 
| 102 102 | 
             
                  it "returns not found" do
         | 
| 103 | 
            -
                     | 
| 103 | 
            +
                    get :show, params: { id: widget.to_param, token: user.spree_api_key }, as: :json
         | 
| 104 104 | 
             
                    assert_not_found!
         | 
| 105 105 | 
             
                  end
         | 
| 106 106 |  | 
| 107 107 | 
             
                  context "it has authorization read widgets" do
         | 
| 108 108 | 
             
                    it "returns widget details" do
         | 
| 109 | 
            -
                       | 
| 109 | 
            +
                      get :show, params: { id: widget.to_param, token: admin_user.spree_api_key }, as: :json
         | 
| 110 110 | 
             
                      expect(response).to be_success
         | 
| 111 111 | 
             
                      expect(json_response['name']).to eq 'a widget'
         | 
| 112 112 | 
             
                    end
         | 
| @@ -115,13 +115,13 @@ module Spree | |
| 115 115 |  | 
| 116 116 | 
             
                describe "#new" do
         | 
| 117 117 | 
             
                  it "returns unauthorized" do
         | 
| 118 | 
            -
                     | 
| 118 | 
            +
                    get :new, params: { token: user.spree_api_key }, as: :json
         | 
| 119 119 | 
             
                    expect(response).to be_unauthorized
         | 
| 120 120 | 
             
                  end
         | 
| 121 121 |  | 
| 122 122 | 
             
                  context "it is allowed to view a new widget" do
         | 
| 123 123 | 
             
                    it "can learn how to create a new widget" do
         | 
| 124 | 
            -
                       | 
| 124 | 
            +
                      get :new, params: { token: admin_user.spree_api_key }, as: :json
         | 
| 125 125 | 
             
                      expect(response).to be_success
         | 
| 126 126 | 
             
                      expect(json_response["attributes"]).to eq(['name'])
         | 
| 127 127 | 
             
                    end
         | 
| @@ -131,7 +131,7 @@ module Spree | |
| 131 131 | 
             
                describe "#create" do
         | 
| 132 132 | 
             
                  it "returns unauthorized" do
         | 
| 133 133 | 
             
                    expect {
         | 
| 134 | 
            -
                       | 
| 134 | 
            +
                      post :create, params: { widget: { name: "a widget" }, token: user.spree_api_key }, as: :json
         | 
| 135 135 | 
             
                    }.not_to change(Widget, :count)
         | 
| 136 136 | 
             
                    expect(response).to be_unauthorized
         | 
| 137 137 | 
             
                  end
         | 
| @@ -139,7 +139,7 @@ module Spree | |
| 139 139 | 
             
                  context "it is authorized to create widgets" do
         | 
| 140 140 | 
             
                    it "can create a widget" do
         | 
| 141 141 | 
             
                      expect {
         | 
| 142 | 
            -
                         | 
| 142 | 
            +
                        post :create, params: { widget: { name: "a widget" }, token: admin_user.spree_api_key }, as: :json
         | 
| 143 143 | 
             
                      }.to change(Widget, :count).by(1)
         | 
| 144 144 | 
             
                      expect(response).to be_created
         | 
| 145 145 | 
             
                      expect(json_response['name']).to eq 'a widget'
         | 
| @@ -151,14 +151,14 @@ module Spree | |
| 151 151 | 
             
                describe "#update" do
         | 
| 152 152 | 
             
                  let!(:widget) { Widget.create!(name: "a widget") }
         | 
| 153 153 | 
             
                  it "returns unauthorized" do
         | 
| 154 | 
            -
                     | 
| 154 | 
            +
                    put :update, params: { id: widget.to_param, widget: { name: "another widget" }, token: user.spree_api_key }, as: :json
         | 
| 155 155 | 
             
                    assert_not_found!
         | 
| 156 156 | 
             
                    expect(widget.reload.name).to eq 'a widget'
         | 
| 157 157 | 
             
                  end
         | 
| 158 158 |  | 
| 159 159 | 
             
                  context "it is authorized to update widgets" do
         | 
| 160 160 | 
             
                    it "can update a widget" do
         | 
| 161 | 
            -
                       | 
| 161 | 
            +
                      put :update, params: { id: widget.to_param, widget: { name: "another widget" }, token: admin_user.spree_api_key }, as: :json
         | 
| 162 162 | 
             
                      expect(response).to be_success
         | 
| 163 163 | 
             
                      expect(json_response['name']).to eq 'another widget'
         | 
| 164 164 | 
             
                      expect(widget.reload.name).to eq 'another widget'
         | 
| @@ -169,14 +169,14 @@ module Spree | |
| 169 169 | 
             
                describe "#destroy" do
         | 
| 170 170 | 
             
                  let!(:widget) { Widget.create!(name: "a widget") }
         | 
| 171 171 | 
             
                  it "returns unauthorized" do
         | 
| 172 | 
            -
                     | 
| 172 | 
            +
                    delete :destroy, params: { id: widget.to_param, token: user.spree_api_key }, as: :json
         | 
| 173 173 | 
             
                    assert_not_found!
         | 
| 174 174 | 
             
                    expect { widget.reload }.not_to raise_error
         | 
| 175 175 | 
             
                  end
         | 
| 176 176 |  | 
| 177 177 | 
             
                  context "it is authorized to destroy widgets" do
         | 
| 178 178 | 
             
                    it "can destroy a widget" do
         | 
| 179 | 
            -
                       | 
| 179 | 
            +
                      delete :destroy, params: { id: widget.to_param, token: admin_user.spree_api_key }, as: :json
         | 
| 180 180 | 
             
                      expect(response.status).to eq 204
         | 
| 181 181 | 
             
                      expect { widget.reload }.to raise_error(ActiveRecord::RecordNotFound)
         | 
| 182 182 | 
             
                    end
         | 
| @@ -131,7 +131,7 @@ module Spree | |
| 131 131 | 
             
                      other_user.save_in_address_book(ron_address_attributes, false)
         | 
| 132 132 |  | 
| 133 133 | 
             
                      get "/api/users/#{other_user.id}/address_book",
         | 
| 134 | 
            -
             | 
| 134 | 
            +
                        headers: { 'X-SPREE-TOKEN' => 'galleon' }
         | 
| 135 135 |  | 
| 136 136 | 
             
                      json_response = JSON.parse(response.body)
         | 
| 137 137 | 
             
                      expect(response.status).to eq(200)
         | 
| @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Spree
         | 
| 4 | 
            -
              describe Api::AddressesController, type: : | 
| 5 | 
            -
                render_views
         | 
| 4 | 
            +
              describe Api::AddressesController, type: :request do
         | 
| 6 5 |  | 
| 7 6 | 
             
                before do
         | 
| 8 7 | 
             
                  stub_authentication!
         | 
| @@ -17,20 +16,18 @@ module Spree | |
| 17 16 |  | 
| 18 17 | 
             
                  context "with their own address" do
         | 
| 19 18 | 
             
                    it "gets an address" do
         | 
| 20 | 
            -
                       | 
| 19 | 
            +
                      get spree.api_order_address_path(@order, @address.id)
         | 
| 21 20 | 
             
                      expect(json_response['address1']).to eq @address.address1
         | 
| 22 21 | 
             
                    end
         | 
| 23 22 |  | 
| 24 23 | 
             
                    it "update replaces the readonly Address associated to the Order" do
         | 
| 25 | 
            -
                       | 
| 26 | 
            -
                                       address: { address1: "123 Test Lane" }
         | 
| 24 | 
            +
                      put spree.api_order_address_path(@order, @address.id), params: { address: { address1: "123 Test Lane" } }
         | 
| 27 25 | 
             
                      expect(Order.find(@order.id).bill_address_id).not_to eq @address.id
         | 
| 28 26 | 
             
                      expect(json_response['address1']).to eq '123 Test Lane'
         | 
| 29 27 | 
             
                    end
         | 
| 30 28 |  | 
| 31 29 | 
             
                    it "receives the errors object if address is invalid" do
         | 
| 32 | 
            -
                       | 
| 33 | 
            -
                                       address: { address1: "" }
         | 
| 30 | 
            +
                      put spree.api_order_address_path(@order, @address.id), params: { address: { address1: "" } }
         | 
| 34 31 |  | 
| 35 32 | 
             
                      expect(json_response['error']).not_to be_nil
         | 
| 36 33 | 
             
                      expect(json_response['errors']).not_to be_nil
         | 
| @@ -46,12 +43,12 @@ module Spree | |
| 46 43 | 
             
                  end
         | 
| 47 44 |  | 
| 48 45 | 
             
                  it "cannot retrieve address information" do
         | 
| 49 | 
            -
                     | 
| 46 | 
            +
                    get spree.api_order_address_path(@order, @address.id)
         | 
| 50 47 | 
             
                    assert_unauthorized!
         | 
| 51 48 | 
             
                  end
         | 
| 52 49 |  | 
| 53 50 | 
             
                  it "cannot update address information" do
         | 
| 54 | 
            -
                     | 
| 51 | 
            +
                    get spree.api_order_address_path(@order, @address.id)
         | 
| 55 52 | 
             
                    assert_unauthorized!
         | 
| 56 53 | 
             
                  end
         | 
| 57 54 | 
             
                end
         | 
| @@ -1,8 +1,7 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            module Spree
         | 
| 4 | 
            -
              describe Api::CheckoutsController, type: : | 
| 5 | 
            -
                render_views
         | 
| 4 | 
            +
              describe Api::CheckoutsController, type: :request do
         | 
| 6 5 |  | 
| 7 6 | 
             
                before(:each) do
         | 
| 8 7 | 
             
                  stub_authentication!
         | 
| @@ -37,30 +36,27 @@ module Spree | |
| 37 36 | 
             
                  it "should transition a recently created order from cart to address" do
         | 
| 38 37 | 
             
                    expect(order.state).to eq "cart"
         | 
| 39 38 | 
             
                    expect(order.email).not_to be_nil
         | 
| 40 | 
            -
                     | 
| 39 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
         | 
| 41 40 | 
             
                    expect(order.reload.state).to eq "address"
         | 
| 42 41 | 
             
                  end
         | 
| 43 42 |  | 
| 44 43 | 
             
                  it "should transition a recently created order from cart to address with order token in header" do
         | 
| 45 44 | 
             
                    expect(order.state).to eq "cart"
         | 
| 46 45 | 
             
                    expect(order.email).not_to be_nil
         | 
| 47 | 
            -
                     | 
| 48 | 
            -
                    api_put :update, id: order.to_param
         | 
| 46 | 
            +
                    put spree.api_checkout_path(order), headers: { "X-Spree-Order-Token" => order.guest_token }
         | 
| 49 47 | 
             
                    expect(order.reload.state).to eq "address"
         | 
| 50 48 | 
             
                  end
         | 
| 51 49 |  | 
| 52 50 | 
             
                  it "can take line_items_attributes as a parameter" do
         | 
| 53 51 | 
             
                    line_item = order.line_items.first
         | 
| 54 | 
            -
                     | 
| 55 | 
            -
                                     order: { line_items_attributes: { 0 => { id: line_item.id, quantity: 1 } } }
         | 
| 52 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { line_items_attributes: { 0 => { id: line_item.id, quantity: 1 } } } }
         | 
| 56 53 | 
             
                    expect(response.status).to eq(200)
         | 
| 57 54 | 
             
                    expect(order.reload.state).to eq "address"
         | 
| 58 55 | 
             
                  end
         | 
| 59 56 |  | 
| 60 57 | 
             
                  it "can take line_items as a parameter" do
         | 
| 61 58 | 
             
                    line_item = order.line_items.first
         | 
| 62 | 
            -
                     | 
| 63 | 
            -
                                     order: { line_items: { 0 => { id: line_item.id, quantity: 1 } } }
         | 
| 59 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { line_items: { 0 => { id: line_item.id, quantity: 1 } } } }
         | 
| 64 60 | 
             
                    expect(response.status).to eq(200)
         | 
| 65 61 | 
             
                    expect(order.reload.state).to eq "address"
         | 
| 66 62 | 
             
                  end
         | 
| @@ -70,7 +66,7 @@ module Spree | |
| 70 66 | 
             
                    order.bill_address = nil
         | 
| 71 67 | 
             
                    order.save
         | 
| 72 68 | 
             
                    order.update_column(:state, "address")
         | 
| 73 | 
            -
                     | 
| 69 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
         | 
| 74 70 | 
             
                    # Order has not transitioned
         | 
| 75 71 | 
             
                    expect(response.status).to eq(422)
         | 
| 76 72 | 
             
                  end
         | 
| @@ -94,12 +90,11 @@ module Spree | |
| 94 90 | 
             
                    end
         | 
| 95 91 |  | 
| 96 92 | 
             
                    it "can update addresses and transition from address to delivery" do
         | 
| 97 | 
            -
                       | 
| 98 | 
            -
                         | 
| 99 | 
            -
                        order: {
         | 
| 93 | 
            +
                      put spree.api_checkout_path(order),
         | 
| 94 | 
            +
                        params: { order_token: order.guest_token, order: {
         | 
| 100 95 | 
             
                          bill_address_attributes: address,
         | 
| 101 96 | 
             
                          ship_address_attributes: address
         | 
| 102 | 
            -
                        }
         | 
| 97 | 
            +
                        } }
         | 
| 103 98 | 
             
                      expect(json_response['state']).to eq('delivery')
         | 
| 104 99 | 
             
                      expect(json_response['bill_address']['firstname']).to eq('John')
         | 
| 105 100 | 
             
                      expect(json_response['ship_address']['firstname']).to eq('John')
         | 
| @@ -109,24 +104,22 @@ module Spree | |
| 109 104 | 
             
                    # Regression Spec for https://github.com/spree/spree/issues/5389 and https://github.com/spree/spree/issues/5880
         | 
| 110 105 | 
             
                    it "can update addresses but not transition to delivery w/o shipping setup" do
         | 
| 111 106 | 
             
                      Spree::ShippingMethod.destroy_all
         | 
| 112 | 
            -
                       | 
| 113 | 
            -
                         | 
| 114 | 
            -
                        order: {
         | 
| 107 | 
            +
                      put spree.api_checkout_path(order),
         | 
| 108 | 
            +
                        params: { order_token: order.guest_token, order: {
         | 
| 115 109 | 
             
                          bill_address_attributes: address,
         | 
| 116 110 | 
             
                          ship_address_attributes: address
         | 
| 117 | 
            -
                        }
         | 
| 111 | 
            +
                        } }
         | 
| 118 112 | 
             
                      expect(json_response['error']).to eq(I18n.t(:could_not_transition, scope: "spree.api.order"))
         | 
| 119 113 | 
             
                      expect(response.status).to eq(422)
         | 
| 120 114 | 
             
                    end
         | 
| 121 115 |  | 
| 122 116 | 
             
                    # Regression test for https://github.com/spree/spree/issues/4498
         | 
| 123 117 | 
             
                    it "does not contain duplicate variant data in delivery return" do
         | 
| 124 | 
            -
                       | 
| 125 | 
            -
                         | 
| 126 | 
            -
                        order: {
         | 
| 118 | 
            +
                      put spree.api_checkout_path(order),
         | 
| 119 | 
            +
                        params: { order_token: order.guest_token, order: {
         | 
| 127 120 | 
             
                          bill_address_attributes: address,
         | 
| 128 121 | 
             
                          ship_address_attributes: address
         | 
| 129 | 
            -
                        }
         | 
| 122 | 
            +
                        } }
         | 
| 130 123 | 
             
                      # Shipments manifests should not return the ENTIRE variant
         | 
| 131 124 | 
             
                      # This information is already present within the order's line items
         | 
| 132 125 | 
             
                      expect(json_response['shipments'].first['manifest'].first['variant']).to be_nil
         | 
| @@ -139,8 +132,7 @@ module Spree | |
| 139 132 | 
             
                    shipment = create(:shipment, order: order)
         | 
| 140 133 | 
             
                    shipment.refresh_rates
         | 
| 141 134 | 
             
                    shipping_rate = shipment.shipping_rates.where(selected: false).first
         | 
| 142 | 
            -
                     | 
| 143 | 
            -
                      order: { shipments_attributes: { "0" => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } }
         | 
| 135 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { shipments_attributes: { "0" => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } } }
         | 
| 144 136 | 
             
                    expect(response.status).to eq(200)
         | 
| 145 137 | 
             
                    # Find the correct shipment...
         | 
| 146 138 | 
             
                    json_shipment = json_response['shipments'].detect { |s| s["id"] == shipment.id }
         | 
| @@ -154,32 +146,17 @@ module Spree | |
| 154 146 |  | 
| 155 147 | 
             
                  it "can update payment method and transition from payment to confirm" do
         | 
| 156 148 | 
             
                    order.update_column(:state, "payment")
         | 
| 157 | 
            -
                    allow_any_instance_of(Spree:: | 
| 158 | 
            -
                     | 
| 159 | 
            -
                      order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
         | 
| 149 | 
            +
                    allow_any_instance_of(Spree::PaymentMethod::BogusCreditCard).to receive(:source_required?).and_return(false)
         | 
| 150 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
         | 
| 160 151 | 
             
                    expect(json_response['state']).to eq('confirm')
         | 
| 161 152 | 
             
                    expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
         | 
| 162 153 | 
             
                    expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
         | 
| 163 154 | 
             
                    expect(response.status).to eq(200)
         | 
| 164 155 | 
             
                  end
         | 
| 165 156 |  | 
| 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 157 | 
             
                  it "returns errors when source is required and missing" do
         | 
| 180 158 | 
             
                    order.update_column(:state, "payment")
         | 
| 181 | 
            -
                     | 
| 182 | 
            -
                      order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }
         | 
| 159 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { payments_attributes: [{ payment_method_id: @payment_method.id }] } }
         | 
| 183 160 | 
             
                    expect(response.status).to eq(422)
         | 
| 184 161 | 
             
                    source_errors = json_response['errors']['payments.source']
         | 
| 185 162 | 
             
                    expect(source_errors).to include("can't be blank")
         | 
| @@ -188,7 +165,6 @@ module Spree | |
| 188 165 | 
             
                  describe 'setting the payment amount' do
         | 
| 189 166 | 
             
                    let(:params) do
         | 
| 190 167 | 
             
                      {
         | 
| 191 | 
            -
                        id: order.to_param,
         | 
| 192 168 | 
             
                        order_token: order.guest_token,
         | 
| 193 169 | 
             
                        order: {
         | 
| 194 170 | 
             
                          payments_attributes: [
         | 
| @@ -202,7 +178,7 @@ module Spree | |
| 202 178 | 
             
                    end
         | 
| 203 179 |  | 
| 204 180 | 
             
                    it 'sets the payment amount to the order total' do
         | 
| 205 | 
            -
                       | 
| 181 | 
            +
                      put spree.api_checkout_path(order), params: params
         | 
| 206 182 | 
             
                      expect(response.status).to eq(200)
         | 
| 207 183 | 
             
                      expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
         | 
| 208 184 | 
             
                    end
         | 
| @@ -215,7 +191,6 @@ module Spree | |
| 215 191 |  | 
| 216 192 | 
             
                    let(:params) do
         | 
| 217 193 | 
             
                      {
         | 
| 218 | 
            -
                        id: order.to_param,
         | 
| 219 194 | 
             
                        order_token: order.guest_token,
         | 
| 220 195 | 
             
                        order: {
         | 
| 221 196 | 
             
                          payments_attributes: [
         | 
| @@ -229,7 +204,7 @@ module Spree | |
| 229 204 | 
             
                    end
         | 
| 230 205 |  | 
| 231 206 | 
             
                    it 'succeeds' do
         | 
| 232 | 
            -
                       | 
| 207 | 
            +
                      put spree.api_checkout_path(order), params: params
         | 
| 233 208 | 
             
                      expect(response.status).to eq(200)
         | 
| 234 209 | 
             
                      expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)
         | 
| 235 210 | 
             
                      expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)
         | 
| @@ -243,7 +218,6 @@ module Spree | |
| 243 218 |  | 
| 244 219 | 
             
                    let(:params) do
         | 
| 245 220 | 
             
                      {
         | 
| 246 | 
            -
                        id: order.to_param,
         | 
| 247 221 | 
             
                        order_token: order.guest_token,
         | 
| 248 222 | 
             
                        order: {
         | 
| 249 223 | 
             
                          payments_attributes: [
         | 
| @@ -257,7 +231,7 @@ module Spree | |
| 257 231 | 
             
                    end
         | 
| 258 232 |  | 
| 259 233 | 
             
                    it 'returns errors' do
         | 
| 260 | 
            -
                       | 
| 234 | 
            +
                      put spree.api_checkout_path(order), params: params
         | 
| 261 235 |  | 
| 262 236 | 
             
                      expect(response.status).to eq(422)
         | 
| 263 237 | 
             
                      cc_errors = json_response['errors']['payments.Credit Card']
         | 
| @@ -275,7 +249,6 @@ module Spree | |
| 275 249 |  | 
| 276 250 | 
             
                    let(:params) do
         | 
| 277 251 | 
             
                      {
         | 
| 278 | 
            -
                        id: order.to_param,
         | 
| 279 252 | 
             
                        order_token: order.guest_token,
         | 
| 280 253 | 
             
                        order: {
         | 
| 281 254 | 
             
                          payments_attributes: [
         | 
| @@ -306,7 +279,7 @@ module Spree | |
| 306 279 | 
             
                        receive(:verification_value=).with('456').and_call_original
         | 
| 307 280 | 
             
                      )
         | 
| 308 281 |  | 
| 309 | 
            -
                       | 
| 282 | 
            +
                      put spree.api_checkout_path(order), params: params
         | 
| 310 283 |  | 
| 311 284 | 
             
                      expect(response.status).to eq 200
         | 
| 312 285 | 
             
                      expect(order.credit_cards).to match_array [credit_card]
         | 
| @@ -315,7 +288,6 @@ module Spree | |
| 315 288 | 
             
                    context 'with deprecated existing_card_id param' do
         | 
| 316 289 | 
             
                      let(:params) do
         | 
| 317 290 | 
             
                        {
         | 
| 318 | 
            -
                          id: order.to_param,
         | 
| 319 291 | 
             
                          order_token: order.guest_token,
         | 
| 320 292 | 
             
                          order: {
         | 
| 321 293 | 
             
                            payments_attributes: [
         | 
| @@ -332,7 +304,7 @@ module Spree | |
| 332 304 |  | 
| 333 305 | 
             
                      it 'succeeds' do
         | 
| 334 306 | 
             
                        Spree::Deprecation.silence do
         | 
| 335 | 
            -
                           | 
| 307 | 
            +
                          put spree.api_checkout_path(order), params: params
         | 
| 336 308 | 
             
                        end
         | 
| 337 309 |  | 
| 338 310 | 
             
                        expect(response.status).to eq 200
         | 
| @@ -343,7 +315,7 @@ module Spree | |
| 343 315 |  | 
| 344 316 | 
             
                  it "returns the order if the order is already complete" do
         | 
| 345 317 | 
             
                    order.update_columns(completed_at: Time.current, state: 'complete')
         | 
| 346 | 
            -
                     | 
| 318 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token }
         | 
| 347 319 | 
             
                    expect(json_response['number']).to eq(order.number)
         | 
| 348 320 | 
             
                    expect(response.status).to eq(200)
         | 
| 349 321 | 
             
                  end
         | 
| @@ -351,8 +323,7 @@ module Spree | |
| 351 323 | 
             
                  # Regression test for https://github.com/spree/spree/issues/3784
         | 
| 352 324 | 
             
                  it "can update the special instructions for an order" do
         | 
| 353 325 | 
             
                    instructions = "Don't drop it. (Please)"
         | 
| 354 | 
            -
                     | 
| 355 | 
            -
                      order: { special_instructions: instructions }
         | 
| 326 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { special_instructions: instructions } }
         | 
| 356 327 | 
             
                    expect(json_response['special_instructions']).to eql(instructions)
         | 
| 357 328 | 
             
                  end
         | 
| 358 329 |  | 
| @@ -361,16 +332,14 @@ module Spree | |
| 361 332 | 
             
                    it "can assign a user to the order" do
         | 
| 362 333 | 
             
                      user = create(:user)
         | 
| 363 334 | 
             
                      # Need to pass email as well so that validations succeed
         | 
| 364 | 
            -
                       | 
| 365 | 
            -
                        order: { user_id: user.id, email: "guest@spreecommerce.com" }
         | 
| 335 | 
            +
                      put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { user_id: user.id, email: "guest@spreecommerce.com" } }
         | 
| 366 336 | 
             
                      expect(response.status).to eq(200)
         | 
| 367 337 | 
             
                      expect(json_response['user_id']).to eq(user.id)
         | 
| 368 338 | 
             
                    end
         | 
| 369 339 | 
             
                  end
         | 
| 370 340 |  | 
| 371 341 | 
             
                  it "can assign an email to the order" do
         | 
| 372 | 
            -
                     | 
| 373 | 
            -
                      order: { email: "guest@spreecommerce.com" }
         | 
| 342 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { email: "guest@spreecommerce.com" } }
         | 
| 374 343 | 
             
                    expect(json_response['email']).to eq("guest@spreecommerce.com")
         | 
| 375 344 | 
             
                    expect(response.status).to eq(200)
         | 
| 376 345 | 
             
                  end
         | 
| @@ -379,7 +348,7 @@ module Spree | |
| 379 348 | 
             
                    order.update_column(:state, "payment")
         | 
| 380 349 | 
             
                    expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original
         | 
| 381 350 | 
             
                    expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return({ coupon_applied?: true })
         | 
| 382 | 
            -
                     | 
| 351 | 
            +
                    put spree.api_checkout_path(order.to_param), params: { order_token: order.guest_token, order: { coupon_code: "foobar" } }
         | 
| 383 352 | 
             
                  end
         | 
| 384 353 | 
             
                end
         | 
| 385 354 |  | 
| @@ -388,7 +357,7 @@ module Spree | |
| 388 357 | 
             
                  it "cannot transition to address without a line item" do
         | 
| 389 358 | 
             
                    order.line_items.delete_all
         | 
| 390 359 | 
             
                    order.update_column(:email, "spree@example.com")
         | 
| 391 | 
            -
                     | 
| 360 | 
            +
                    put spree.next_api_checkout_path(order), params: { order_token: order.guest_token }
         | 
| 392 361 | 
             
                    expect(response.status).to eq(422)
         | 
| 393 362 | 
             
                    expect(json_response["errors"]["base"]).to include(Spree.t(:there_are_no_items_for_this_order))
         | 
| 394 363 | 
             
                  end
         | 
| @@ -396,7 +365,7 @@ module Spree | |
| 396 365 | 
             
                  it "can transition an order to the next state" do
         | 
| 397 366 | 
             
                    order.update_column(:email, "spree@example.com")
         | 
| 398 367 |  | 
| 399 | 
            -
                     | 
| 368 | 
            +
                    put spree.next_api_checkout_path(order), params: { order_token: order.guest_token }
         | 
| 400 369 | 
             
                    expect(response.status).to eq(200)
         | 
| 401 370 | 
             
                    expect(json_response['state']).to eq('address')
         | 
| 402 371 | 
             
                  end
         | 
| @@ -407,7 +376,7 @@ module Spree | |
| 407 376 | 
             
                      email: nil
         | 
| 408 377 | 
             
                    )
         | 
| 409 378 |  | 
| 410 | 
            -
                     | 
| 379 | 
            +
                    put spree.next_api_checkout_path(order), params: { id: order.to_param, order_token: order.guest_token }
         | 
| 411 380 | 
             
                    expect(response.status).to eq(422)
         | 
| 412 381 | 
             
                    expect(json_response['error']).to match(/could not be transitioned/)
         | 
| 413 382 | 
             
                  end
         | 
| @@ -416,10 +385,10 @@ module Spree | |
| 416 385 | 
             
                context "complete" do
         | 
| 417 386 | 
             
                  context "with order in confirm state" do
         | 
| 418 387 | 
             
                    subject do
         | 
| 419 | 
            -
                       | 
| 388 | 
            +
                      put spree.complete_api_checkout_path(order), params: params
         | 
| 420 389 | 
             
                    end
         | 
| 421 390 |  | 
| 422 | 
            -
                    let(:params) { {  | 
| 391 | 
            +
                    let(:params) { { order_token: order.guest_token } }
         | 
| 423 392 | 
             
                    let(:order) { create(:order_with_line_items) }
         | 
| 424 393 |  | 
| 425 394 | 
             
                    before do
         | 
| @@ -434,7 +403,7 @@ module Spree | |
| 434 403 | 
             
                    end
         | 
| 435 404 |  | 
| 436 405 | 
             
                    it "returns a sensible error when no payment method is specified" do
         | 
| 437 | 
            -
                      #  | 
| 406 | 
            +
                      # put :complete, id: order.to_param, order_token: order.token, order: {}
         | 
| 438 407 | 
             
                      subject
         | 
| 439 408 | 
             
                      expect(json_response["errors"]["base"]).to include(Spree.t(:no_payment_found))
         | 
| 440 409 | 
             
                    end
         | 
| @@ -443,7 +412,7 @@ module Spree | |
| 443 412 | 
             
                      let(:params) { super().merge(expected_total: order.total + 1) }
         | 
| 444 413 |  | 
| 445 414 | 
             
                      it "returns an error if expected_total is present and does not match actual total" do
         | 
| 446 | 
            -
                        #  | 
| 415 | 
            +
                        # put :complete, id: order.to_param, order_token: order.token, expected_total: order.total + 1
         | 
| 447 416 | 
             
                        subject
         | 
| 448 417 | 
             
                        expect(response.status).to eq(400)
         | 
| 449 418 | 
             
                        expect(json_response['errors']['expected_total']).to include(Spree.t(:expected_total_mismatch, scope: 'api.order'))
         | 
| @@ -457,11 +426,11 @@ module Spree | |
| 457 426 |  | 
| 458 427 | 
             
                  it 'continues to advance an order while it can move forward' do
         | 
| 459 428 | 
             
                    expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)
         | 
| 460 | 
            -
                     | 
| 429 | 
            +
                    put spree.advance_api_checkout_path(order), params: { order_token: order.guest_token }
         | 
| 461 430 | 
             
                  end
         | 
| 462 431 |  | 
| 463 432 | 
             
                  it 'returns the order' do
         | 
| 464 | 
            -
                     | 
| 433 | 
            +
                    put spree.advance_api_checkout_path(order), params: { order_token: order.guest_token }
         | 
| 465 434 | 
             
                    expect(json_response['id']).to eq(order.id)
         | 
| 466 435 | 
             
                  end
         | 
| 467 436 | 
             
                end
         |