diff --git a/lib/shopify_api/webhooks/registry.rb b/lib/shopify_api/webhooks/registry.rb index 71c769294..d58530848 100644 --- a/lib/shopify_api/webhooks/registry.rb +++ b/lib/shopify_api/webhooks/registry.rb @@ -223,7 +223,9 @@ def webhook_registration_needed?(client, registration) parsed_check_result = registration.parse_check_result(T.cast(check_response.body, T::Hash[String, T.untyped])) # update this to check for more than just the current address - must_register = parsed_check_result[:current_address] != registration.callback_address + # must_register = parsed_check_result[:current_address] != registration.callback_address + + must_register = true # TODO: remove and make a real check # any subscription arg (depends on what kind of registration i.e. pubsub, http, eventbridge) has changed # all 3 have these fields: callbackUrl, subscriptionArgs (which includes includeFields, metafieldNamespaces) diff --git a/test/webhooks/registry_test.rb b/test/webhooks/registry_test.rb index b892c1b69..ca3bf027a 100644 --- a/test/webhooks/registry_test.rb +++ b/test/webhooks/registry_test.rb @@ -196,7 +196,15 @@ def test_http_registration_with_fields_add_and_update fields: "field1, field2", ) - # TODO: update webhook fields + # update webhook fields + do_registration_test( + queries[:http][:check_existing_response], + queries[:http][:register_update_query_with_fields], + queries[:http][:register_update_with_fields_response], + :http, + "app-address.com/test-webhooks", + fields: "field1, field2, field3", + ) end def test_http_registration_with_fields_array_add_and_update @@ -210,7 +218,15 @@ def test_http_registration_with_fields_array_add_and_update fields: ["field1", "field2"], ) - # TODO: update webhook fields + # update webhook fields + do_registration_test( + queries[:http][:check_existing_response], + queries[:http][:register_update_query_with_fields], + queries[:http][:register_update_with_fields_response], + :http, + "app-address.com/test-webhooks", + fields: ["field1", "field2", "field3"], + ) end def test_http_registration_with_metafield_namespaces_add_and_update @@ -224,7 +240,15 @@ def test_http_registration_with_metafield_namespaces_add_and_update metafield_namespaces: ["namespace1", "namespace2"], ) - # TODO: update webhook metafield namespaces + # update webhook metafield namespaces + do_registration_test( + queries[:http][:check_existing_response], + queries[:http][:register_update_query_with_metafield_namespaces], + queries[:http][:register_update_with_metafield_namespaces_response], + :http, + "test-webhooks", + metafield_namespaces: ["namespace1", "namespace2", "namespace3"], + ) end def test_raises_on_http_registration_check_error @@ -262,7 +286,15 @@ def test_pubsub_registration_with_fields_add_and_update fields: "field1, field2", ) - # TODO: update webhook fields + # update webhook fields + do_registration_test( + queries[:pub_sub][:check_existing_response], + queries[:pub_sub][:register_update_query_with_fields], + queries[:pub_sub][:register_update_with_fields_response], + :pub_sub, + "pubsub://my-project-id:my-topic-id", + fields: "field1, field2, field3", + ) end def test_pubsub_registration_with_fields_array_add_and_update @@ -276,7 +308,15 @@ def test_pubsub_registration_with_fields_array_add_and_update fields: ["field1", "field2"], ) - # TODO: update webhook fields + # update webhook fields + do_registration_test( + queries[:pub_sub][:check_existing_response], + queries[:pub_sub][:register_update_query_with_fields], + queries[:pub_sub][:register_update_with_fields_response], + :pub_sub, + "pubsub://my-project-id:my-topic-id", + fields: ["field1", "field2", "field3"], + ) end def test_pubsub_registration_with_metafield_namespaces_add_and_update @@ -290,7 +330,15 @@ def test_pubsub_registration_with_metafield_namespaces_add_and_update metafield_namespaces: ["namespace1", "namespace2"], ) - # TODO: update webhook metafield namespaces + # update webhook metafield namespaces + do_registration_test( + queries[:pub_sub][:check_existing_response], + queries[:pub_sub][:register_update_query_with_metafield_namespaces], + queries[:pub_sub][:register_update_with_metafield_namespaces_response], + :pub_sub, + "pubsub://my-project-id:my-topic-id", + metafield_namespaces: ["namespace1", "namespace2", "namespace3"], + ) end def test_raises_on_pubsub_registration_check_error @@ -328,7 +376,15 @@ def test_eventbridge_registration_with_fields_add_and_update fields: "field1, field2", ) - # TODO: update webhook fields + # update webhook fields + do_registration_test( + queries[:event_bridge][:check_existing_response], + queries[:event_bridge][:register_update_query_with_fields], + queries[:event_bridge][:register_update_with_fields_response], + :event_bridge, + "test-webhooks", + fields: "field1, field2, field3", + ) end def test_eventbridge_registration_with_fields_array_add_and_update @@ -342,7 +398,15 @@ def test_eventbridge_registration_with_fields_array_add_and_update fields: ["field1", "field2"], ) - # TODO: update webhook fields + # update webhook fields + do_registration_test( + queries[:event_bridge][:check_existing_response], + queries[:event_bridge][:register_update_query_with_fields], + queries[:event_bridge][:register_update_with_fields_response], + :event_bridge, + "test-webhooks", + fields: ["field1", "field2", "field3"], + ) end def test_eventbridge_registration_with_metafield_namespaces_add_and_update @@ -356,7 +420,15 @@ def test_eventbridge_registration_with_metafield_namespaces_add_and_update metafield_namespaces: ["namespace1", "namespace2"], ) - # TODO: update webhook metafield namespaces + # update webhook metafield namespaces + do_registration_test( + queries[:event_bridge][:check_existing_response], + queries[:event_bridge][:register_update_query_with_metafield_namespaces], + queries[:event_bridge][:register_update_with_metafield_namespaces_response], + :event_bridge, + "test-webhooks", + metafield_namespaces: ["namespace1", "namespace2", "namespace3"], + ) end def test_raises_on_eventbridge_registration_check_error diff --git a/test/webhooks/webhook_registration_queries.rb b/test/webhooks/webhook_registration_queries.rb index 8d4659ae8..4d9415923 100644 --- a/test/webhooks/webhook_registration_queries.rb +++ b/test/webhooks/webhook_registration_queries.rb @@ -137,6 +137,36 @@ def queries } } QUERY + register_update_query_with_fields: + <<~QUERY, + mutation webhookSubscription { + webhookSubscriptionUpdate(id: "gid://shopify/WebhookSubscription/12345", webhookSubscription: {callbackUrl: "https://app-address.com/test-webhooks", includeFields: ["field1", "field2", "field3"]}) { + userErrors { + field + message + } + webhookSubscription { + id + includeFields + } + } + } + QUERY + register_update_query_with_metafield_namespaces: + <<~QUERY, + mutation webhookSubscription { + webhookSubscriptionUpdate(id: "gid://shopify/WebhookSubscription/12345", webhookSubscription: {callbackUrl: "https://app-address.com/test-webhooks", metafieldNamespaces: ["namespace1", "namespace2", "namespace3"]}) { + userErrors { + field + message + } + webhookSubscription { + id + metafieldNamespaces + } + } + } + QUERY register_update_response: { "data" => { "webhookSubscriptionUpdate" => { @@ -145,6 +175,29 @@ def queries }, }, }, + + register_update_with_fields_response: { + "data" => { + "webhookSubscriptionUpdate" => { + "userErrors" => [], + "webhookSubscription" => { + "id" => "gid://shopify/WebhookSubscription/12345", + "includeFields" => ["field1", "field2", "field3"], + }, + }, + }, + }, + register_update_with_metafield_namespaces_response: { + "data" => { + "webhookSubscriptionUpdate" => { + "userErrors" => [], + "webhookSubscription" => { + "id" => "gid://shopify/WebhookSubscription/12345", + "metafieldNamespaces" => ["namespace1", "namespace2", "namespace3"], + }, + }, + }, + }, }, event_bridge: { check_query: @@ -275,6 +328,36 @@ def queries } } QUERY + register_update_query_with_fields: + <<~QUERY, + mutation webhookSubscription { + eventBridgeWebhookSubscriptionUpdate(id: "gid://shopify/WebhookSubscription/12345", webhookSubscription: {arn: "test-webhooks", includeFields: ["field1", "field2", "field3"]}) { + userErrors { + field + message + } + webhookSubscription { + id + includeFields + } + } + } + QUERY + register_update_query_with_metafield_namespaces: + <<~QUERY, + mutation webhookSubscription { + eventBridgeWebhookSubscriptionUpdate(id: "gid://shopify/WebhookSubscription/12345", webhookSubscription: {arn: "test-webhooks", metafieldNamespaces: ["namespace1", "namespace2", "namespace3"]}) { + userErrors { + field + message + } + webhookSubscription { + id + metafieldNamespaces + } + } + } + QUERY register_update_response: { "data" => { "eventBridgeWebhookSubscriptionUpdate" => { @@ -283,6 +366,28 @@ def queries }, }, }, + register_update_with_fields_response: { + "data" => { + "eventBridgeWebhookSubscriptionUpdate" => { + "userErrors" => [], + "webhookSubscription" => { + "id" => "gid://shopify/WebhookSubscription/12345", + "includeFields" => ["field1", "field2", "field3"], + }, + }, + }, + }, + register_update_with_metafield_namespaces_response: { + "data" => { + "eventBridgeWebhookSubscriptionUpdate" => { + "userErrors" => [], + "webhookSubscription" => { + "id" => "gid://shopify/WebhookSubscription/12345", + "metafieldNamespaces" => ["namespace1", "namespace2", "namespace3"], + }, + }, + }, + }, }, pub_sub: { check_query: @@ -415,6 +520,37 @@ def queries } } QUERY + register_update_query_with_fields: + <<~QUERY, + mutation webhookSubscription { + pubSubWebhookSubscriptionUpdate(id: "gid://shopify/WebhookSubscription/12345", webhookSubscription: {pubSubProject: "my-project-id", pubSubTopic: "my-topic-id", includeFields: ["field1", "field2", "field3"]}) { + userErrors { + field + message + } + webhookSubscription { + id + includeFields + } + } + } + QUERY + register_update_query_with_metafield_namespaces: + <<~QUERY, + mutation webhookSubscription { + pubSubWebhookSubscriptionUpdate(id: "gid://shopify/WebhookSubscription/12345", webhookSubscription: {pubSubProject: "my-project-id", pubSubTopic: "my-topic-id", metafieldNamespaces: ["namespace1", "namespace2", "namespace3"]}) { + userErrors { + field + message + } + webhookSubscription { + id + metafieldNamespaces + } + } + } + QUERY + register_update_response: { "data" => { "pubSubWebhookSubscriptionUpdate" => { @@ -423,6 +559,28 @@ def queries }, }, }, + register_update_with_fields_response: { + "data" => { + "pubSubWebhookSubscriptionUpdate" => { + "userErrors" => [], + "webhookSubscription" => { + "id" => "gid://shopify/WebhookSubscription/12345", + "includeFields" => ["field1", "field2", "field3"], + }, + }, + }, + }, + register_update_with_metafield_namespaces_response: { + "data" => { + "pubSubWebhookSubscriptionUpdate" => { + "userErrors" => [], + "webhookSubscription" => { + "id" => "gid://shopify/WebhookSubscription/12345", + "metafieldNamespaces" => ["namespace1", "namespace2", "namespace3"], + }, + }, + }, + }, }, fetch_id_query: <<~QUERY,