Skip to content

Commit

Permalink
helper function to setup tests and expected queries
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-liuu committed Nov 5, 2024
1 parent 6dcfdf7 commit 9bb2ff7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions test/webhooks/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,10 @@ def do_registration_test(
metafield_namespaces: nil
)
# Given
ShopifyAPI::Webhooks::Registry.clear

stub_request(:post, @url)
.with(body: JSON.dump({ query: queries[delivery_method][:check_query], variables: nil }))
.to_return({ status: 200, body: JSON.dump(expected_check_response) })

stub_request(:post, @url)
.with(body: JSON.dump({ query: expected_update_webhook_query, variables: nil }))
.to_return({ status: 200, body: JSON.dump(expected_update_webhook_response) })
setup_queries_and_responses(
[queries[delivery_method][:check_query], expected_update_webhook_query],
[expected_check_response, expected_update_webhook_response],
)

# When
update_registration_response = add_and_register_webhook(
Expand Down Expand Up @@ -430,6 +425,15 @@ def add_and_register_webhook(protocol, address, fields: nil, metafield_namespace

update_registration_response
end

def setup_queries_and_responses(queries, responses)
ShopifyAPI::Webhooks::Registry.clear
queries.zip(responses).each do |query, response|
stub_request(:post, @url)
.with(body: JSON.dump({ query: query, variables: nil }))
.to_return({ status: 200, body: JSON.dump(response) })
end
end
end
end
end

0 comments on commit 9bb2ff7

Please sign in to comment.