Skip to content

Commit

Permalink
fix(webhook): Fix specs when webhook worker is enabled (#3099)
Browse files Browse the repository at this point in the history
## Description

This PR makes sure that specs involving the `on_queue` matcher keeps
passing when the webhook worker is configured
  • Loading branch information
vincent-pochet authored Jan 24, 2025
1 parent 033e72e commit 98d336b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def pp(*args)
config.include ScenariosHelper
config.include LicenseHelper
config.include PdfHelper
config.include QueuesHelper
config.include ActiveSupport::Testing::TimeHelpers
config.include ActiveStorageValidations::Matchers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
.with(
'customer.crm_provider_created',
customer
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it_behaves_like 'throttles!', :hubspot
Expand Down Expand Up @@ -139,7 +139,7 @@
.with(
'customer.crm_provider_created',
customer
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it_behaves_like 'throttles!', :hubspot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
.with(
'customer.accounting_provider_created',
customer
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it_behaves_like 'throttles!', :anrok, :hubspot, :netsuite, :xero
Expand Down Expand Up @@ -150,7 +150,7 @@
.with(
'customer.accounting_provider_created',
customer
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it_behaves_like 'throttles!', :anrok, :hubspot, :netsuite, :xero
Expand Down
2 changes: 1 addition & 1 deletion spec/services/invoices/payments/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
message: "error",
error_code: "code"
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end

context "when payment has a payable_payment_status" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_thresholds(subscription, amounts:, recurring: nil)
'subscription.usage_threshold_reached',
subscription,
usage_threshold:
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it "creates an invoice for the usage_threshold" do
Expand Down Expand Up @@ -105,7 +105,7 @@ def create_thresholds(subscription, amounts:, recurring: nil)
'subscription.usage_threshold_reached',
subscription,
usage_threshold:
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it "sends a webhook for the last threshold" do
Expand All @@ -114,7 +114,7 @@ def create_thresholds(subscription, amounts:, recurring: nil)
'subscription.usage_threshold_reached',
subscription,
usage_threshold: usage_threshold2
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it "creates an invoice for the current usage" do
Expand Down Expand Up @@ -160,7 +160,7 @@ def create_thresholds(subscription, amounts:, recurring: nil)
'subscription.usage_threshold_reached',
subscription,
usage_threshold: usage_threshold2
).on_queue(:webhook)
).on_queue(webhook_queue)
end

it "creates an invoice for the current usage" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
customer,
checkout_url: 'https://test.adyen.link/test'
)
.on_queue(:webhook)
.on_queue(webhook_queue)
end
end

Expand Down Expand Up @@ -73,7 +73,7 @@
message: 'There are no payment methods available for the given parameters.',
error_code: 'validation'
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end
end

Expand Down Expand Up @@ -174,7 +174,7 @@
customer,
checkout_url: 'https://test.adyen.link/test'
)
.on_queue(:webhook)
.on_queue(webhook_queue)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/services/payment_provider_customers/stripe_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
message: 'API key invalid.',
error_code: nil
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end
end

Expand Down Expand Up @@ -204,7 +204,7 @@
message: 'Invalid request',
error_code: nil
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end
end

Expand All @@ -231,7 +231,7 @@
message: 'Permission error',
error_code: nil
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end
end

Expand All @@ -257,7 +257,7 @@
message: 'Invalid username.',
error_code: nil
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end
end
end
Expand Down Expand Up @@ -554,7 +554,7 @@
message: 'Expired API Key provided',
error_code: nil
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
message: "error",
error_code: "code"
}
).on_queue(:webhook)
).on_queue(webhook_queue)
end

context "when payment has a payable_payment_status" do
Expand Down
11 changes: 11 additions & 0 deletions spec/support/queues_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module QueuesHelper
def webhook_queue
if ActiveModel::Type::Boolean.new.cast(ENV['SIDEKIQ_WEBHOOK'])
:webhook_worker
else
:webhook
end
end
end

0 comments on commit 98d336b

Please sign in to comment.