From aebfc2e4490fc67fb10254b1da705ec83842637f Mon Sep 17 00:00:00 2001 From: m11o Date: Fri, 4 Nov 2022 18:35:25 +0900 Subject: [PATCH 1/2] add session arguments in ShopifyApp::WebhooksManager.destroy_webhooks --- lib/shopify_app/managers/webhooks_manager.rb | 6 ++--- .../managers/webhooks_manager_test.rb | 27 +++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lib/shopify_app/managers/webhooks_manager.rb b/lib/shopify_app/managers/webhooks_manager.rb index ebc90fea9..5d521b752 100644 --- a/lib/shopify_app/managers/webhooks_manager.rb +++ b/lib/shopify_app/managers/webhooks_manager.rb @@ -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 diff --git a/test/shopify_app/managers/webhooks_manager_test.rb b/test/shopify_app/managers/webhooks_manager_test.rb index f595fe64d..86e6fc1d7 100644 --- a/test/shopify_app/managers/webhooks_manager_test.rb +++ b/test/shopify_app/managers/webhooks_manager_test.rb @@ -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| @@ -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 @@ -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 From 78861bd7e9fc48a504965596f1e89d960aa72629 Mon Sep 17 00:00:00 2001 From: m11o Date: Sat, 5 Nov 2022 11:59:39 +0900 Subject: [PATCH 2/2] add message in `CHANGELOG` --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c67897461..26ae9f5a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) 21.2.0 (Oct 25, 2022) ----------