Skip to content

Commit

Permalink
Support for Events 2.0 topic names
Browse files Browse the repository at this point in the history
  • Loading branch information
pacocastrotech committed May 5, 2023
1 parent 427f40b commit ad6bfab
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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_domain_event
stub_request(:post, @url)
.with(body: JSON.dump({ query: queries[:fetch_id_domain_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: "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_domain_event_query:
<<~QUERY,
{
webhookSubscriptions(first: 1, topics: SOMETHING_HAPPENED) {
edges {
node {
id
}
}
}
}
QUERY
delete_query:
<<~QUERY,
mutation webhookSubscription {
Expand Down

0 comments on commit ad6bfab

Please sign in to comment.