diff --git a/test/webhooks/registry_test.rb b/test/webhooks/registry_test.rb index 60f8cb8a..6090e205 100644 --- a/test/webhooks/registry_test.rb +++ b/test/webhooks/registry_test.rb @@ -32,103 +32,105 @@ def setup @url = "#{ShopifyAPI::Context.host}/admin/api/#{ShopifyAPI::Context.api_version}/graphql.json" end - DEFAULT_PROTOCOL_ADDRESS = { - http: "test-webhooks", - pub_sub: "pubsub://my-project-id:my-topic-id", - event_bridge: "test-webhooks", + DEFAULT_PROTOCOL_ADDRESSES = { + http: ["test-webhooks", "https://app-address.com/test-webhooks", "app-address.com/test-webhooks"], + pub_sub: ["pubsub://my-project-id:my-topic-id"], + event_bridge: ["test-webhooks"], } - DEFAULT_PROTOCOL_ADDRESS.each do |protocol, address| - define_method("test_add_#{protocol}_registration_if_identical_webhook_exists") do - do_no_registration_needed_test( - queries[protocol][:check_existing_response], - protocol, - address, - ) - - do_no_registration_needed_test( - queries[protocol][:check_existing_response_with_attributes], - protocol, - address, - fields: "field1, field2", - metafield_namespaces: ["namespace1", "namespace2"], - ) - end - - define_method("test_#{protocol}_registration_add_and_update") do - do_registration_test( - queries[protocol][:check_empty_response], - queries[protocol][:register_add_query], - queries[protocol][:register_add_response], - protocol, - address, - ) - end - - define_method("test_#{protocol}_registration_with_fields_add_and_update") do - # add webhook - do_registration_test( - queries[protocol][:check_empty_response], - queries[protocol][:register_add_query_with_fields], - queries[protocol][:register_add_with_fields_response], - protocol, - address, - fields: "field1, field2", - ) - - # update webhook fields - do_registration_test( - queries[protocol][:check_existing_response], - queries[protocol][:register_update_query_with_fields], - queries[protocol][:register_update_with_fields_response], - protocol, - address, - fields: "field1, field2, field3", - ) - end - - define_method("test_#{protocol}_registration_with_fields_array_add_and_update") do - # add webhook - do_registration_test( - queries[protocol][:check_empty_response], - queries[protocol][:register_add_query_with_fields], - queries[protocol][:register_add_with_fields_response], - protocol, - address, - fields: ["field1", "field2"], - ) - - # update webhook fields - do_registration_test( - queries[protocol][:check_existing_response], - queries[protocol][:register_update_query_with_fields], - queries[protocol][:register_update_with_fields_response], - protocol, - address, - fields: ["field1", "field2", "field3"], - ) - end - - define_method("test_#{protocol}_registration_with_metafield_namespaces_add_and_update") do - # add webhook - do_registration_test( - queries[protocol][:check_empty_response], - queries[protocol][:register_add_query_with_metafield_namespaces], - queries[protocol][:register_add_with_metafield_namespaces_response], - protocol, - address, - metafield_namespaces: ["namespace1", "namespace2"], - ) - - # update webhook metafield namespaces - do_registration_test( - queries[protocol][:check_existing_response], - queries[protocol][:register_update_query_with_metafield_namespaces], - queries[protocol][:register_update_with_metafield_namespaces_response], - protocol, - address, - metafield_namespaces: ["namespace1", "namespace2", "namespace3"], - ) + DEFAULT_PROTOCOL_ADDRESSES.each do |protocol, addresses| + addresses.each do |address| + define_method("test_add_#{protocol}_registration_if_identical_webhook_exists_on_#{address}") do + do_no_registration_needed_test( + queries[protocol][:check_existing_response], + protocol, + address, + ) + + do_no_registration_needed_test( + queries[protocol][:check_existing_response_with_attributes], + protocol, + address, + fields: "field1, field2", + metafield_namespaces: ["namespace1", "namespace2"], + ) + end + + define_method("test_#{protocol}_registration_add_and_update_on_#{address}") do + do_registration_test( + queries[protocol][:check_empty_response], + queries[protocol][:register_add_query], + queries[protocol][:register_add_response], + protocol, + address, + ) + end + + define_method("test_#{protocol}_registration_with_fields_add_and_update_on_#{address}") do + # add webhook + do_registration_test( + queries[protocol][:check_empty_response], + queries[protocol][:register_add_query_with_fields], + queries[protocol][:register_add_with_fields_response], + protocol, + address, + fields: "field1, field2", + ) + + # update webhook fields + do_registration_test( + queries[protocol][:check_existing_response], + queries[protocol][:register_update_query_with_fields], + queries[protocol][:register_update_with_fields_response], + protocol, + address, + fields: "field1, field2, field3", + ) + end + + define_method("test_#{protocol}_registration_with_fields_array_add_and_update_on_address_#{address}") do + # add webhook + do_registration_test( + queries[protocol][:check_empty_response], + queries[protocol][:register_add_query_with_fields], + queries[protocol][:register_add_with_fields_response], + protocol, + address, + fields: ["field1", "field2"], + ) + + # update webhook fields + do_registration_test( + queries[protocol][:check_existing_response], + queries[protocol][:register_update_query_with_fields], + queries[protocol][:register_update_with_fields_response], + protocol, + address, + fields: ["field1", "field2", "field3"], + ) + end + + define_method("test_#{protocol}_registration_with_metafield_namespaces_add_and_update_on_address_#{address}") do + # add webhook + do_registration_test( + queries[protocol][:check_empty_response], + queries[protocol][:register_add_query_with_metafield_namespaces], + queries[protocol][:register_add_with_metafield_namespaces_response], + protocol, + address, + metafield_namespaces: ["namespace1", "namespace2"], + ) + + # update webhook metafield namespaces + do_registration_test( + queries[protocol][:check_existing_response], + queries[protocol][:register_update_query_with_metafield_namespaces], + queries[protocol][:register_update_with_metafield_namespaces_response], + protocol, + address, + metafield_namespaces: ["namespace1", "namespace2", "namespace3"], + ) + end end end @@ -225,46 +227,6 @@ def test_process_no_handler end end - def test_http_registration_add_and_update_with_full_url - # add webhook - do_registration_test( - queries[:http][:check_empty_response], - queries[:http][:register_add_query], - queries[:http][:register_add_response], - :http, - "https://app-address.com/test-webhooks", - ) - - # update webhook path - do_registration_test( - queries[:http][:check_existing_response], - queries[:http][:register_update_query], - queries[:http][:register_update_response], - :http, - "https://app-address.com/test-webhooks-updated", - ) - end - - def test_http_registration_add_and_update_with_schemeless_url - # add webhook - do_registration_test( - queries[:http][:check_empty_response], - queries[:http][:register_add_query], - queries[:http][:register_add_response], - :http, - "app-address.com/test-webhooks", - ) - - # update webhook path - do_registration_test( - queries[:http][:check_existing_response], - queries[:http][:register_update_query], - queries[:http][:register_update_response], - :http, - "app-address.com/test-webhooks-updated", - ) - end - def test_raises_on_http_registration_check_error do_registration_check_error_test(:http, "test-webhooks") end