summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/jobs/solidus_subscriptions/process_installment_job.rb11
-rw-r--r--app/jobs/solidus_subscriptions/process_installments_job.rb24
-rw-r--r--lib/solidus_subscriptions/processor.rb2
-rw-r--r--spec/jobs/solidus_subscriptions/process_installment_job_spec.rb11
-rw-r--r--spec/jobs/solidus_subscriptions/process_installments_job_spec.rb28
-rw-r--r--spec/lib/solidus_subscriptions/processor_spec.rb8
6 files changed, 27 insertions, 57 deletions
diff --git a/app/jobs/solidus_subscriptions/process_installment_job.rb b/app/jobs/solidus_subscriptions/process_installment_job.rb
new file mode 100644
index 0000000..6beeec6
--- /dev/null
+++ b/app/jobs/solidus_subscriptions/process_installment_job.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module SolidusSubscriptions
+ class ProcessInstallmentJob < ApplicationJob
+ queue_as SolidusSubscriptions.configuration.processing_queue
+
+ def perform(installment)
+ Checkout.new([installment]).process
+ end
+ end
+end
diff --git a/app/jobs/solidus_subscriptions/process_installments_job.rb b/app/jobs/solidus_subscriptions/process_installments_job.rb
deleted file mode 100644
index e7e1f63..0000000
--- a/app/jobs/solidus_subscriptions/process_installments_job.rb
+++ /dev/null
@@ -1,24 +0,0 @@
-# frozen_string_literal: true
-
-# This job is responsible for creating a consolidated installment from a
-# list of installments and processing it.
-
-module SolidusSubscriptions
- class ProcessInstallmentsJob < ApplicationJob
- queue_as SolidusSubscriptions.configuration.processing_queue
-
- # Process a collection of installments
- #
- # @param installment_ids [Array<Integer>] The ids of the
- # installments to be processed together and fulfilled by the same order
- #
- # @return [Spree::Order] The order which fulfills the list of installments
- def perform(installment_ids)
- return if installment_ids.empty?
-
- installments = SolidusSubscriptions::Installment.where(id: installment_ids).
- includes(subscription: [:line_items, :user])
- Checkout.new(installments).process
- end
- end
-end
diff --git a/lib/solidus_subscriptions/processor.rb b/lib/solidus_subscriptions/processor.rb
index 4547cec..b5aaa70 100644
--- a/lib/solidus_subscriptions/processor.rb
+++ b/lib/solidus_subscriptions/processor.rb
@@ -29,7 +29,7 @@ module SolidusSubscriptions
end
def process_installment(installment)
- ProcessInstallmentsJob.perform_later(installment)
+ ProcessInstallmentJob.perform_later(installment)
end
end
end
diff --git a/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
new file mode 100644
index 0000000..4a33819
--- /dev/null
+++ b/spec/jobs/solidus_subscriptions/process_installment_job_spec.rb
@@ -0,0 +1,11 @@
+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
+end
diff --git a/spec/jobs/solidus_subscriptions/process_installments_job_spec.rb b/spec/jobs/solidus_subscriptions/process_installments_job_spec.rb
deleted file mode 100644
index 111fc05..0000000
--- a/spec/jobs/solidus_subscriptions/process_installments_job_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe SolidusSubscriptions::ProcessInstallmentsJob do
- let(:root_order) { create :completed_order_with_pending_payment }
- let(:installments) do
- traits = {
- subscription_traits: [{
- user: root_order.user,
- line_item_traits: [{
- spree_line_item: root_order.line_items.first
- }]
- }]
- }
-
- create_list(:installment, 2, traits)
- end
-
- describe '#perform' do
- subject { described_class.new.perform(installments) }
-
- it 'processes the consolidated installment' do
- expect_any_instance_of(SolidusSubscriptions::Checkout).
- to receive(:process).once
-
- subject
- end
- end
-end
diff --git a/spec/lib/solidus_subscriptions/processor_spec.rb b/spec/lib/solidus_subscriptions/processor_spec.rb
index a7301f0..03be168 100644
--- a/spec/lib/solidus_subscriptions/processor_spec.rb
+++ b/spec/lib/solidus_subscriptions/processor_spec.rb
@@ -46,8 +46,8 @@ RSpec.describe SolidusSubscriptions::Processor, :checkout do
described_class.run
- expect(SolidusSubscriptions::ProcessInstallmentsJob).to have_been_enqueued
- .with([subscription.installments.last])
+ expect(SolidusSubscriptions::ProcessInstallmentJob).to have_been_enqueued
+ .with(subscription.installments.last)
end
it 'schedules other actionable installments for processing' do
@@ -55,8 +55,8 @@ RSpec.describe SolidusSubscriptions::Processor, :checkout do
described_class.run
- expect(SolidusSubscriptions::ProcessInstallmentsJob).to have_been_enqueued
- .with([actionable_installment])
+ expect(SolidusSubscriptions::ProcessInstallmentJob).to have_been_enqueued
+ .with(actionable_installment)
end
end