summaryrefslogtreecommitdiff
path: root/spec/lib/solidus_subscriptions/dispatcher/failure_dispatcher_spec.rb
blob: 0d7db9526fcb4251fa444c8ec390727d20136fa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

RSpec.describe SolidusSubscriptions::Dispatcher::FailureDispatcher do
  describe '#dispatch' do
    it 'marks the installment as failed' do
      installment = instance_spy(SolidusSubscriptions::Installment)
      order = create(:order_with_line_items)

      dispatcher = described_class.new(installment, order)
      dispatcher.dispatch

      expect(installment).to have_received(:failed!).with(order)
    end

    it 'cancels the order' do
      if Spree.solidus_gem_version > Gem::Version.new('2.10')
        skip 'Orders in `cart` state cannot be canceled starting from Solidus 2.11.'
      end

      installment = instance_spy(SolidusSubscriptions::Installment)
      order = create(:order_with_line_items)

      dispatcher = described_class.new(installment, order)
      dispatcher.dispatch

      expect(order.state).to eq('canceled')
    end
  end
end