Skip to content

Commit

Permalink
Merge pull request #1150 from Shopify/topic-name-graphql-transformation
Browse files Browse the repository at this point in the history
Add support for Event topic names
  • Loading branch information
pacocastrotech committed May 11, 2023
2 parents e260ef5 + b1531b9 commit c0de587
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api

- [#1140](https://github.com/Shopify/shopify-api-ruby/pull/1140) ⚠️ [Breaking] Reformat Http error messages to be JSON parsable.
- [#1142](https://github.com/Shopify/shopify-api-ruby/issues/1142) Restore API version 2022-04, in alignment with [this](https://shopify.dev/changelog/action-required-support-for-api-version-2022-04-extended-to-june-30-2023) changelog notice.
- [#1150](https://github.com/Shopify/shopify-api-ruby/pull/1150) [Patch] Add support for Event topic names.

## 12.5.0

Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_api/webhooks/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def unregister(topic:, session:)
def get_webhook_id(topic:, client:)
fetch_id_query = <<~QUERY
{
webhookSubscriptions(first: 1, topics: #{topic.gsub("/", "_").upcase}) {
webhookSubscriptions(first: 1, topics: #{topic.gsub(%r{/|\.}, "_").upcase}) {
edges {
node {
id
Expand Down
15 changes: 15 additions & 0 deletions test/webhooks/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ def test_get_webhook_id_success
)
end

def test_get_webhook_id_success_for_event
stub_request(:post, @url)
.with(body: JSON.dump({ query: queries[:fetch_id_event_query], variables: nil }))
.to_return({ status: 200, body: JSON.dump(queries[:fetch_id_response]) })

webhook_id_response = ShopifyAPI::Webhooks::Registry.get_webhook_id(
topic: "domain.sub_domain.something_happened",
client: ShopifyAPI::Clients::Graphql::Admin.new(session: @session),
)
assert_equal(
queries[:fetch_id_response]["data"]["webhookSubscriptions"]["edges"][0]["node"]["id"],
webhook_id_response,
)
end

def test_get_webhook_id_not_found
stub_request(:post, @url)
.with(body: JSON.dump({ query: queries[:fetch_id_query], variables: nil }))
Expand Down
12 changes: 12 additions & 0 deletions test/webhooks/webhook_registration_queries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,18 @@ def queries
"message" => "some error",
],
},
fetch_id_event_query:
<<~QUERY,
{
webhookSubscriptions(first: 1, topics: DOMAIN_SUB_DOMAIN_SOMETHING_HAPPENED) {
edges {
node {
id
}
}
}
}
QUERY
delete_query:
<<~QUERY,
mutation webhookSubscription {
Expand Down

0 comments on commit c0de587

Please sign in to comment.