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.

56 lines
1.4KB

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