diff --git a/app/models/customer.rb b/app/models/customer.rb index 3711d160243..539b568d987 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -72,8 +72,6 @@ class Customer < ApplicationRecord scope :falling_back_to_default_dunning_campaign, -> { where(applied_dunning_campaign_id: nil, exclude_from_dunning_campaign: false) } - scope :with_dunning_campaign_completed, -> { where(dunning_campaign_completed: true) } - scope :with_dunning_campaign_not_completed, -> { where(dunning_campaign_completed: false) } validates :country, :shipping_country, country_code: true, allow_nil: true validates :document_locale, language_code: true, unless: -> { document_locale.nil? } @@ -192,7 +190,6 @@ def overdue_balance_cents def reset_dunning_campaign! update!( - dunning_campaign_completed: false, last_dunning_campaign_attempt: 0, last_dunning_campaign_attempt_at: nil ) @@ -222,7 +219,6 @@ def ensure_slug # customer_type :enum # deleted_at :datetime # document_locale :string -# dunning_campaign_completed :boolean default(FALSE) # email :string # exclude_from_dunning_campaign :boolean default(FALSE), not null # finalize_zero_amount_invoice :integer default("inherit"), not null diff --git a/app/models/dunning_campaign.rb b/app/models/dunning_campaign.rb index 73207e04302..e966b1c4dac 100644 --- a/app/models/dunning_campaign.rb +++ b/app/models/dunning_campaign.rb @@ -36,7 +36,7 @@ def self.ransackable_attributes(_auth_object = nil) def reset_customers_last_attempt # NOTE: Reset last attempt on customers with the campaign applied explicitly - customers.with_dunning_campaign_not_completed.update_all( # rubocop:disable Rails/SkipsModelValidations + customers.update_all( # rubocop:disable Rails/SkipsModelValidations last_dunning_campaign_attempt: 0, last_dunning_campaign_attempt_at: nil ) diff --git a/app/models/organization.rb b/app/models/organization.rb index f22bed69713..5435a352bc2 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -138,7 +138,6 @@ def auto_dunning_enabled? def reset_customers_last_dunning_campaign_attempt customers .falling_back_to_default_dunning_campaign - .with_dunning_campaign_not_completed .update_all( # rubocop:disable Rails/SkipsModelValidations last_dunning_campaign_attempt: 0, last_dunning_campaign_attempt_at: nil diff --git a/app/services/dunning_campaigns/bulk_process_service.rb b/app/services/dunning_campaigns/bulk_process_service.rb index 447dab754f2..b00896e6420 100644 --- a/app/services/dunning_campaigns/bulk_process_service.rb +++ b/app/services/dunning_campaigns/bulk_process_service.rb @@ -16,7 +16,6 @@ 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']) @@ -31,7 +30,6 @@ 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? diff --git a/app/services/dunning_campaigns/process_attempt_service.rb b/app/services/dunning_campaigns/process_attempt_service.rb index 2408fa0a901..c274c018e4e 100644 --- a/app/services/dunning_campaigns/process_attempt_service.rb +++ b/app/services/dunning_campaigns/process_attempt_service.rb @@ -16,7 +16,7 @@ def call return result unless applicable_dunning_campaign? return result unless dunning_campaign_threshold_reached? return result unless days_between_attempts_passed? - return result if customer.dunning_campaign_completed? + return result if max_attempts_reached? ActiveRecord::Base.transaction do payment_request_result = PaymentRequests::CreateService.call( @@ -30,7 +30,6 @@ def call customer.increment(:last_dunning_campaign_attempt) customer.last_dunning_campaign_attempt_at = Time.zone.now - customer.dunning_campaign_completed = last_dunning_campaign_attempt? customer.save! result.customer = customer @@ -65,7 +64,7 @@ def days_between_attempts_passed? (customer.last_dunning_campaign_attempt_at + dunning_campaign.days_between_attempts.days).past? end - def last_dunning_campaign_attempt? + def max_attempts_reached? customer.last_dunning_campaign_attempt >= dunning_campaign.max_attempts end diff --git a/app/services/dunning_campaigns/update_service.rb b/app/services/dunning_campaigns/update_service.rb index dfb39d7ac15..c8fed6d73b8 100644 --- a/app/services/dunning_campaigns/update_service.rb +++ b/app/services/dunning_campaigns/update_service.rb @@ -18,7 +18,6 @@ def call dunning_campaign.assign_attributes(permitted_attributes) handle_thresholds if params.key?(:thresholds) handle_applied_to_organization_update if params.key?(:applied_to_organization) - handle_max_attempts_change if dunning_campaign.max_attempts_changed? dunning_campaign.save! end @@ -84,9 +83,7 @@ def reset_customers_if_no_threshold_match end def customers_to_reset - @customers_to_reset ||= customers_applied_campaign - .or(customers_fallback_campaign) - .with_dunning_campaign_not_completed + @customers_to_reset ||= customers_applied_campaign.or(customers_fallback_campaign) end def customers_applied_campaign @@ -110,17 +107,9 @@ def handle_applied_to_organization_update organization.reset_customers_last_dunning_campaign_attempt customers_fallback_campaign.update_all( # rubocop:disable Rails/SkipsModelValidations - dunning_campaign_completed: false, last_dunning_campaign_attempt_at: nil, last_dunning_campaign_attempt: 0 ) end - - def handle_max_attempts_change - # we assume there is matching threshold at this point or it was reseted - customers_to_reset - .where("last_dunning_campaign_attempt >= ?", dunning_campaign.max_attempts) - .update_all(dunning_campaign_completed: true) # rubocop:disable Rails/SkipsModelValidations - end end end diff --git a/app/services/payment_requests/payments/stripe_service.rb b/app/services/payment_requests/payments/stripe_service.rb index dcf6e0172fa..b3d7a6a201f 100644 --- a/app/services/payment_requests/payments/stripe_service.rb +++ b/app/services/payment_requests/payments/stripe_service.rb @@ -344,11 +344,7 @@ def reset_customer_dunning_campaign_status(payment_status) return unless payment_status_succeeded?(payment_status) return unless payable.try(:dunning_campaign) - customer.update!( - dunning_campaign_completed: false, - last_dunning_campaign_attempt: 0, - last_dunning_campaign_attempt_at: nil - ) + customer.reset_dunning_campaign! end end end diff --git a/db/migrate/20241128091634_remove_dunning_campaign_completed_from_customers.rb b/db/migrate/20241128091634_remove_dunning_campaign_completed_from_customers.rb new file mode 100644 index 00000000000..e1b940939d6 --- /dev/null +++ b/db/migrate/20241128091634_remove_dunning_campaign_completed_from_customers.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class RemoveDunningCampaignCompletedFromCustomers < ActiveRecord::Migration[7.1] + def change + safety_assured do + remove_column :customers, :dunning_campaign_completed, :boolean, default: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 436d3f4dc70..3bc16d8a6b1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_11_26_141853) do +ActiveRecord::Schema[7.1].define(version: 2024_11_28_091634) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -469,7 +469,6 @@ t.boolean "exclude_from_dunning_campaign", default: false, null: false t.integer "last_dunning_campaign_attempt", default: 0, null: false t.datetime "last_dunning_campaign_attempt_at", precision: nil - t.boolean "dunning_campaign_completed", default: false t.index ["applied_dunning_campaign_id"], name: "index_customers_on_applied_dunning_campaign_id" t.index ["deleted_at"], name: "index_customers_on_deleted_at" t.index ["external_id", "organization_id"], name: "index_customers_on_external_id_and_organization_id", unique: true, where: "(deleted_at IS NULL)" diff --git a/spec/models/customer_spec.rb b/spec/models/customer_spec.rb index 00a92c01183..dd4234c9764 100644 --- a/spec/models/customer_spec.rb +++ b/spec/models/customer_spec.rb @@ -599,7 +599,6 @@ let(:customer) do create( :customer, - dunning_campaign_completed: true, last_dunning_campaign_attempt: 5, last_dunning_campaign_attempt_at: 1.day.ago ) @@ -607,8 +606,7 @@ it "changes dunning campaign status counters" do expect { customer.reset_dunning_campaign! && customer.reload } - .to change(customer, :dunning_campaign_completed).to(false) - .and change(customer, :last_dunning_campaign_attempt).to(0) + .to change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) end end diff --git a/spec/models/dunning_campaign_spec.rb b/spec/models/dunning_campaign_spec.rb index 32fc665b2b1..fd08562827e 100644 --- a/spec/models/dunning_campaign_spec.rb +++ b/spec/models/dunning_campaign_spec.rb @@ -65,19 +65,6 @@ .and change { customer.last_dunning_campaign_attempt_at }.from(last_dunning_campaign_attempt_at).to(nil) end - it "does not reset last attempt on customers with dunning campaign already completed" do - customer = create( - :customer, - organization:, - applied_dunning_campaign: dunning_campaign, - last_dunning_campaign_attempt: 1, - dunning_campaign_completed: true - ) - - expect { dunning_campaign.reset_customers_last_attempt } - .not_to change { customer.reload.last_dunning_campaign_attempt }.from(1) - end - context "when applied to organization" do subject(:dunning_campaign) { create(:dunning_campaign, applied_to_organization: true) } @@ -93,18 +80,6 @@ .to change { customer.reload.last_dunning_campaign_attempt }.from(2).to(0) .and change { customer.last_dunning_campaign_attempt_at }.from(last_dunning_campaign_attempt_at).to(nil) end - - it "does not reset last attempt on customers with dunning campaign already completed" do - customer = create( - :customer, - organization:, - last_dunning_campaign_attempt: 2, - dunning_campaign_completed: true - ) - - expect { dunning_campaign.reset_customers_last_attempt } - .not_to change { customer.reload.last_dunning_campaign_attempt }.from(2) - end end end end diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index f49e3b2ec7f..e253432d159 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -245,13 +245,11 @@ it "resets the last dunning campaign attempt for customers" do customer1 = create(:customer, organization:, last_dunning_campaign_attempt: 1, last_dunning_campaign_attempt_at:) customer2 = create(:customer, organization:, last_dunning_campaign_attempt: 1, last_dunning_campaign_attempt_at:, applied_dunning_campaign: campaign) - customer3 = create(:customer, organization:, last_dunning_campaign_attempt: 1, last_dunning_campaign_attempt_at:, dunning_campaign_completed: true) expect { organization.reset_customers_last_dunning_campaign_attempt } .to change { customer1.reload.last_dunning_campaign_attempt }.from(1).to(0) .and change(customer1, :last_dunning_campaign_attempt_at).from(last_dunning_campaign_attempt_at).to(nil) expect(customer2.reload.last_dunning_campaign_attempt).to eq(1) - expect(customer3.reload.last_dunning_campaign_attempt).to eq(1) end end diff --git a/spec/services/customers/update_service_spec.rb b/spec/services/customers/update_service_spec.rb index daddd26177c..ebc7f0f196c 100644 --- a/spec/services/customers/update_service_spec.rb +++ b/spec/services/customers/update_service_spec.rb @@ -356,7 +356,6 @@ expect { customers_service.call } .to not_change(customer, :applied_dunning_campaign_id) .and not_change(customer, :exclude_from_dunning_campaign) - .and not_change(customer, :dunning_campaign_completed) .and not_change(customer, :last_dunning_campaign_attempt) .and not_change { customer.last_dunning_campaign_attempt_at.iso8601 } @@ -370,8 +369,7 @@ organization:, exclude_from_dunning_campaign: true, last_dunning_campaign_attempt: 3, - last_dunning_campaign_attempt_at: 2.days.ago, - dunning_campaign_completed: true + last_dunning_campaign_attempt_at: 2.days.ago ) end @@ -391,7 +389,6 @@ expect { customers_service.call } .to change(customer, :applied_dunning_campaign_id).to(dunning_campaign.id) .and change(customer, :exclude_from_dunning_campaign).to(false) - .and change(customer, :dunning_campaign_completed).to(false) .and change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) @@ -405,8 +402,7 @@ organization:, applied_dunning_campaign: dunning_campaign, last_dunning_campaign_attempt: 3, - last_dunning_campaign_attempt_at: 2.days.ago, - dunning_campaign_completed: true + last_dunning_campaign_attempt_at: 2.days.ago ) end @@ -418,7 +414,6 @@ expect { customers_service.call } .to change(customer, :applied_dunning_campaign_id).to(nil) .and change(customer, :exclude_from_dunning_campaign).to(true) - .and change(customer, :dunning_campaign_completed).to(false) .and change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) @@ -434,8 +429,7 @@ applied_dunning_campaign: dunning_campaign, exclude_from_dunning_campaign: false, last_dunning_campaign_attempt: 3, - last_dunning_campaign_attempt_at: 2.days.ago, - dunning_campaign_completed: true + last_dunning_campaign_attempt_at: 2.days.ago ) end @@ -445,7 +439,6 @@ expect { customers_service.call } .to change(customer, :applied_dunning_campaign_id).to(nil) .and not_change(customer, :exclude_from_dunning_campaign) - .and change(customer, :dunning_campaign_completed).to(false) .and change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) @@ -461,8 +454,7 @@ applied_dunning_campaign: dunning_campaign, exclude_from_dunning_campaign: false, last_dunning_campaign_attempt: 3, - last_dunning_campaign_attempt_at: 2.days.ago, - dunning_campaign_completed: true + last_dunning_campaign_attempt_at: 2.days.ago ) end @@ -472,7 +464,6 @@ expect { customers_service.call } .to not_change(customer, :applied_dunning_campaign_id) .and not_change(customer, :exclude_from_dunning_campaign) - .and not_change(customer, :dunning_campaign_completed) .and not_change(customer, :last_dunning_campaign_attempt) .and not_change(customer, :last_dunning_campaign_attempt_at) diff --git a/spec/services/dunning_campaigns/bulk_process_service_spec.rb b/spec/services/dunning_campaigns/bulk_process_service_spec.rb index 93c9901dbb5..0733dc36fa1 100644 --- a/spec/services/dunning_campaigns/bulk_process_service_spec.rb +++ b/spec/services/dunning_campaigns/bulk_process_service_spec.rb @@ -65,17 +65,6 @@ .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: []) } diff --git a/spec/services/dunning_campaigns/process_attempt_service_spec.rb b/spec/services/dunning_campaigns/process_attempt_service_spec.rb index ec61314f743..fe7daf3fc5e 100644 --- a/spec/services/dunning_campaigns/process_attempt_service_spec.rb +++ b/spec/services/dunning_campaigns/process_attempt_service_spec.rb @@ -71,25 +71,23 @@ expect { result && customer.reload } .to change(customer, :last_dunning_campaign_attempt).by(1) .and change(customer, :last_dunning_campaign_attempt_at).to(Time.zone.now) - .and not_change(customer, :dunning_campaign_completed).from(false) end end - context "when dunning campaign max attemp is reached" do + context "when dunning campaign max attempt is reached" do let(:customer) do create( :customer, organization:, currency:, - last_dunning_campaign_attempt: dunning_campaign.max_attempts - 1, - last_dunning_campaign_attempt_at: dunning_campaign.days_between_attempts.days.ago, - dunning_campaign_completed: false + last_dunning_campaign_attempt: dunning_campaign.max_attempts, + last_dunning_campaign_attempt_at: dunning_campaign.days_between_attempts.days.ago ) end - it "updates customer's dunning campaign completed flag" do - expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to(true) + it "does nothing" do + result + expect(PaymentRequests::CreateService).not_to have_received(:call) end end @@ -136,22 +134,6 @@ end 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 nothing" do - result - expect(PaymentRequests::CreateService).not_to have_received(:call) - end - end - context "when days between attempts has not passed" do let(:customer) do create( diff --git a/spec/services/dunning_campaigns/update_service_spec.rb b/spec/services/dunning_campaigns/update_service_spec.rb index 61429aff70a..758d1acf2eb 100644 --- a/spec/services/dunning_campaigns/update_service_spec.rb +++ b/spec/services/dunning_campaigns/update_service_spec.rb @@ -79,17 +79,6 @@ ] end - let(:customer_completed) do - create( - :customer, - currency: dunning_campaign_threshold.currency, - applied_dunning_campaign: dunning_campaign, - last_dunning_campaign_attempt: 4, - last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: true, - organization: organization - ) - end let(:customer_defaulting) do create( :customer, @@ -97,7 +86,6 @@ applied_dunning_campaign: nil, last_dunning_campaign_attempt: 4, last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: false, organization: organization ) end @@ -108,7 +96,6 @@ applied_dunning_campaign: dunning_campaign, last_dunning_campaign_attempt: 4, last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: false, organization: organization ) end @@ -128,105 +115,6 @@ .to have_attributes({amount_cents: 5_55, currency: "CHF"}) end - context "when max_attempts is changed and some customers exceed it" do - let(:params) { {max_attempts: 3} } - - before do - create( - :invoice, - organization:, - customer:, - payment_overdue: true, - total_amount_cents: dunning_campaign_threshold.amount_cents, - currency: dunning_campaign_threshold.currency - ) - end - - context "when the campaign is applied to the customer" do - let(:dunning_campaign) do - create(:dunning_campaign, organization:, applied_to_organization: false) - end - - let(:customer) do - create( - :customer, - currency: dunning_campaign_threshold.currency, - applied_dunning_campaign: dunning_campaign, - last_dunning_campaign_attempt: 3, - last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: false, - organization: organization - ) - end - - before { customer } - - it "sets dunning_campaign_completed to true for customers whose last_dunning_campaign_attempt exceeds max_attempts" do - expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to true - end - - it "does not update customers whose last_dunning_campaign_attempt is within the new max_attempts" do - another_customer = create( - :customer, - currency: dunning_campaign_threshold.currency, - applied_dunning_campaign: dunning_campaign, - last_dunning_campaign_attempt: 2, - last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: false, - organization: organization - ) - - expect { result && another_customer.reload } - .not_to change { another_customer.dunning_campaign_completed } - - expect(result).to be_success - end - end - - context "when the customer falls back to the campaign through the organization" do - let(:customer) do - create( - :customer, - currency: dunning_campaign_threshold.currency, - applied_dunning_campaign: nil, - last_dunning_campaign_attempt: 4, - last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: false, - organization: organization - ) - end - - let(:dunning_campaign) do - create(:dunning_campaign, organization:, applied_to_organization: true) - end - - before { customer } - - it "sets dunning_campaign_completed to true for customers whose last_dunning_campaign_attempt exceeds max_attempts" do - expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to true - end - - it "does not update customers whose last_dunning_campaign_attempt is within the new max_attempts" do - another_customer = create( - :customer, - currency: dunning_campaign_threshold.currency, - applied_dunning_campaign: dunning_campaign, - last_dunning_campaign_attempt: 2, - last_dunning_campaign_attempt_at: 1.day.ago, - dunning_campaign_completed: false, - organization: organization - ) - - expect { result && another_customer.reload } - .not_to change { another_customer.dunning_campaign_completed } - - expect(result).to be_success - end - end - end - shared_examples "resets customer last dunning campaign attempt fields" do |customer_name| let(:customer) { send(customer_name) } @@ -290,10 +178,6 @@ context "when the customer defaults to the campaign applied to organization" do include_examples "resets customer last dunning campaign attempt fields", :customer_defaulting end - - context "when the customer already completed the campaign" do - include_examples "does not reset customer last dunning campaign attempt fields", :customer_completed - end end context "when threshold currency changes and does not apply anymore to the customer" do @@ -329,10 +213,6 @@ context "when the customer defaults to the campaign applied to organization" do include_examples "resets customer last dunning campaign attempt fields", :customer_defaulting end - - context "when the customer already completed the campaign" do - include_examples "does not reset customer last dunning campaign attempt fields", :customer_completed - end end context "when threshold amount_cents changes but it still applies to the customer" do @@ -370,10 +250,6 @@ context "when the customer defaults to the campaign applied to organization" do include_examples "does not reset customer last dunning campaign attempt fields", :customer_defaulting end - - context "when the customer already completed the campaign" do - include_examples "does not reset customer last dunning campaign attempt fields", :customer_completed - end end context "when threshold currency changes but it still applies to the customer" do @@ -418,10 +294,6 @@ context "when the customer defaults to the campaign applied to organization" do include_examples "does not reset customer last dunning campaign attempt fields", :customer_defaulting end - - context "when the customer already completed the campaign" do - include_examples "does not reset customer last dunning campaign attempt fields", :customer_completed - end end context "when a threshold is discarded and the campaign does not apply anymore to the customer" do @@ -449,10 +321,6 @@ context "when the customer defaults to the campaign applied to organization" do include_examples "resets customer last dunning campaign attempt fields", :customer_defaulting end - - context "when the customer already completed the campaign" do - include_examples "does not reset customer last dunning campaign attempt fields", :customer_completed - end end context "when a threshold is discarded and replaced with one that still applies to the customer" do @@ -489,10 +357,6 @@ context "when the customer defaults to the campaign applied to organization" do include_examples "does not reset customer last dunning campaign attempt fields", :customer_defaulting end - - context "when the customer already completed the campaign" do - include_examples "does not reset customer last dunning campaign attempt fields", :customer_completed - end end context "when the input does not include a thresholds" do @@ -555,18 +419,16 @@ .and change { customer.last_dunning_campaign_attempt_at }.from(a_value).to(nil) end - it "flags customers as not dunning campaign completed" do + it "resets last attempt" do customer = create( :customer, organization:, - dunning_campaign_completed: true, last_dunning_campaign_attempt: 3, last_dunning_campaign_attempt_at: Time.zone.now ) expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to(false) - .and change(customer, :last_dunning_campaign_attempt).to(0) + .to change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) end end diff --git a/spec/services/invoices/update_service_spec.rb b/spec/services/invoices/update_service_spec.rb index 7f815ccc77b..708efd12dee 100644 --- a/spec/services/invoices/update_service_spec.rb +++ b/spec/services/invoices/update_service_spec.rb @@ -40,7 +40,6 @@ let(:customer) do create( :customer, - dunning_campaign_completed: true, last_dunning_campaign_attempt: 3, last_dunning_campaign_attempt_at: 1.day.ago ) @@ -58,8 +57,7 @@ it "does not reset customer dunning campaign status counters" do expect { result && customer.reload } - .to not_change(customer, :dunning_campaign_completed) - .and not_change(customer, :last_dunning_campaign_attempt) + .to not_change(customer, :last_dunning_campaign_attempt) .and not_change { customer.last_dunning_campaign_attempt_at.to_i } end @@ -71,8 +69,7 @@ it "resets customer dunning campaign status counters" do expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to(false) - .and change(customer, :last_dunning_campaign_attempt).to(0) + .to change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) end end diff --git a/spec/services/payment_requests/payments/adyen_service_spec.rb b/spec/services/payment_requests/payments/adyen_service_spec.rb index fa69cc0bb65..1f225b4d5a0 100644 --- a/spec/services/payment_requests/payments/adyen_service_spec.rb +++ b/spec/services/payment_requests/payments/adyen_service_spec.rb @@ -462,7 +462,6 @@ create( :customer, payment_provider_code: code, - dunning_campaign_completed: true, last_dunning_campaign_attempt: 3, last_dunning_campaign_attempt_at: Time.zone.now ) @@ -482,8 +481,7 @@ it "resets the customer dunning campaign counters" do expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to(false) - .and change(customer, :last_dunning_campaign_attempt).to(0) + .to change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) expect(result).to be_success @@ -494,8 +492,7 @@ it "doest not reset the customer dunning campaign counters" do expect { result && customer.reload } - .to not_change(customer, :dunning_campaign_completed) - .and not_change(customer, :last_dunning_campaign_attempt) + .to not_change(customer, :last_dunning_campaign_attempt) .and not_change { customer.last_dunning_campaign_attempt_at&.to_i } expect(result).to be_success diff --git a/spec/services/payment_requests/payments/gocardless_service_spec.rb b/spec/services/payment_requests/payments/gocardless_service_spec.rb index 58a2480bb0c..aebef0cbf00 100644 --- a/spec/services/payment_requests/payments/gocardless_service_spec.rb +++ b/spec/services/payment_requests/payments/gocardless_service_spec.rb @@ -321,7 +321,6 @@ create( :customer, payment_provider_code: code, - dunning_campaign_completed: true, last_dunning_campaign_attempt: 3, last_dunning_campaign_attempt_at: Time.zone.now ) @@ -341,8 +340,7 @@ it "resets the customer dunning campaign counters" do expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to(false) - .and change(customer, :last_dunning_campaign_attempt).to(0) + .to change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) expect(result).to be_success @@ -353,8 +351,7 @@ it "doest not reset the customer dunning campaign counters" do expect { result && customer.reload } - .to not_change(customer, :dunning_campaign_completed) - .and not_change(customer, :last_dunning_campaign_attempt) + .to not_change(customer, :last_dunning_campaign_attempt) .and not_change { customer.last_dunning_campaign_attempt_at&.to_i } expect(result).to be_success diff --git a/spec/services/payment_requests/payments/stripe_service_spec.rb b/spec/services/payment_requests/payments/stripe_service_spec.rb index b39a04fecba..17db961f8bd 100644 --- a/spec/services/payment_requests/payments/stripe_service_spec.rb +++ b/spec/services/payment_requests/payments/stripe_service_spec.rb @@ -508,7 +508,6 @@ create( :customer, payment_provider_code: code, - dunning_campaign_completed: true, last_dunning_campaign_attempt: 3, last_dunning_campaign_attempt_at: Time.zone.now ) @@ -528,8 +527,7 @@ it "resets the customer dunning campaign counters" do expect { result && customer.reload } - .to change(customer, :dunning_campaign_completed).to(false) - .and change(customer, :last_dunning_campaign_attempt).to(0) + .to change(customer, :last_dunning_campaign_attempt).to(0) .and change(customer, :last_dunning_campaign_attempt_at).to(nil) expect(result).to be_success @@ -540,8 +538,7 @@ it "doest not reset the customer dunning campaign counters" do expect { result && customer.reload } - .to not_change(customer, :dunning_campaign_completed) - .and not_change(customer, :last_dunning_campaign_attempt) + .to not_change(customer, :last_dunning_campaign_attempt) .and not_change { customer.last_dunning_campaign_attempt_at&.to_i } expect(result).to be_success