Skip to content

Commit

Permalink
Make the ApiClient use application/x-www-form-urlencoded as content t…
Browse files Browse the repository at this point in the history
…ype when submitting form data (#399)
  • Loading branch information
supherman authored Feb 9, 2024
1 parent e73a4d4 commit 67411c7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/noticed/api_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def post_request(url, args = {})
if (json = args.delete(:json))
request.body = json.to_json
elsif (form = args.delete(:form))
request.set_form(form, "multipart/form-data")
request.form_data = form
end

logger.debug("POST #{url}")
Expand Down
2 changes: 1 addition & 1 deletion test/bulk_delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WebhookBulkDeliveryMethodTest < ActiveSupport::TestCase
url: "https://example.org/webhook",
form: {foo: :bar}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /multipart\/form-data/})
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /application\/x-www-form-urlencoded/})
@delivery_method.deliver
end

Expand Down
7 changes: 6 additions & 1 deletion test/delivery_methods/twilio_messaging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class TwilioMessagingTest < ActiveSupport::TestCase
stub_request(:post, "https://api.twilio.com/2010-04-01/Accounts/acct_1234/Messages.json").with(
headers: {
"Authorization" => "Basic YWNjdF8xMjM0OnRva2Vu",
"Content-Type" => "multipart/form-data"
"Content-Type" => "application/x-www-form-urlencoded"
},
body: {
From: "+1234567890",
To: "+1234567890",
Body: "Hello world"
}
).to_return(status: 200)
@delivery_method.deliver
Expand Down
2 changes: 1 addition & 1 deletion test/delivery_methods/webhook_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WebhookDeliveryMethodTest < ActiveSupport::TestCase
url: "https://example.org/webhook",
form: {foo: :bar}
)
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /multipart\/form-data/})
stub_request(:post, "https://example.org/webhook").with(headers: {"Content-Type" => /application\/x-www-form-urlencoded/})
@delivery_method.deliver
end

Expand Down

0 comments on commit 67411c7

Please sign in to comment.