Skip to content

Commit 9bb2ff7

Browse files
committed
helper function to setup tests and expected queries
1 parent 6dcfdf7 commit 9bb2ff7

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

test/webhooks/registry_test.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,10 @@ def do_registration_test(
389389
metafield_namespaces: nil
390390
)
391391
# Given
392-
ShopifyAPI::Webhooks::Registry.clear
393-
394-
stub_request(:post, @url)
395-
.with(body: JSON.dump({ query: queries[delivery_method][:check_query], variables: nil }))
396-
.to_return({ status: 200, body: JSON.dump(expected_check_response) })
397-
398-
stub_request(:post, @url)
399-
.with(body: JSON.dump({ query: expected_update_webhook_query, variables: nil }))
400-
.to_return({ status: 200, body: JSON.dump(expected_update_webhook_response) })
392+
setup_queries_and_responses(
393+
[queries[delivery_method][:check_query], expected_update_webhook_query],
394+
[expected_check_response, expected_update_webhook_response],
395+
)
401396

402397
# When
403398
update_registration_response = add_and_register_webhook(
@@ -430,6 +425,15 @@ def add_and_register_webhook(protocol, address, fields: nil, metafield_namespace
430425

431426
update_registration_response
432427
end
428+
429+
def setup_queries_and_responses(queries, responses)
430+
ShopifyAPI::Webhooks::Registry.clear
431+
queries.zip(responses).each do |query, response|
432+
stub_request(:post, @url)
433+
.with(body: JSON.dump({ query: query, variables: nil }))
434+
.to_return({ status: 200, body: JSON.dump(response) })
435+
end
436+
end
433437
end
434438
end
435439
end

0 commit comments

Comments
 (0)