Sha256: 1c163eb33606d68d8810f1153d88af0a65b473549c0e01083bdf8209ef233e89

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# 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 'swallows error when a proc is not configured' 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)

      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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
solidus_subscriptions-1.0.0 spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
solidus_subscriptions-1.0.0.rc1 spec/jobs/solidus_subscriptions/process_installment_job_spec.rb