Fix XMPP API POST request
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

Faraday does not turn hashes into JSON by itself apparently.
This commit is contained in:
Basti 2020-12-13 14:07:25 +01:00
parent 73a89c2601
commit 26e9073674
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
2 changed files with 3 additions and 11 deletions

View File

@ -4,7 +4,7 @@ class EjabberdApiClient
end end
def post(endpoint, payload) def post(endpoint, payload)
res = Faraday.post("#{@base_url}/#{endpoint}", payload, res = Faraday.post("#{@base_url}/#{endpoint}", payload.to_json,
"Content-Type" => "application/json") "Content-Type" => "application/json")
if res.status != 200 if res.status != 200

View File

@ -90,17 +90,9 @@ RSpec.describe CreateAccount, type: :model do
service.send(:exchange_xmpp_contacts) service.send(:exchange_xmpp_contacts)
expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem") expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem")
.with { |req| req.body == { .with { |req| req.body == '{"localuser":"isaacnewton","localhost":"kosmos.org","user":"willherschel","host":"kosmos.org","nick":"willherschel","group":"Friends","subs":"both"}' }
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") expect(WebMock).to have_requested(:post, "http://xmpp.example.com/api/add_rosteritem")
.with { |req| req.body == { .with { |req| req.body == '{"localuser":"willherschel","localhost":"kosmos.org","user":"isaacnewton","host":"kosmos.org","nick":"isaacnewton","group":"Friends","subs":"both"}' }
localuser: "willherschel", localhost: "kosmos.org",
user: "isaacnewton", host: "kosmos.org",
nick: "isaacnewton", group: "Friends", subs: "both"
}}
end end
end end
end end