From 26e907367471dab8d5bdee964f43d4ae124c5228 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Sun, 13 Dec 2020 14:07:25 +0100 Subject: [PATCH] Fix XMPP API POST request Faraday does not turn hashes into JSON by itself apparently. --- app/services/ejabberd_api_client.rb | 2 +- spec/services/create_account_spec.rb | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/app/services/ejabberd_api_client.rb b/app/services/ejabberd_api_client.rb index ddce590..65b3795 100644 --- a/app/services/ejabberd_api_client.rb +++ b/app/services/ejabberd_api_client.rb @@ -4,7 +4,7 @@ class EjabberdApiClient end def post(endpoint, payload) - res = Faraday.post("#{@base_url}/#{endpoint}", payload, + res = Faraday.post("#{@base_url}/#{endpoint}", payload.to_json, "Content-Type" => "application/json") if res.status != 200 diff --git a/spec/services/create_account_spec.rb b/spec/services/create_account_spec.rb index 2808836..c6e74d5 100644 --- a/spec/services/create_account_spec.rb +++ b/spec/services/create_account_spec.rb @@ -90,17 +90,9 @@ RSpec.describe CreateAccount, type: :model do service.send(:exchange_xmpp_contacts) expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem") - .with { |req| req.body == { - localuser: "isaacnewton", localhost: "kosmos.org", - user: "willherschel", host: "kosmos.org", - nick: "willherschel", group: "Friends", subs: "both" - }} + .with { |req| req.body == '{"localuser":"isaacnewton","localhost":"kosmos.org","user":"willherschel","host":"kosmos.org","nick":"willherschel","group":"Friends","subs":"both"}' } expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem") - .with { |req| req.body == { - localuser: "willherschel", localhost: "kosmos.org", - user: "isaacnewton", host: "kosmos.org", - nick: "isaacnewton", group: "Friends", subs: "both" - }} + .with { |req| req.body == '{"localuser":"willherschel","localhost":"kosmos.org","user":"isaacnewton","host":"kosmos.org","nick":"isaacnewton","group":"Friends","subs":"both"}' } end end end