Skip to content

Commit

Permalink
fill out all test scenarios, temp set check to true
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-liuu committed Oct 30, 2024
1 parent 0d411c5 commit b2f136e
Show file tree
Hide file tree
Showing 3 changed files with 242 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/shopify_api/webhooks/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
90 changes: 81 additions & 9 deletions test/webhooks/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
158 changes: 158 additions & 0 deletions test/webhooks/webhook_registration_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => {
Expand All @@ -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:
Expand Down Expand Up @@ -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" => {
Expand All @@ -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:
Expand Down Expand Up @@ -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" => {
Expand All @@ -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,
Expand Down

0 comments on commit b2f136e

Please sign in to comment.