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

Add session argument in ShopifyApp::WebhooksManager.destroy_webhooks #1569

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
----------
* Fixes a bug with `ShopifyApp::WebhooksManager.destroy_webhooks` causing not passing session arguments to [unregister](https://github.com/Shopify/shopify-api-ruby/blob/main/lib/shopify_api/webhooks/registry.rb#L99) method [#1569](https://github.com/Shopify/shopify_app/pull/1569)
* Fixes a bug with `EnsureAuthenticatedLinks` causing deep links to not work [#1549](https://github.com/Shopify/shopify_app/pull/1549)

21.2.0 (Oct 25, 2022)
Expand Down
6 changes: 3 additions & 3 deletions lib/shopify_app/managers/webhooks_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ def create_webhooks(session:)
end

def recreate_webhooks!(session:)
destroy_webhooks
destroy_webhooks(session: session)
return unless ShopifyApp.configuration.has_webhooks?

add_registrations
ShopifyAPI::Webhooks::Registry.register_all(session: session)
end

def destroy_webhooks
def destroy_webhooks(session:)
return unless ShopifyApp.configuration.has_webhooks?

ShopifyApp.configuration.webhooks.each do |attributes|
ShopifyAPI::Webhooks::Registry.unregister(topic: attributes[:topic])
ShopifyAPI::Webhooks::Registry.unregister(topic: attributes[:topic], session: session)
end
end

Expand Down
27 changes: 25 additions & 2 deletions test/shopify_app/managers/webhooks_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ class ShopifyApp::WebhooksManagerTest < ActiveSupport::TestCase
end

test "#recreate_webhooks! destroys all webhooks and recreates" do
session = ShopifyAPI::Auth::Session.new(shop: "shop.myshopify.com")

ShopifyAPI::Webhooks::Registry.expects(:register_all)
ShopifyAPI::Webhooks::Registry.expects(:unregister).with(topic: "orders/updated")
ShopifyAPI::Webhooks::Registry.expects(:unregister).with(topic: "orders/updated", session: session)
ShopifyApp::WebhooksManager.expects(:add_registrations).twice

ShopifyApp.configure do |config|
Expand All @@ -88,7 +90,7 @@ class ShopifyApp::WebhooksManagerTest < ActiveSupport::TestCase
]
end
ShopifyApp::WebhooksManager.add_registrations
ShopifyApp::WebhooksManager.recreate_webhooks!(session: ShopifyAPI::Auth::Session.new(shop: "shop.myshopify.com"))
ShopifyApp::WebhooksManager.recreate_webhooks!(session: session)
end

test "#recreate_webhooks! does not call unregister if there is no webhook" do
Expand All @@ -102,4 +104,25 @@ class ShopifyApp::WebhooksManagerTest < ActiveSupport::TestCase
ShopifyApp::WebhooksManager.add_registrations
ShopifyApp::WebhooksManager.recreate_webhooks!(session: ShopifyAPI::Auth::Session.new(shop: "shop.myshopify.com"))
end

test "#destroy_webhooks destroy all webhooks" do
session = ShopifyAPI::Auth::Session.new(shop: "shop.myshopify.com")
ShopifyAPI::Webhooks::Registry.expects(:unregister).with(topic: "orders/updated", session: session)

ShopifyApp.configure do |config|
config.webhooks = [
{ topic: "orders/updated", path: "webhooks" },
]
end
ShopifyApp::WebhooksManager.destroy_webhooks(session: session)
end

test "#destroy_webhooks does not call unregister if there is no webhook" do
ShopifyAPI::Webhooks::Registry.expects(:unregister).never

ShopifyApp.configure do |config|
config.webhooks = []
end
ShopifyApp::WebhooksManager.destroy_webhooks(session: ShopifyAPI::Auth::Session.new(shop: "shop.myshopify.com"))
end
end