Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.HTTPTest do
  5. use Pleroma.DataCase
  6. import Tesla.Mock
  7. setup do
  8. mock(fn
  9. %{
  10. method: :get,
  11. url: "http://example.com/hello",
  12. headers: [{"content-type", "application/json"}]
  13. } ->
  14. json(%{"my" => "data"})
  15. %{method: :get, url: "http://example.com/hello"} ->
  16. %Tesla.Env{status: 200, body: "hello"}
  17. %{method: :post, url: "http://example.com/world"} ->
  18. %Tesla.Env{status: 200, body: "world"}
  19. end)
  20. :ok
  21. end
  22. describe "get/1" do
  23. test "returns successfully result" do
  24. assert Pleroma.HTTP.get("http://example.com/hello") == {
  25. :ok,
  26. %Tesla.Env{status: 200, body: "hello"}
  27. }
  28. end
  29. end
  30. describe "get/2 (with headers)" do
  31. test "returns successfully result for json content-type" do
  32. assert Pleroma.HTTP.get("http://example.com/hello", [{"content-type", "application/json"}]) ==
  33. {
  34. :ok,
  35. %Tesla.Env{
  36. status: 200,
  37. body: "{\"my\":\"data\"}",
  38. headers: [{"content-type", "application/json"}]
  39. }
  40. }
  41. end
  42. end
  43. describe "post/2" do
  44. test "returns successfully result" do
  45. assert Pleroma.HTTP.post("http://example.com/world", "") == {
  46. :ok,
  47. %Tesla.Env{status: 200, body: "world"}
  48. }
  49. end
  50. end
  51. end