Sha256: 35846b8dacc0a088ad8ee873806cb619fc14d72665926ce19b99433b26b11a77

Contents?: true

Size: 1.75 KB

Versions: 16

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Spree
  describe Api::InventoryUnitsController, type: :request do
    let(:admin_user)      { create(:user, :admin)   }
    let!(:inventory_unit) { create(:inventory_unit) }

    context "as an admin" do
      let(:variant) { create(:variant) }

      it "gets an inventory unit" do
        get spree.api_inventory_unit_path(inventory_unit), headers: admin_user.create_new_auth_token
        expect(json_response['state']).to eq inventory_unit.state
      end

      it "updates an inventory unit" do
        put spree.api_inventory_unit_path(inventory_unit), headers: admin_user.create_new_auth_token, params: {
          inventory_unit: { variant_id: variant.id }
        }
        expect(json_response['variant_id']).to eq variant.id
      end

      context 'fires state event' do
        it 'if supplied with :fire param' do
          put spree.api_inventory_unit_path(inventory_unit), headers: admin_user.create_new_auth_token, params: {
            fire: 'ship',
            inventory_unit: { variant_id: variant.id }
          }

          expect(json_response['state']).to eq 'shipped'
        end

        it 'and returns exception if cannot fire' do
          put spree.api_inventory_unit_path(inventory_unit), headers: admin_user.create_new_auth_token, params: {
            fire: 'return'
          }
          expect(json_response['exception']).to match /cannot transition to return/
        end

        it 'and returns exception bad state' do
          put spree.api_inventory_unit_path(inventory_unit), headers: admin_user.create_new_auth_token, params: {
            fire: 'bad'
          }
          expect(json_response['exception']).to match /cannot transition to bad/
        end
      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/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.13 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.12 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.11 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.10 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.9 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.8 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.7 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.6 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.5 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.4 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.3 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.2 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.1 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha.0 spec/requests/spree/api/inventory_units_controller_spec.rb
solidus_api_devise_token_auth-2.8.0.alpha spec/requests/spree/api/inventory_units_controller_spec.rb