Skip to content

Commit

Permalink
feat(dunning): Validate dunning campaign has at least one threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Nov 5, 2024
1 parent c9e4746 commit b93bac6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/services/dunning_campaigns/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(organization:, params:)

def call
return result.forbidden_failure! unless organization.auto_dunning_enabled?
# TODO: At least one threshold currency/amount pair is needed
return result.validation_failure!(errors: { thresholds: ["can't be blank"] }) if params[:thresholds].blank?

ActiveRecord::Base.transaction do
if params[:applied_to_organization]
Expand Down
3 changes: 1 addition & 2 deletions spec/services/dunning_campaigns/bulk_process_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
end
end

context "when neither organizaiton nor customer has an applied dunning campaign" do
context "when neither organization nor customer has an applied dunning campaign" do
let(:dunning_campaign) { create :dunning_campaign, organization:, applied_to_organization: false }

let(:dunning_campaign_threshold) do
Expand All @@ -403,7 +403,6 @@
end

before do
dunning_campaign
dunning_campaign_threshold
invoice_1
end
Expand Down
14 changes: 14 additions & 0 deletions spec/services/dunning_campaigns/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@
expect(result.error.messages[:code]).to eq(["value_already_exist"])
end
end

context "without thresholds" do
let(:thresholds) { [] }

it "returns an error" do
result = create_service.call

aggregate_failures do
expect(result).not_to be_success
expect(result.error).to be_a(BaseService::ValidationFailure)
expect(result.error.messages[:thresholds]).to eq(["can't be blank"])
end
end
end
end
end
end
Expand Down

0 comments on commit b93bac6

Please sign in to comment.