Skip to content

Commit

Permalink
pull out adding and registring webhooks into seperate fn
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-liuu committed Nov 4, 2024
1 parent 9c272c0 commit b8382a5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions test/webhooks/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,20 +439,12 @@ def do_registration_test(
.to_return({ status: 200, body: JSON.dump(expected_update_webhook_response) })

# When
ShopifyAPI::Webhooks::Registry.add_registration(
topic: @topic,
delivery_method: delivery_method,
path: path,
handler: TestHelpers::FakeWebhookHandler.new(
lambda do |topic, shop, body|
end,
),
update_registration_response = add_and_register_webhook(
delivery_method,
path,
fields: fields,
metafield_namespaces: metafield_namespaces,
)
update_registration_response = ShopifyAPI::Webhooks::Registry.register_all(
session: @session,
)[0]

# Then
assert(update_registration_response.success)
Expand Down Expand Up @@ -499,10 +491,22 @@ def do_no_registration_needed_test(
.to_return({ status: 200, body: JSON.dump(expected_check_response) })

# When
update_registration_response = add_and_register_webhook(
delivery_method,
path,
fields: fields,
metafield_namespaces: metafield_namespaces,
)

# Then
assert_nil(update_registration_response.body)
end

def add_and_register_webhook(protocol, address, fields: nil, metafield_namespaces: nil)
ShopifyAPI::Webhooks::Registry.add_registration(
topic: @topic,
delivery_method: delivery_method,
path: path,
delivery_method: protocol,
path: address,
handler: TestHelpers::FakeWebhookHandler.new(
lambda do |topic, shop, body|
end,
Expand All @@ -514,8 +518,7 @@ def do_no_registration_needed_test(
session: @session,
)[0]

# Then
assert_nil(update_registration_response.body)
update_registration_response
end
end
end
Expand Down

0 comments on commit b8382a5

Please sign in to comment.