Sha256: 7f8b8ff513a688c7463de91ea27b4e809003c99e2fc0144a43f714977658b483

Contents?: true

Size: 1.56 KB

Versions: 21

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

module Spree
  RSpec.describe ReimbursementType::Exchange, type: :model do
    describe '.reimburse' do
      let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
      let(:return_items)  { reimbursement.return_items }
      let(:new_exchange)  { double("Exchange") }
      let(:simulate)      { true }
      let(:created_by_user) { create(:user, email: 'user@email.com') }

      subject { Spree::ReimbursementType::Exchange.reimburse(reimbursement, return_items, simulate, created_by: created_by_user) }

      context 'return items are supplied' do
        before do
          expect(Spree::Exchange).to receive(:new).with(reimbursement.order, return_items).and_return(new_exchange)
        end

        context "simulate is true" do
          it 'does not perform an exchange and returns the exchange object' do
            expect(new_exchange).not_to receive(:perform!)
            expect(subject).to eq [new_exchange]
          end
        end

        context "simulate is false" do
          let(:simulate) { false }

          it 'performs an exchange and returns the exchange object' do
            expect(new_exchange).to receive(:perform!)
            expect(subject).to eq [new_exchange]
          end
        end
      end

      context "no return items are supplied" do
        let(:return_items) { [] }

        it 'does not perform an exchange and returns an empty array' do
          expect(new_exchange).not_to receive(:perform!)
          expect(subject).to eq []
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_core-2.10.5 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.10.3 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.10.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.6 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.8.6 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.10.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.5 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.10.0 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.4 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.8.5 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.3 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.10.0.beta1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.0 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.9.0.rc.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.8.4 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.8.3 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.8.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.8.1 spec/models/spree/reimbursement_type/exchange_spec.rb