Sha256: 698fc8bda8ae26cd64762f7b4a9fbfe5e7cb17fdf311179021d6a15b25cdbd55

Contents?: true

Size: 1.97 KB

Versions: 16

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Spree
  describe Api::AddressesController, type: :request do
    let(:user) { create(:user) }

    before do
      @address = create(:address)
      @order = create(:order, bill_address: @address)
    end

    context "with order" do
      before do
        allow_any_instance_of(Order).to receive_messages user: user
      end

      context "with their own address" do
        it "gets an address" do
          get spree.api_order_address_path(@order, @address.id), headers: user.create_new_auth_token
          expect(json_response['address1']).to eq @address.address1
        end

        it "update replaces the readonly Address associated to the Order" do
          put spree.api_order_address_path(@order, @address.id), headers: user.create_new_auth_token, params: { address: { address1: "123 Test Lane" } }
          expect(Order.find(@order.id).bill_address_id).not_to eq @address.id
          expect(json_response['address1']).to eq '123 Test Lane'
        end

        it "receives the errors object if address is invalid" do
          put spree.api_order_address_path(@order, @address.id), headers: user.create_new_auth_token, params: { address: { address1: "" } }

          expect(json_response['error']).not_to be_nil
          expect(json_response['errors']).not_to be_nil
          expect(json_response['errors']['address1'].first).to eq "can't be blank"
        end
      end
    end

    context "on an address that does not belong to this order" do
      before do
        @order.bill_address_id = nil
        @order.ship_address = nil
      end

      it "cannot retrieve address information" do
        get spree.api_order_address_path(@order, @address.id), headers: user.create_new_auth_token
        assert_unauthorized!
      end

      it "cannot update address information" do
        get spree.api_order_address_path(@order, @address.id), headers: user.create_new_auth_token
        assert_unauthorized!
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
solidus_api_devise_token_auth-2.8.0.alpha.14 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.13 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.12 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.11 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.10 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.9 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.8 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.7 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.6 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.5 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.4 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.3 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.2 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.1 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.0 spec/requests/spree/api/addresses_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha spec/requests/spree/api/addresses_controller_spec.rb