summaryrefslogtreecommitdiff
path: root/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
blob: 7211cfeb0f430727132ec4ce14ba2272edbe43f5 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

RSpec.describe SolidusSubscriptions::ProcessInstallmentJob do
  it 'processes checkout for the installment' do
    installment = build_stubbed(:installment)
    checkout = instance_spy(SolidusSubscriptions::Checkout)
    allow(SolidusSubscriptions::Checkout).to receive(:new).with(installment).and_return(checkout)

    described_class.perform_now(installment)

    expect(checkout).to have_received(:process)
  end

  context 'when handling #perform errors' do
    it 'by default logs exception data without raising exceptions' do
      checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
        allow(c).to receive(:process).and_raise('test error')
      end
      allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout)
      allow(Rails.logger).to receive(:error)

      expect {
        described_class.perform_now(build_stubbed(:installment))
      }.not_to raise_error

      expect(Rails.logger).to have_received(:error).with("test error").ordered
    end

    it 'swallows error when a proc is not configured' do
      stub_config(processing_error_handler: nil )
      checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
        allow(c).to receive(:process).and_raise('test error')
      end
      allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout)

      expect {
        described_class.perform_now(build_stubbed(:installment))
      }.not_to raise_error
    end

    it 'runs proc when a proc is configured' do
      stub_config(processing_error_handler: proc { |e| raise e } )
      checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
        allow(c).to receive(:process).and_raise('test error')
      end
      allow(SolidusSubscriptions::Checkout).to receive(:new).and_return(checkout)

      expect {
        described_class.perform_now(build_stubbed(:installment))
      }.to raise_error(/test error/)
    end
  end
end