summaryrefslogtreecommitdiff
path: root/spec/lib/solidus_subscriptions/dispatcher/success_dispatcher_spec.rb
blob: 366e1f7c1ee3b5c1f8f5b1f3eab42f5a3da03d0e (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
30
# frozen_string_literal: true

RSpec.describe SolidusSubscriptions::Dispatcher::SuccessDispatcher do
  describe '#dispatch' do
    it 'marks the installment as success' 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(:success!).with(order)
    end

    it 'fires an installments_succeeded event' do
      stub_const('Spree::Event', class_spy(Spree::Event))
      installment = instance_spy(SolidusSubscriptions::Installment)
      order = create(:order_with_line_items)

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

      expect(Spree::Event).to have_received(:fire).with(
        'solidus_subscriptions.installment_succeeded',
        installment: installment,
        order: order,
      )
    end
  end
end