Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dunning): Dunning Campaign processing skip customers completed #2869

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/services/dunning_campaigns/bulk_process_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def call

def eligible_customers
Customer
.with_dunning_campaign_not_completed
.joins(:organization)
.where(exclude_from_dunning_campaign: false)
.where("organizations.premium_integrations @> ARRAY[?]::varchar[]", ['auto_dunning'])
Expand All @@ -30,6 +31,7 @@ def initialize(customer)
end

def call
return result if customer.dunning_campaign_completed?
return result unless threshold
return result if max_attempts_reached?
return result unless days_between_attempts_satisfied?
Expand Down
11 changes: 11 additions & 0 deletions spec/services/dunning_campaigns/bulk_process_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@
.with(customer:, dunning_campaign_threshold:)
end

context "when the customer has completed the dunning campaign" do
let(:customer) do
create :customer, organization:, currency:, dunning_campaign_completed: true
end

it "does not queue a job for the customer" do
result
expect(DunningCampaigns::ProcessAttemptJob).not_to have_been_enqueued
end
end

context "when organization does not have auto_dunning feature enabled" do
let(:organization) { create(:organization, premium_integrations: []) }

Expand Down